Skip to content

Commit df51d52

Browse files
committed
set termios
1 parent f3587ae commit df51d52

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

entry/src/main/cpp/napi_init.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdlib.h>
1616
#include <string>
1717
#include <sys/time.h>
18+
#include <termios.h>
1819
#include <unistd.h>
1920
#include <vector>
2021

@@ -137,13 +138,48 @@ static napi_value run(napi_env env, napi_callback_info info) {
137138
struct winsize ws = {};
138139
ws.ws_col = width;
139140
ws.ws_row = height;
140-
int pid = forkpty(&fd, nullptr, nullptr, &ws);
141+
142+
// termios
143+
struct termios t {};
144+
struct termios *term = &t;
145+
146+
term->c_iflag = ICRNL | IXON | IUTF8;
147+
term->c_oflag = NL0 | CR0 | TAB0 | BS0 | VT0 | FF0 | OPOST | ONLCR;
148+
term->c_cflag = B38400 | CS8 | CREAD;
149+
// ICANON | ECHO removed
150+
term->c_lflag = ISIG | ECHOE | ECHOK | IEXTEN | ECHOCTL | ECHOKE;
151+
152+
term->c_cc[VINTR] = 0x3;
153+
term->c_cc[VQUIT] = 0x1c;
154+
term->c_cc[VERASE] = 0x7f;
155+
term->c_cc[VKILL] = 0x15;
156+
term->c_cc[VEOF] = 0x4;
157+
term->c_cc[VMIN] = 0x1;
158+
term->c_cc[VSTART] = 0x11;
159+
term->c_cc[VSTOP] = 0x13;
160+
term->c_cc[VSUSP] = 0x1a;
161+
term->c_cc[VREPRINT] = 0x12;
162+
term->c_cc[VDISCARD] = 0xf;
163+
term->c_cc[VWERASE] = 0x17;
164+
term->c_cc[VLNEXT] = 0x16;
165+
166+
term->c_cc[19] = 0x7f;
167+
term->c_cc[24] = 0x20;
168+
term->c_cc[25] = 0x88;
169+
term->c_cc[26] = 0xb6;
170+
term->c_cc[27] = 0x7f;
171+
term->c_cc[31] = 0x78;
172+
173+
int pid = forkpty(&fd, nullptr, term, &ws);
141174

142175
if (!pid) {
143176
const char *home = "/storage/Users/currentUser";
144177
setenv("HOME", home, 1);
145178
setenv("PWD", home, 1);
146-
setenv("PATH", "/data/app/bin:/data/service/hnp/bin:/bin:/usr/local/bin:/usr/bin:/system/bin:/vendor/bin", 1);
179+
setenv("PATH",
180+
"/data/app/bin:/data/service/hnp/bin:/bin:"
181+
"/usr/local/bin:/usr/bin:/system/bin:/vendor/bin",
182+
1);
147183

148184
chdir(home);
149185
execl("/bin/sh", "/bin/sh", nullptr);

0 commit comments

Comments
 (0)