pty-shell 1.0.5 → 1.1.0

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 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 {
@@ -75,6 +77,7 @@ export declare class PtyShell implements PtyShellUserMethod {
75
77
  private select_end;
76
78
  private history_line;
77
79
  private history_line_index;
80
+ private history_line_max;
78
81
  /**
79
82
  * public method
80
83
  */
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) {
@@ -334,8 +335,12 @@ class PtyShell {
334
335
  if (this.child) {
335
336
  // SystemUtil.killProcess(this.child.pid);
336
337
  const pid = this.child.pid;
337
- this.child.kill(); // 不同平台信号不同 win 默认 SIGHUP
338
- this.exec_end_call(code, pid);
338
+ if (this.on_child_kill) {
339
+ this.exec_end_call(code, pid);
340
+ }
341
+ else {
342
+ this.child.kill(); // 不同平台信号不同 win 默认 SIGHUP
343
+ }
339
344
  this.child = undefined;
340
345
  }
341
346
  }
@@ -708,7 +713,7 @@ class PtyShell {
708
713
  return; // 和最后的一样就不插入了
709
714
  }
710
715
  this.history_line.push(line);
711
- if (this.history_line.length > 20) {
716
+ if (this.history_line.length > this.history_line_max) {
712
717
  this.history_line.shift(); // 删除最前面的
713
718
  }
714
719
  this.history_line_index = -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pty-shell",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "a virtual PTY shell for javaScript",
5
5
  "author": "xiaobaidadada",
6
6
  "main": "dist/index.js",