mepcli 0.2.7 → 0.4.0

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/dist/utils.d.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  export declare function detectCapabilities(): {
5
5
  isCI: boolean;
6
6
  hasTrueColor: boolean;
7
- hasUnicode: boolean;
7
+ hasUnicode: boolean | "";
8
+ hasMouse: boolean;
8
9
  };
9
10
  /**
10
11
  * Strips ANSI escape codes from a string.
package/dist/utils.js CHANGED
@@ -14,17 +14,48 @@ function detectCapabilities() {
14
14
  const isCI = !!env.CI;
15
15
  // Check for True Color support
16
16
  const hasTrueColor = env.COLORTERM === 'truecolor';
17
- // Check for Unicode support
18
- // Windows Terminal (WT_SESSION), VS Code (TERM_PROGRAM=vscode), or modern Linux terminals usually support it.
17
+ // Check if it is a TTY
18
+ const isTTY = process.stdout.isTTY;
19
19
  const isWindows = process.platform === 'win32';
20
- const hasUnicode = !!env.WT_SESSION ||
21
- env.TERM_PROGRAM === 'vscode' ||
22
- env.TERM_PROGRAM === 'Apple_Terminal' ||
23
- (!isWindows && env.LANG && env.LANG.toUpperCase().endsWith('UTF-8'));
20
+ // Logic detect Unicode xịn hơn
21
+ const isUnicodeSupported = () => {
22
+ // 1. Windows: Check specific environmental variables
23
+ if (isWindows) {
24
+ // Windows Terminal
25
+ if (env.WT_SESSION)
26
+ return true;
27
+ // VSCode terminal
28
+ if (env.TERM_PROGRAM === 'vscode')
29
+ return true;
30
+ // Modern terminals setting TERM (e.g. Alacritty, Git Bash, Cygwin)
31
+ if (env.TERM === 'xterm-256color' || env.TERM === 'alacritty')
32
+ return true;
33
+ // ConEmu / Cmder
34
+ if (env.ConEmuTask)
35
+ return true;
36
+ // CI on Windows typically supports Unicode.
37
+ if (isCI)
38
+ return true;
39
+ // Default cmd.exe / old powershell => False (ASCII)
40
+ return false;
41
+ }
42
+ // 2. Non-Windows (Linux/macOS)
43
+ if (env.TERM_PROGRAM === 'Apple_Terminal')
44
+ return true;
45
+ // Check if the LANG or LC_ALL variable contains UTF-8.
46
+ const lang = env.LANG || '';
47
+ const lcAll = env.LC_ALL || '';
48
+ return (lang && lang.toUpperCase().endsWith('UTF-8')) ||
49
+ (lcAll && lcAll.toUpperCase().endsWith('UTF-8'));
50
+ };
24
51
  return {
25
52
  isCI,
26
53
  hasTrueColor,
27
- hasUnicode: hasUnicode || !isWindows // Assume non-windows has unicode by default if not strictly detected?
54
+ // Enable Unicode only if it's TTY and environment supports it.
55
+ hasUnicode: isTTY && isUnicodeSupported(),
56
+ // Check if mouse should be enabled (TTY and not CI, or explicit override)
57
+ // SGR is widely supported in modern terminals
58
+ hasMouse: isTTY && !isCI
28
59
  };
29
60
  }
30
61
  /**
package/example.ts CHANGED
@@ -96,7 +96,16 @@ async function runComprehensiveDemo() {
96
96
  });
97
97
  console.log(`\n✅ Slider Result: Brightness: ${brightness}%`);
98
98
 
99
- // --- 9. Date / Time Picker (New) ---
99
+ // --- 9. Rating Prompt (New) ---
100
+ const userRating = await MepCLI.rating({
101
+ message: "How would you rate this CLI tool?",
102
+ min: 1,
103
+ max: 5,
104
+ initial: 5
105
+ });
106
+ console.log(`\n✅ Rating Result: You rated it: ${userRating}/5`);
107
+
108
+ // --- 10. Date / Time Picker (New) ---
100
109
  // We capture 'now' once to ensure initial >= min
101
110
  const now = new Date();
102
111
  const releaseDate = await MepCLI.date({
@@ -106,14 +115,14 @@ async function runComprehensiveDemo() {
106
115
  });
107
116
  console.log(`\n✅ Date Result: Release set for: ${releaseDate.toLocaleString()}`);
108
117
 
109
- // --- 10. File Path Selector (New) ---
118
+ // --- 11. File Path Selector (New) ---
110
119
  const configPath = await MepCLI.file({
111
120
  message: "Select configuration file (Tab to autocomplete):",
112
121
  basePath: process.cwd()
113
122
  });
114
123
  console.log(`\n✅ File Result: Path: ${configPath}`);
115
124
 
116
- // --- 11. Multi-Select Autocomplete (New) ---
125
+ // --- 12. Multi-Select Autocomplete (New) ---
117
126
  const linters = await MepCLI.multiSelect({
118
127
  message: "Select linters to install (Type to search, Space to select):",
119
128
  choices: [
@@ -128,14 +137,14 @@ async function runComprehensiveDemo() {
128
137
  });
129
138
  console.log(`\n✅ MultiSelect Result: Linters: [${linters.join(', ')}]`);
130
139
 
131
- // --- 12. Confirm Prompt (Simple Yes/No) ---
140
+ // --- 13. Confirm Prompt (Simple Yes/No) ---
132
141
  const proceed = await MepCLI.confirm({
133
142
  message: "Ready to deploy the project now?",
134
143
  initial: true
135
144
  });
136
145
  console.log(`\n✅ Confirm Result: Deployment decision: ${proceed ? 'Proceed' : 'Cancel'}`);
137
146
 
138
- // --- 13. Spin Utility (Loading/Async Task Indicator) ---
147
+ // --- 14. Spin Utility (Loading/Async Task Indicator) ---
139
148
  await MepCLI.spin(
140
149
  "Finalizing configuration and deploying...",
141
150
  new Promise(resolve => setTimeout(resolve, 1500)) // Simulates a 1.5 second async task
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mepcli",
3
- "version": "0.2.7",
3
+ "version": "0.4.0",
4
4
  "description": "Zero-dependency, minimalist interactive CLI prompt for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,8 +30,8 @@
30
30
  "author": "CodeTease",
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
- "@types/node": "^20.19.27",
34
- "ts-node": "^10.9.2",
35
- "typescript": "^5.9.3"
33
+ "@types/node": "^22",
34
+ "ts-node": "^10",
35
+ "typescript": "^5"
36
36
  }
37
37
  }