dict


Logs | Files | README | LICENSE | GitLab


1
commit 8e679803f9696c1ac7ed2e1f02d58391ed05ef44
2
Author: Connor Etherington <[email protected]>
3
Date:   Sun Jan 28 02:15:45 2024 +0200
4
5
    Auto-Commit Update - 20240128
6
---
7
 usr/bin/dict                      | 31 ++++++++++++++++++++++++++-----
8
 usr/lib/node_modules/dict/dict.js |  2 +-
9
 2 files changed, 27 insertions(+), 6 deletions(-)
10
11
diff --git a/usr/bin/dict b/usr/bin/dict
12
index 5397c16..3105d2c 100755
13
--- a/usr/bin/dict
14
+++ b/usr/bin/dict
15
@@ -2,9 +2,30 @@
16
 
17
 const { search, printBoxedText } = require('/usr/lib/node_modules/dict');
18
 
19
-if (require.main === module) {
20
-  search(process.argv[2], process.argv[3] || 1).then(res => {
21
-    printBoxedText(res);
22
-  });
23
-}
24
+const sh = async (cmd) => {
25
+  const { exec } = require('child_process');
26
+  try { await exec(cmd, { stdio: 'inherit' }, (err, stdout, stderr) => { if (err) { console.log(err); } else { console.log(stdout); } }); }
27
+  catch (err) { console.log(err); }
28
+};
29
+
30
+const help = () => {
31
+  sh(`echo -e "\\n\\e[33m  Usage: \\e[36mdict \\e[0;1;32m[\\e[0;1;35msearch term\\e[0;1;32m] [\\e[0;1;35mnumber of results\\e[0;1;32m]\\e[0m"`);
32
+};
33
+
34
+(async () => {
35
+  if (require.main === module) {
36
+    let query = process.argv[2],
37
+        limit = process.argv[3] || 1;
38
+
39
+    if (query && (query == '-h' || query == '--help')) {
40
+      return help();
41
+    } else if (!query) {
42
+      return help();
43
+    } else {
44
+      search(query, limit).then(res => {
45
+        printBoxedText(res);
46
+      });
47
+    }
48
+  }
49
+})();
50
 
51
diff --git a/usr/lib/node_modules/dict/dict.js b/usr/lib/node_modules/dict/dict.js
52
index 3e7fa1d..4cf530a 100755
53
--- a/usr/lib/node_modules/dict/dict.js
54
+++ b/usr/lib/node_modules/dict/dict.js
55
@@ -2,7 +2,6 @@
56
 
57
 const axios = require('axios');
58
 const endpoint = 'https://en.wikipedia.org/w/rest.php/v1/search/page';
59
-const spinner = require('ora')('Searching...').start();
60
 const chalk = require('chalk');
61
 const process = require('process');
62
 
63
@@ -49,6 +48,7 @@ const printBoxedText = (text) => {
64
 }
65
 
66
 const search = async (query, limit) => {
67
+  const spinner = require('ora')('Searching...').start();
68
   let success = false, res = {};
69
 
70
   while (!success) {