elphadeal-terminal 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/dist/cli.js +38 -9
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const readline = require('readline');
6
- const { exec } = require('child_process');
6
+ const { exec, spawn } = require('child_process');
7
7
 
8
8
  // Load wasm_exec.js
9
9
  require('./wasm_exec.js');
@@ -15,6 +15,7 @@ const rl = readline.createInterface({
15
15
  });
16
16
 
17
17
  let goInstance;
18
+ let currentChild = null;
18
19
 
19
20
  function displayError(command, error, stderr) {
20
21
  console.log('\x1b[31m╔══════════════════════════════════════╗\x1b[0m');
@@ -43,7 +44,7 @@ function displaySuccess(command, stdout) {
43
44
 
44
45
  function displayWarning(stderr) {
45
46
  console.log('\x1b[33m╔══════════════════════════════════════╗\x1b[0m');
46
- console.log('\x1b[33m║ ⚠️ WARNING ║\x1b[0m');
47
+ console.log('\x1b[33m║ ⚠️ WARNING ║\x1b[0m');
47
48
  console.log('\x1b[33m╚══════════════════════════════════════╝\x1b[0m');
48
49
  console.log(`\x1b[33m${stderr}\x1b[0m`);
49
50
  console.log('\x1b[33m════════════════════════════════════════\x1b[0m');
@@ -78,6 +79,16 @@ async function init() {
78
79
  rl.setPrompt('\x1b[32m>\x1b[0m ');
79
80
  rl.prompt();
80
81
 
82
+ // Handle Ctrl+C to interrupt running child process or exit
83
+ rl.on('SIGINT', () => {
84
+ if (currentChild) {
85
+ console.log('\n^C');
86
+ currentChild.kill('SIGINT');
87
+ } else {
88
+ rl.close();
89
+ }
90
+ });
91
+
81
92
  // Set up event listener after init
82
93
  rl.on('line', (line) => {
83
94
  const command = line.trim();
@@ -94,17 +105,35 @@ async function init() {
94
105
  } else {
95
106
  // For other commands, try to execute them
96
107
  console.log(`\x1b[34mExecuting: ${command}\x1b[0m`);
97
- exec(command, (error, stdout, stderr) => {
98
- if (error) {
99
- displayError(command, error, stderr);
100
- } else if (stderr) {
101
- displayWarning(stderr);
102
- displaySuccess(command, stdout);
108
+ // Spawn child with shell to stream stdout/stderr in real-time (works cross-platform)
109
+ currentChild = spawn(command, { shell: true });
110
+
111
+ currentChild.stdout.on('data', (data) => {
112
+ process.stdout.write(data.toString());
113
+ });
114
+
115
+ currentChild.stderr.on('data', (data) => {
116
+ process.stderr.write(data.toString());
117
+ });
118
+
119
+ currentChild.on('error', (err) => {
120
+ displayError(command, err, null);
121
+ currentChild = null;
122
+ rl.prompt();
123
+ });
124
+
125
+ currentChild.on('close', (code, signal) => {
126
+ if (signal) {
127
+ displayWarning(`Process terminated with signal: ${signal}`);
128
+ } else if (code !== 0) {
129
+ displayError(command, { code: code, message: `Exited with code ${code}` }, null);
103
130
  } else {
104
- displaySuccess(command, stdout);
131
+ displaySuccess(command, null);
105
132
  }
133
+ currentChild = null;
106
134
  rl.prompt();
107
135
  });
136
+
108
137
  return; // Don't prompt again here
109
138
  }
110
139
  rl.prompt();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elphadeal-terminal",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A custom terminal design powered by Go WebAssembly",
5
5
  "main": "dist/index.js",
6
6
  "bin": {