webide-cli 0.0.1-alpha.7 → 0.0.1-alpha.8

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.
Files changed (2) hide show
  1. package/index.js +25 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -90,11 +90,16 @@ program
90
90
  }
91
91
  });
92
92
 
93
+ function truncateMessage(msg, maxLength = 50) {
94
+ if (msg.length <= maxLength) return msg;
95
+ return msg.substring(0, maxLength - 3) + '...';
96
+ }
97
+
93
98
  program
94
99
  .command('search <keyword>')
95
100
  .description('Search for libraries')
96
101
  .action(async function (keyword) {
97
- const load = loading(`Searching for libraries with keyword "${keyword}" ...`);
102
+ const load = loading(`Searching for libraries with keyword "${truncateMessage(keyword)}" ...`);
98
103
  const results = await search(keyword);
99
104
  load();
100
105
  console.log("\r\nSearch results(" + results.length + " items):");
@@ -118,14 +123,31 @@ async function getFile(path) {
118
123
 
119
124
  function loading(msg) {
120
125
  const spinnerChars = ['⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
126
+ const terminalWidth = process.stdout.columns || 80; // 获取终端宽度
121
127
  let i = 0;
128
+ let linesUsed = Math.ceil((spinnerChars[0].length + msg.length + 1) / terminalWidth);
129
+
122
130
  const interval = setInterval(() => {
123
- process.stdout.write(`\r${spinnerChars[i++]} ${msg}`);
131
+ const displayText = `${spinnerChars[i++]} ${msg}`;
132
+ linesUsed = Math.ceil(displayText.length / terminalWidth);
133
+
134
+ // 清除之前占用的行
135
+ let clearLines = '';
136
+ for (let j = 0; j < linesUsed - 1; j++) {
137
+ clearLines += '\x1b[1F\x1b[K'; // 移动到上一行并清除
138
+ }
139
+ clearLines += '\r\x1b[K';
140
+ process.stdout.write(clearLines + displayText);
124
141
  i = i % spinnerChars.length;
125
142
  }, 50);
126
143
  return () => {
127
144
  clearInterval(interval);
128
- process.stdout.write('\r\x1b[K');
145
+ let clearLines = '';
146
+ for (let j = 0; j < linesUsed - 1; j++) {
147
+ clearLines += '\x1b[1F\x1b[K';
148
+ }
149
+ clearLines += '\r\x1b[K';
150
+ process.stdout.write(clearLines);
129
151
  }
130
152
  }
131
153
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webide-cli",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.8",
4
4
  "description": "A CLI for NEW WebIDE",
5
5
  "keywords": [
6
6
  "WebIDE",