pty-shell 1.1.1 → 1.2.1
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 +59 -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,17 @@ 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
|
-
return;
|
|
777
|
-
}
|
|
777
|
+
yield this.exec_cmd(exe, params);
|
|
778
|
+
// 不用再继续了
|
|
779
|
+
this.clear_line();
|
|
780
|
+
this.exec_end_call(0);
|
|
778
781
|
}
|
|
779
782
|
this.spawn(exe, params, use_noe_pty);
|
|
780
783
|
this.clear_line();
|
|
@@ -888,58 +891,60 @@ class PtyShell {
|
|
|
888
891
|
}
|
|
889
892
|
}
|
|
890
893
|
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
|
-
}
|
|
894
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
895
|
+
try {
|
|
896
|
+
const handle = this.cmd_exec_map.get(exe);
|
|
897
|
+
if (exe !== 'cd' && handle) {
|
|
898
|
+
// 如果用户有了就用用户的 不用系统自己的 但是 cd 命令排除在外
|
|
899
|
+
yield handle(params, (data) => {
|
|
900
|
+
this.send_and_enter(data, true);
|
|
901
|
+
});
|
|
905
902
|
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
|
-
}
|
|
903
|
+
}
|
|
904
|
+
switch (exe) {
|
|
905
|
+
case 'pwd':
|
|
906
|
+
{
|
|
907
|
+
this.send_and_enter(`${this.cwd}`);
|
|
915
908
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
909
|
+
return true;
|
|
910
|
+
case 'cd':
|
|
911
|
+
{
|
|
912
|
+
let p;
|
|
913
|
+
if (!this.not_use_node_pre_cmd_exec) {
|
|
914
|
+
// 有node环境可以检测一下
|
|
915
|
+
p = this.node_require.path.isAbsolute(params[0]) ? params[0] : this.node_require.path.join(this.cwd, params[0]);
|
|
916
|
+
if (!this.node_require.fs.existsSync(p)) {
|
|
917
|
+
this.send_and_enter(`not directory ${p}`);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
// 没有node环境只能这样了 todo 对于 .. 路径有问题
|
|
922
|
+
p = (0, path_util_1.path_join)(this.cwd, params[0]);
|
|
923
|
+
}
|
|
924
|
+
this.cwd = p;
|
|
925
|
+
this.send_and_enter(``);
|
|
926
|
+
this.word_detection = undefined; // 清空检测器
|
|
919
927
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
928
|
+
return true;
|
|
929
|
+
case 'ls':
|
|
930
|
+
{
|
|
931
|
+
if (this.not_use_node_pre_cmd_exec) {
|
|
932
|
+
return false; // 让其它方式处理
|
|
933
|
+
}
|
|
934
|
+
const items = this.node_require.fs.readdirSync(this.cwd); // 读取目录内容
|
|
935
|
+
const v = this.cols_handle(" " + items.join(" "));
|
|
936
|
+
this.send_and_enter(v);
|
|
929
937
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return true;
|
|
935
|
-
default:
|
|
936
|
-
return false; // 让其它方式处理
|
|
938
|
+
return true;
|
|
939
|
+
default:
|
|
940
|
+
return false; // 让其它方式处理
|
|
941
|
+
}
|
|
937
942
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
+
catch (e) {
|
|
944
|
+
this.send_and_enter(JSON.stringify(e));
|
|
945
|
+
}
|
|
946
|
+
return false; // 让其它方式处理
|
|
947
|
+
});
|
|
943
948
|
}
|
|
944
949
|
// 解析命令与参数
|
|
945
950
|
get_exec(str) {
|