pty-shell 1.1.1 → 1.2.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/dist/index.d.ts +6 -2
- package/dist/index.js +60 -54
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ interface Param extends Partial<PtyShellUserMethod> {
|
|
|
41
41
|
history_line?: string[];
|
|
42
42
|
history_line_max?: number;
|
|
43
43
|
}
|
|
44
|
-
type CmdHandler = (params: string[], send_prompt?: (data: string) => void) => void
|
|
44
|
+
type CmdHandler = (params: string[], send_prompt?: (data: string) => void) => Promise<void>;
|
|
45
45
|
export declare class PtyShell implements PtyShellUserMethod {
|
|
46
46
|
rows: number;
|
|
47
47
|
cols: number;
|
|
@@ -58,7 +58,11 @@ export declare class PtyShell implements PtyShellUserMethod {
|
|
|
58
58
|
on_call_child_raw?: (data: string) => void;
|
|
59
59
|
on_control_cmd: (type: exec_cmd_type, data?: string) => void;
|
|
60
60
|
on_child_kill?: (code: number, pid?: number) => void;
|
|
61
|
-
check_exe_cmd:
|
|
61
|
+
check_exe_cmd?: (exe_cmd: string, params: string[]) => Promise<exec_type>;
|
|
62
|
+
cmd_replace?: (exe_cmd: string, params: string[]) => Promise<{
|
|
63
|
+
exe_cmd: string;
|
|
64
|
+
params: string[];
|
|
65
|
+
}>;
|
|
62
66
|
private cmd_set;
|
|
63
67
|
private shell_set;
|
|
64
68
|
private node_require;
|
package/dist/index.js
CHANGED
|
@@ -743,7 +743,7 @@ class PtyShell {
|
|
|
743
743
|
this.clear_line();
|
|
744
744
|
return;
|
|
745
745
|
}
|
|
746
|
-
|
|
746
|
+
let { exe, params } = this.get_exec(this.line);
|
|
747
747
|
this.history_line_index = -1;
|
|
748
748
|
try {
|
|
749
749
|
let use_noe_pty = false;
|
|
@@ -767,14 +767,18 @@ class PtyShell {
|
|
|
767
767
|
return;
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
|
+
if (this.cmd_replace) {
|
|
771
|
+
const r = yield this.cmd_replace(exe, params);
|
|
772
|
+
exe = r.exe_cmd;
|
|
773
|
+
params = r.params;
|
|
774
|
+
}
|
|
770
775
|
if (this.cmd_set.has(exe)) {
|
|
771
776
|
// 检测某个已经有预处理的命令 包括用户自定义的
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
777
|
+
yield this.exec_cmd(exe, params);
|
|
778
|
+
// 不用再继续了
|
|
779
|
+
this.clear_line();
|
|
780
|
+
this.exec_end_call(0);
|
|
781
|
+
return;
|
|
778
782
|
}
|
|
779
783
|
this.spawn(exe, params, use_noe_pty);
|
|
780
784
|
this.clear_line();
|
|
@@ -888,58 +892,60 @@ class PtyShell {
|
|
|
888
892
|
}
|
|
889
893
|
}
|
|
890
894
|
exec_cmd(exe, params) {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
}
|
|
900
|
-
switch (exe) {
|
|
901
|
-
case 'pwd':
|
|
902
|
-
{
|
|
903
|
-
this.send_and_enter(`${this.cwd}`);
|
|
904
|
-
}
|
|
895
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
896
|
+
try {
|
|
897
|
+
const handle = this.cmd_exec_map.get(exe);
|
|
898
|
+
if (exe !== 'cd' && handle) {
|
|
899
|
+
// 如果用户有了就用用户的 不用系统自己的 但是 cd 命令排除在外
|
|
900
|
+
yield handle(params, (data) => {
|
|
901
|
+
this.send_and_enter(data, true);
|
|
902
|
+
});
|
|
905
903
|
return true;
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
p = this.node_require.path.isAbsolute(params[0]) ? params[0] : this.node_require.path.join(this.cwd, params[0]);
|
|
912
|
-
if (!this.node_require.fs.existsSync(p)) {
|
|
913
|
-
this.send_and_enter(`not directory ${p}`);
|
|
914
|
-
}
|
|
904
|
+
}
|
|
905
|
+
switch (exe) {
|
|
906
|
+
case 'pwd':
|
|
907
|
+
{
|
|
908
|
+
this.send_and_enter(`${this.cwd}`);
|
|
915
909
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
910
|
+
return true;
|
|
911
|
+
case 'cd':
|
|
912
|
+
{
|
|
913
|
+
let p;
|
|
914
|
+
if (!this.not_use_node_pre_cmd_exec) {
|
|
915
|
+
// 有node环境可以检测一下
|
|
916
|
+
p = this.node_require.path.isAbsolute(params[0]) ? params[0] : this.node_require.path.join(this.cwd, params[0]);
|
|
917
|
+
if (!this.node_require.fs.existsSync(p)) {
|
|
918
|
+
this.send_and_enter(`not directory ${p}`);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
// 没有node环境只能这样了 todo 对于 .. 路径有问题
|
|
923
|
+
p = (0, path_util_1.path_join)(this.cwd, params[0]);
|
|
924
|
+
}
|
|
925
|
+
this.cwd = p;
|
|
926
|
+
this.send_and_enter(``);
|
|
927
|
+
this.word_detection = undefined; // 清空检测器
|
|
919
928
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
+
return true;
|
|
930
|
+
case 'ls':
|
|
931
|
+
{
|
|
932
|
+
if (this.not_use_node_pre_cmd_exec) {
|
|
933
|
+
return false; // 让其它方式处理
|
|
934
|
+
}
|
|
935
|
+
const items = this.node_require.fs.readdirSync(this.cwd); // 读取目录内容
|
|
936
|
+
const v = this.cols_handle(" " + items.join(" "));
|
|
937
|
+
this.send_and_enter(v);
|
|
929
938
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return true;
|
|
935
|
-
default:
|
|
936
|
-
return false; // 让其它方式处理
|
|
939
|
+
return true;
|
|
940
|
+
default:
|
|
941
|
+
return false; // 让其它方式处理
|
|
942
|
+
}
|
|
937
943
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
944
|
+
catch (e) {
|
|
945
|
+
this.send_and_enter(JSON.stringify(e));
|
|
946
|
+
}
|
|
947
|
+
return false; // 让其它方式处理
|
|
948
|
+
});
|
|
943
949
|
}
|
|
944
950
|
// 解析命令与参数
|
|
945
951
|
get_exec(str) {
|