turkiyem 1.10.1 → 1.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/menu.js +74 -21
package/package.json
CHANGED
package/src/commands/menu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import
|
|
2
|
+
import readline from 'node:readline';
|
|
3
3
|
import { printBanner } from '../utils/banner.js';
|
|
4
4
|
import { getCity } from '../utils/config.js';
|
|
5
5
|
|
|
@@ -13,39 +13,92 @@ function printSessionHeader() {
|
|
|
13
13
|
console.log('');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const commands = [
|
|
17
|
+
'sehir', 'hat', 'durak', 'hava', 'deprem', 'eczane', 'doviz', 'temizle', 'help', 'clear', 'exit', 'çıkış'
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const subcommands = {
|
|
21
|
+
'sehir': ['ankara', 'istanbul', 'adana', 'antalya', 'bursa', 'izmir', 'trabzon', 'samsun'],
|
|
22
|
+
'hat': ['canli'],
|
|
23
|
+
'hava': ['guncel', 'saatlik', 'kalite'],
|
|
24
|
+
'deprem': ['son24', '7gun', 'buyukluk'],
|
|
25
|
+
'eczane': ['nobetci', 'ara']
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function completer(line) {
|
|
29
|
+
const parts = line.trimStart().split(/\s+/);
|
|
30
|
+
let completions = [];
|
|
31
|
+
|
|
32
|
+
if (parts.length === 1) {
|
|
33
|
+
completions = commands.filter(c => c.startsWith(parts[0]));
|
|
34
|
+
if (completions.length > 0) return [completions, line];
|
|
35
|
+
} else if (parts.length === 2) {
|
|
36
|
+
const cmd = parts[0];
|
|
37
|
+
if (subcommands[cmd]) {
|
|
38
|
+
const subCompletions = subcommands[cmd].filter(c => c.startsWith(parts[1]));
|
|
39
|
+
if (subCompletions.length > 0) {
|
|
40
|
+
const prefix = line.substring(0, line.length - parts[1].length);
|
|
41
|
+
const mappedCompletions = subCompletions.map(c => prefix + c);
|
|
42
|
+
return [mappedCompletions, line];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return [[], line];
|
|
48
|
+
}
|
|
49
|
+
|
|
16
50
|
export async function showMenu() {
|
|
51
|
+
console.clear();
|
|
17
52
|
printBanner();
|
|
18
53
|
console.log(chalk.white.bold(' 🇹🇷 Sürekli oturum modu — Komutları direkt yazabilirsiniz (Örn: hat 500T, deprem son24)\n'));
|
|
19
54
|
console.log(chalk.gray(' Tüm komutları görmek için "help" yazabilirsiniz.\n'));
|
|
20
55
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
const rl = readline.createInterface({
|
|
57
|
+
input: process.stdin,
|
|
58
|
+
output: process.stdout,
|
|
59
|
+
completer: completer,
|
|
60
|
+
prompt: chalk.cyan('turkiyem > '),
|
|
61
|
+
historySize: 200 // Yukarı/aşağı ok tuşu arabellek boyutu
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
printSessionHeader();
|
|
65
|
+
rl.prompt();
|
|
24
66
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
name: 'cmd',
|
|
28
|
-
message: chalk.cyan('turkiyem >')
|
|
29
|
-
});
|
|
67
|
+
rl.on('line', async (line) => {
|
|
68
|
+
const cmd = line.trim();
|
|
30
69
|
|
|
31
|
-
if (cmd
|
|
70
|
+
if (cmd.toLowerCase() === 'exit' || cmd.toLowerCase() === 'çıkış') {
|
|
32
71
|
console.log('');
|
|
33
72
|
console.log(chalk.cyan(' Görüşmek üzere! 🇹🇷👋'));
|
|
34
73
|
console.log('');
|
|
35
|
-
|
|
74
|
+
rl.close();
|
|
75
|
+
return;
|
|
36
76
|
}
|
|
37
77
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
78
|
+
if (cmd.toLowerCase() === 'clear') {
|
|
79
|
+
console.clear();
|
|
80
|
+
printBanner();
|
|
81
|
+
console.log(chalk.white.bold(' 🇹🇷 Sürekli oturum modu — Komutları direkt yazabilirsiniz (Örn: hat 500T, deprem son24)\n'));
|
|
82
|
+
console.log(chalk.gray(' Tüm komutları görmek için "help" yazabilirsiniz.\n'));
|
|
83
|
+
printSessionHeader();
|
|
84
|
+
rl.prompt();
|
|
85
|
+
return;
|
|
42
86
|
}
|
|
43
87
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
88
|
+
const args = cmd.split(' ').filter(Boolean);
|
|
89
|
+
|
|
90
|
+
if (args.length > 0) {
|
|
91
|
+
try {
|
|
92
|
+
const { spawnSync } = await import('node:child_process');
|
|
93
|
+
spawnSync(process.argv[0], [process.argv[1], ...args], { stdio: 'inherit' });
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.log(chalk.red(`\n Komut çalıştırılamadı: ${err.message}`));
|
|
96
|
+
}
|
|
49
97
|
}
|
|
50
|
-
|
|
98
|
+
|
|
99
|
+
printSessionHeader();
|
|
100
|
+
rl.prompt();
|
|
101
|
+
}).on('close', () => {
|
|
102
|
+
process.exit(0);
|
|
103
|
+
});
|
|
51
104
|
}
|