Skip to content

Commit e31dc45

Browse files
committed
fix(console) event path -> label
1 parent 6d3cb96 commit e31dc45

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ For more details see [Jq-console keyboard shortcuts](https://github.com/replit/j
3636

3737
### Client API
3838

39-
`Console` inhertis from [Emitify](https://github.com/coderaiser/emitify) so you can subscribe to next events:
40-
41-
- `path`
42-
43-
```js
44-
const konsole = Console();
45-
konsole.on('path', console.log);
46-
```
47-
4839
#### Console(element [, options, prefix], callback)
4940

5041
- element - html element, or selector

client/console.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ require('../css/ansi.css');
88
module.exports = ConsoleProto;
99

1010
const load = require('load.js');
11-
const inherits = require('inherits');
12-
const Emitify = require('emitify/legacy');
1311
const currify = require('currify/legacy');
1412
const getHost = require('./get-host');
1513
const getEnv = require('./get-env');
@@ -18,8 +16,6 @@ const isFn = (fn) => typeof fn === 'function';
1816
const exec = (fn, ...a) => isFn(fn) && fn(...a);
1917
const sum = currify((a, b) => a + b);
2018

21-
inherits(ConsoleProto, Emitify);
22-
2319
function ConsoleProto(element, options, callback) {
2420
let Spawn;
2521
let jqconsole;
@@ -28,7 +24,6 @@ function ConsoleProto(element, options, callback) {
2824
if (!(this instanceof ConsoleProto))
2925
return new ConsoleProto(element, options, callback);
3026

31-
Emitify.call(this);
3227
Console(element, options, callback);
3328

3429
const self = this;
@@ -212,15 +207,13 @@ function ConsoleProto(element, options, callback) {
212207
self.setPromptText(promptText.pop());
213208
});
214209

215-
socket.on('path', (path) => {
210+
socket.on('label', (path) => {
216211
if (commands.length)
217212
execute(commands.pop(), env);
218213
else
219214
setPromptLabel(path + '> ');
220215

221216
cwd = path;
222-
223-
self.emit('path', path);
224217
});
225218

226219
socket.on('connect', () => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"rendy": "^1.1.0",
4141
"socket.io": "^2.0.1",
4242
"spawnify": "^4.0.0",
43-
"tildify": "^1.2.0"
43+
"tildify": "^1.2.0",
44+
"untildify": "^3.0.2"
4445
},
4546
"devDependencies": {
4647
"babel-core": "^6.25.0",
@@ -49,7 +50,6 @@
4950
"babel-preset-env": "^1.6.0",
5051
"clean-css-loader": "^0.1.2",
5152
"css-loader": "^0.28.4",
52-
"emitify": "^3.1.0",
5353
"eslint": "^4.0.0",
5454
"inherits": "^2.0.3",
5555
"load.js": "^1.1.5",

server/console.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
const io = require('socket.io');
44
const tildify = require('tildify');
55
const debug = require('debug');
6+
67
const logConsole = debug('console');
78
const logClients = debug('console:clients');
9+
const rmLastSlash = (a) => a.replace(/\/$/, '') || '/';
810

911
const WIN = process.platform === 'win32';
1012
const CWD = process.cwd();
1113

1214
const Clients = [];
1315

16+
const cwd = (conNum) => (path) => {
17+
if (!path)
18+
return Clients[conNum].cwd;
19+
20+
Clients[conNum].cwd = path;
21+
};
22+
1423
let Socket;
1524
let ConNum = -1;
1625

@@ -62,7 +71,7 @@ function onConnection(options, socket) {
6271
const dir = WIN ? cwd : tildify(cwd);
6372

6473
socket.emit('data', msg);
65-
socket.emit('path', options.prompt || dir);
74+
socket.emit('label', options.prompt || rmLastSlash(dir));
6675
socket.emit('prompt');
6776

6877
Clients[ConNum] = {
@@ -100,15 +109,6 @@ function processing(socket, conNum, fn, command) {
100109
fn(socket, command, cwd(conNum));
101110
}
102111

103-
function cwd(conNum) {
104-
return (path) => {
105-
if (!path)
106-
return Clients[conNum].cwd;
107-
108-
Clients[conNum].cwd = path;
109-
};
110-
}
111-
112112
function getType(type) {
113113
if (!type)
114114
return ' ';

server/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ const join = require('join-io');
77
const spawnify = require('spawnify');
88
const rendy = require('rendy');
99

10+
const untildify = require('untildify');
1011
const express = require('express');
1112
const currify = require('currify/legacy');
1213
const Router = express.Router;
1314

1415
const modules = require('../json/modules');
1516

17+
const rmLastSlash = (a) => a.replace(/\/$/, '') || '/';
18+
const addLastSlash = (a) => a[a.length - 1] === '/' ? a : `${a}/`;
19+
1620
const modulesFn = currify(_modulesFn);
1721
const joinFn = currify(_joinFn);
1822
const konsoleFn = currify(_konsoleFn);
@@ -169,7 +173,9 @@ function execute(socket, command, cwd) {
169173
}
170174

171175
function onPath(path) {
172-
socket.emit('path', path);
176+
socket.emit('label', rmLastSlash(path));
177+
socket.emit('path', addLastSlash(untildify(path)));
178+
173179
cwd(path);
174180
}
175181

0 commit comments

Comments
 (0)