pty-shell 1.0.6 → 1.1.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/LICENSE +21 -21
- package/README.md +29 -29
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -1
- package/package.json +39 -39
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 xiaobaidadada
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 xiaobaidadada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# pty-shell
|
|
2
|
-
This is a virtual PTY shell that can be used to filter or log executable commands. It can also be used in a browser environment. Currently, it does not support features like piping. It supports the use of `node-pty`. For more usage examples, you can refer to the code in the [filecat](https://github.com/xiaobaidadada/filecat) project.
|
|
3
|
-
It needs to be used in combination with projects similar to xterm.js.
|
|
4
|
-
这是一个虚拟的pty shell ,可以用来过滤或者记录可执行命令, 并可以用于浏览器环境, 目前并不支持管道等功能,支持使用 node-pty ,更多使用例子目前可以参考 filecat(https://github.com/xiaobaidadada/filecat)项目中的代码 。
|
|
5
|
-
需要配合 xterm.js 类似的项目组合使用
|
|
6
|
-
# Sample Example
|
|
7
|
-
```js
|
|
8
|
-
import {PtyShell} from "pty-shell";
|
|
9
|
-
|
|
10
|
-
const ptyShell = new PtyShell({
|
|
11
|
-
cols: 200,
|
|
12
|
-
rows: 300,
|
|
13
|
-
cwd: __dirname,
|
|
14
|
-
node_pty:undefined,
|
|
15
|
-
node_pty_shell_list: [],
|
|
16
|
-
env:{},
|
|
17
|
-
on_call:(data)=>{
|
|
18
|
-
console.log(data)
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
ptyShell.write("cd .. \r");
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
# supports
|
|
26
|
-
1. commands auto-completion
|
|
27
|
-
2. command and parameter interception and filtering
|
|
28
|
-
3. browser environment
|
|
29
|
-
4. use node-pty
|
|
1
|
+
# pty-shell
|
|
2
|
+
This is a virtual PTY shell that can be used to filter or log executable commands. It can also be used in a browser environment. Currently, it does not support features like piping. It supports the use of `node-pty`. For more usage examples, you can refer to the code in the [filecat](https://github.com/xiaobaidadada/filecat) project.
|
|
3
|
+
It needs to be used in combination with projects similar to xterm.js.
|
|
4
|
+
这是一个虚拟的pty shell ,可以用来过滤或者记录可执行命令, 并可以用于浏览器环境, 目前并不支持管道等功能,支持使用 node-pty ,更多使用例子目前可以参考 filecat(https://github.com/xiaobaidadada/filecat)项目中的代码 。
|
|
5
|
+
需要配合 xterm.js 类似的项目组合使用
|
|
6
|
+
# Sample Example
|
|
7
|
+
```js
|
|
8
|
+
import {PtyShell} from "pty-shell";
|
|
9
|
+
|
|
10
|
+
const ptyShell = new PtyShell({
|
|
11
|
+
cols: 200,
|
|
12
|
+
rows: 300,
|
|
13
|
+
cwd: __dirname,
|
|
14
|
+
node_pty:undefined,
|
|
15
|
+
node_pty_shell_list: [],
|
|
16
|
+
env:{},
|
|
17
|
+
on_call:(data)=>{
|
|
18
|
+
console.log(data)
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
ptyShell.write("cd .. \r");
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# supports
|
|
26
|
+
1. commands auto-completion
|
|
27
|
+
2. command and parameter interception and filtering
|
|
28
|
+
3. browser environment
|
|
29
|
+
4. use node-pty
|
|
30
30
|
5. operations such as command, select all, move, select, etc., similar to those in PowerShell.
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ interface Param extends Partial<PtyShellUserMethod> {
|
|
|
38
38
|
rows?: number;
|
|
39
39
|
env?: any;
|
|
40
40
|
node_pty_shell_list?: string[];
|
|
41
|
+
history_line?: string[];
|
|
42
|
+
history_line_max?: number;
|
|
41
43
|
}
|
|
42
44
|
type CmdHandler = (params: string[], send_prompt?: (data: string) => void) => void;
|
|
43
45
|
export declare class PtyShell implements PtyShellUserMethod {
|
|
@@ -53,6 +55,7 @@ export declare class PtyShell implements PtyShellUserMethod {
|
|
|
53
55
|
char_num: number;
|
|
54
56
|
};
|
|
55
57
|
on_call: (data: string) => void;
|
|
58
|
+
on_call_child_raw?: (data: string) => void;
|
|
56
59
|
on_control_cmd: (type: exec_cmd_type, data?: string) => void;
|
|
57
60
|
on_child_kill?: (code: number, pid?: number) => void;
|
|
58
61
|
check_exe_cmd: any;
|
|
@@ -75,6 +78,7 @@ export declare class PtyShell implements PtyShellUserMethod {
|
|
|
75
78
|
private select_end;
|
|
76
79
|
private history_line;
|
|
77
80
|
private history_line_index;
|
|
81
|
+
private history_line_max;
|
|
78
82
|
/**
|
|
79
83
|
* public method
|
|
80
84
|
*/
|
package/dist/index.js
CHANGED
|
@@ -99,6 +99,7 @@ class PtyShell {
|
|
|
99
99
|
this.select_end = -2;
|
|
100
100
|
this.history_line = [];
|
|
101
101
|
this.history_line_index = -1;
|
|
102
|
+
this.history_line_max = 20;
|
|
102
103
|
this.next_not_enter = false;
|
|
103
104
|
this.reset_option(param);
|
|
104
105
|
if (!this.not_use_node_pre_cmd_exec) {
|
|
@@ -712,7 +713,7 @@ class PtyShell {
|
|
|
712
713
|
return; // 和最后的一样就不插入了
|
|
713
714
|
}
|
|
714
715
|
this.history_line.push(line);
|
|
715
|
-
if (this.history_line.length >
|
|
716
|
+
if (this.history_line.length > this.history_line_max) {
|
|
716
717
|
this.history_line.shift(); // 删除最前面的
|
|
717
718
|
}
|
|
718
719
|
this.history_line_index = -1;
|
|
@@ -832,6 +833,9 @@ class PtyShell {
|
|
|
832
833
|
this.child = this.node_pty.spawn(exe, params, Object.assign({ name: 'xterm-color', cols: this.cols, rows: this.rows, cwd: this.cwd, useConptyDll: false, useConpty: process.env.NODE_ENV !== "production" ? false : undefined, env: Object.assign(Object.assign({}, process.env), this.env) }, spawn_option));
|
|
833
834
|
this.child.onData((data) => {
|
|
834
835
|
this.on_call(data.toString());
|
|
836
|
+
if (this.on_call_child_raw) {
|
|
837
|
+
this.on_call_child_raw(data);
|
|
838
|
+
}
|
|
835
839
|
});
|
|
836
840
|
this.child.onExit(({ exitCode, signal }) => {
|
|
837
841
|
this.close_child(exitCode);
|
|
@@ -855,11 +859,17 @@ class PtyShell {
|
|
|
855
859
|
this.child.stdout.on('data', (data) => {
|
|
856
860
|
// const v = data.toString(); // 子程序没有换行等符号不会立即输出 有缓冲区
|
|
857
861
|
this.send_and_enter(data.toString());
|
|
862
|
+
if (this.on_call_child_raw) {
|
|
863
|
+
this.on_call_child_raw(data);
|
|
864
|
+
}
|
|
858
865
|
});
|
|
859
866
|
this.child.stderr.on('data', (data) => {
|
|
860
867
|
// const v = data.toString();
|
|
861
868
|
this.send_and_enter(data.toString());
|
|
862
869
|
this.next_not_enter = false; // 下一次的换行输出 上一次没有换行
|
|
870
|
+
if (this.on_call_child_raw) {
|
|
871
|
+
this.on_call_child_raw(data);
|
|
872
|
+
}
|
|
863
873
|
});
|
|
864
874
|
this.child.on('exit', (code) => {
|
|
865
875
|
this.close_child(code);
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pty-shell",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "a virtual PTY shell for javaScript",
|
|
5
|
-
"author": "xiaobaidadada",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git@github.com:xiaobaidadada/pty-shell.git"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/xiaobaidadada/pty-shell",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/xiaobaidadada/pty-shell/issues"
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "tsc"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@types/node": "^22.13.10",
|
|
21
|
-
"typescript": "^5.5.3"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist/**/*",
|
|
25
|
-
"LICENSE.txt",
|
|
26
|
-
"README.md",
|
|
27
|
-
"package.json"
|
|
28
|
-
],
|
|
29
|
-
"keywords":[
|
|
30
|
-
"pty",
|
|
31
|
-
"shell",
|
|
32
|
-
"tty",
|
|
33
|
-
"terminal",
|
|
34
|
-
"browser",
|
|
35
|
-
"web",
|
|
36
|
-
"virtual",
|
|
37
|
-
"command intercept"
|
|
38
|
-
]
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pty-shell",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "a virtual PTY shell for javaScript",
|
|
5
|
+
"author": "xiaobaidadada",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git@github.com:xiaobaidadada/pty-shell.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/xiaobaidadada/pty-shell",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/xiaobaidadada/pty-shell/issues"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.13.10",
|
|
21
|
+
"typescript": "^5.5.3"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/**/*",
|
|
25
|
+
"LICENSE.txt",
|
|
26
|
+
"README.md",
|
|
27
|
+
"package.json"
|
|
28
|
+
],
|
|
29
|
+
"keywords":[
|
|
30
|
+
"pty",
|
|
31
|
+
"shell",
|
|
32
|
+
"tty",
|
|
33
|
+
"terminal",
|
|
34
|
+
"browser",
|
|
35
|
+
"web",
|
|
36
|
+
"virtual",
|
|
37
|
+
"command intercept"
|
|
38
|
+
]
|
|
39
|
+
}
|