xshell 1.1.10 → 1.1.12
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/prototype.browser.js +9 -8
- package/prototype.js +9 -8
- package/stdin.d.ts +4 -0
- package/stdin.js +23 -0
package/package.json
CHANGED
package/prototype.browser.js
CHANGED
|
@@ -343,21 +343,22 @@ Object.defineProperties(String.prototype, {
|
|
|
343
343
|
return fp.endsWith('/') ? fp : `${fp}/`;
|
|
344
344
|
},
|
|
345
345
|
fdir() {
|
|
346
|
-
return this.strip_end(this.fname);
|
|
346
|
+
return this.fp.strip_end(this.fname);
|
|
347
347
|
},
|
|
348
348
|
fname() {
|
|
349
|
-
const
|
|
349
|
+
const { fp } = this;
|
|
350
|
+
const ilast = fp.lastIndexOf('/');
|
|
350
351
|
if (ilast === -1)
|
|
351
|
-
return
|
|
352
|
+
return fp; // 没有斜杠时返回整个字符串
|
|
352
353
|
// 以斜杠结尾的情况
|
|
353
|
-
if (ilast ===
|
|
354
|
-
const iprev =
|
|
354
|
+
if (ilast === fp.length - 1) {
|
|
355
|
+
const iprev = fp.lastIndexOf('/', ilast - 1);
|
|
355
356
|
return iprev === -1
|
|
356
|
-
?
|
|
357
|
-
:
|
|
357
|
+
? fp // 只有一个斜杠且在末尾
|
|
358
|
+
: fp.slice(iprev + 1);
|
|
358
359
|
}
|
|
359
360
|
// 返回最后一个斜杠后的内容
|
|
360
|
-
return
|
|
361
|
+
return fp.slice(ilast + 1);
|
|
361
362
|
},
|
|
362
363
|
fext() {
|
|
363
364
|
const { fname } = this;
|
package/prototype.js
CHANGED
|
@@ -380,21 +380,22 @@ if (!globalThis.my_prototype_defined) {
|
|
|
380
380
|
return fp.endsWith('/') ? fp : `${fp}/`;
|
|
381
381
|
},
|
|
382
382
|
fdir() {
|
|
383
|
-
return this.strip_end(this.fname);
|
|
383
|
+
return this.fp.strip_end(this.fname);
|
|
384
384
|
},
|
|
385
385
|
fname() {
|
|
386
|
-
const
|
|
386
|
+
const { fp } = this;
|
|
387
|
+
const ilast = fp.lastIndexOf('/');
|
|
387
388
|
if (ilast === -1)
|
|
388
|
-
return
|
|
389
|
+
return fp; // 没有斜杠时返回整个字符串
|
|
389
390
|
// 以斜杠结尾的情况
|
|
390
|
-
if (ilast ===
|
|
391
|
-
const iprev =
|
|
391
|
+
if (ilast === fp.length - 1) {
|
|
392
|
+
const iprev = fp.lastIndexOf('/', ilast - 1);
|
|
392
393
|
return iprev === -1
|
|
393
|
-
?
|
|
394
|
-
:
|
|
394
|
+
? fp // 只有一个斜杠且在末尾
|
|
395
|
+
: fp.slice(iprev + 1);
|
|
395
396
|
}
|
|
396
397
|
// 返回最后一个斜杠后的内容
|
|
397
|
-
return
|
|
398
|
+
return fp.slice(ilast + 1);
|
|
398
399
|
},
|
|
399
400
|
fext() {
|
|
400
401
|
const { fname } = this;
|
package/stdin.d.ts
ADDED
package/stdin.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import process from 'process';
|
|
2
|
+
/** 监听终端按键 (输入),并调用 key_processor 处理
|
|
3
|
+
- on_key: 按键处理函数
|
|
4
|
+
- on_exit?: ctrl + c 会退出进程,可加入退出前自定义处理逻辑 */
|
|
5
|
+
export function process_stdin(on_key, on_exit) {
|
|
6
|
+
// https://stackoverflow.com/a/12506613/7609214
|
|
7
|
+
let { stdin } = process;
|
|
8
|
+
stdin.setRawMode(true);
|
|
9
|
+
stdin.resume();
|
|
10
|
+
stdin.setEncoding('utf-8');
|
|
11
|
+
// on any data into stdin
|
|
12
|
+
stdin.on('data', async (key) => {
|
|
13
|
+
// ctrl-c ( end of text )
|
|
14
|
+
if (key === '\u0003') {
|
|
15
|
+
await on_exit?.();
|
|
16
|
+
process.exit();
|
|
17
|
+
}
|
|
18
|
+
// write the key to stdout all normal like
|
|
19
|
+
console.log(key);
|
|
20
|
+
await on_key(key);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=stdin.js.map
|