Skip to content

Commit 8a186bf

Browse files
committed
feature(gritty) add support of cwd
1 parent da103cd commit 8a186bf

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ socket.use((socket, next) => {
142142
prefix: 'console',
143143
command: 'bash', // optional
144144
autoRestart: true, // optional
145+
cwd: '/', // optional
145146
env: {
146147
TERMINAL: 'gritty',
147148
CURRENT: getCurrentFile,

client/gritty.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function gritty(element, options = {}) {
4343
const {
4444
command,
4545
autoRestart,
46+
cwd,
4647
} = options;
4748

4849
const socket = connect(prefix, socketPath);
@@ -51,14 +52,15 @@ function gritty(element, options = {}) {
5152

5253
return createTerminal(el, {
5354
env,
55+
cwd,
5456
command,
5557
autoRestart,
5658
socket,
5759
fontFamily,
5860
});
5961
}
6062

61-
function createTerminal(terminalContainer, {env, command, autoRestart, socket, fontFamily}) {
63+
function createTerminal(terminalContainer, {env, cwd, command, autoRestart, socket, fontFamily}) {
6264
const terminal = new Terminal({
6365
scrollback: 1000,
6466
tabStopWidth: 4,
@@ -77,7 +79,7 @@ function createTerminal(terminalContainer, {env, command, autoRestart, socket, f
7779

7880
const {cols, rows} = terminal.proposeGeometry();
7981

80-
socket.on('accept', onConnect(socket, terminal, {env, cols, rows, command, autoRestart}));
82+
socket.on('accept', onConnect(socket, terminal, {env, cwd, cols, rows, command, autoRestart}));
8183
socket.on('disconnect', onDisconnect(terminal));
8284
socket.on('data', onData(terminal));
8385

@@ -87,8 +89,8 @@ function createTerminal(terminalContainer, {env, command, autoRestart, socket, f
8789
};
8890
}
8991

90-
function _onConnect(socket, terminal, {env, cols, rows, command, autoRestart}) {
91-
socket.emit('terminal', {env, cols, rows, command, autoRestart});
92+
function _onConnect(socket, terminal, {env, cwd, cols, rows, command, autoRestart}) {
93+
socket.emit('terminal', {env, cwd, cols, rows, command, autoRestart});
9294
socket.emit('resize', {cols, rows});
9395
terminal.fit();
9496
}

server/gritty.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function staticFn(req, res) {
6262
res.sendFile(file);
6363
}
6464

65-
function createTerminal({command, env, cols, rows}) {
65+
function createTerminal({command, env, cwd, cols, rows}) {
6666
cols = cols || 80;
6767
rows = rows || 24;
6868

@@ -71,7 +71,7 @@ function createTerminal({command, env, cols, rows}) {
7171
name: 'xterm-color',
7272
cols,
7373
rows,
74-
cwd: process.env.PWD,
74+
cwd,
7575
env: {
7676
...process.env,
7777
...env,
@@ -151,10 +151,12 @@ function connection(options, socket) {
151151
const {
152152
rows,
153153
cols,
154+
cwd,
154155
} = params;
155156

156157
term = createTerminal({
157158
command,
159+
cwd,
158160
env,
159161
rows,
160162
cols,

test/client/gritty.js

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ test('gritty: onConnect: socket: terminal', (t) => {
157157
},
158158
cols: 80,
159159
rows: 25,
160+
cwd: '/',
160161
command: 'bash',
161162
autoRestart: false,
162163
};

webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module.exports = {
4848
rules,
4949
},
5050
performance: {
51-
maxEntrypointSize: 300000,
52-
maxAssetSize: 300000
51+
maxEntrypointSize: 400000,
52+
maxAssetSize: 400000
5353
},
5454
};
5555

0 commit comments

Comments
 (0)