Comparing version
47
index.js
@@ -29,6 +29,6 @@ #! /usr/bin/env node | ||
const identity = uuid.v4(); | ||
const shell = enchannel.createShellSubject(identity, c.config); | ||
const stdin = enchannel.createStdinSubject(identity, c.config); | ||
// const iopub = enchannel.createIOPubSubject(identity, kernel); | ||
const shell = enchannel.createShellSubject(identity, c.config); | ||
// const control = enchannel.createControlSubject(identity, kernel); | ||
// const stdinChannel = enchannel.createStdinSubject(identity, kernel); | ||
@@ -60,3 +60,22 @@ function createMessage(session, msg_type) { | ||
function startREPL(langInfo) { | ||
const rl = readline.createInterface(process.stdin, process.stdout); | ||
const rl = readline.createInterface(process.stdin, process.stdout, (line, callback) => { | ||
const completeRequest = createMessage(sessionID, 'complete_request'); | ||
completeRequest.content = { | ||
code: line, | ||
cursor_pos: line.length, | ||
}; | ||
const childMessages = shell.filter(isChildMessage.bind(completeRequest)); | ||
const completeReply = childMessages | ||
.filter(msg => msg.header.msg_type === 'complete_reply') | ||
.map(msg => msg.content); | ||
completeReply.subscribe(content => { | ||
callback(null, [content.matches, line]); | ||
}); | ||
shell.next(completeRequest); | ||
}); | ||
const iopub = enchannel.createIOPubSubject(identity, c.config); | ||
@@ -80,3 +99,3 @@ | ||
user_expressions: {}, | ||
allow_stdin: false, | ||
allow_stdin: true, | ||
stop_on_error: false, | ||
@@ -174,2 +193,21 @@ }; | ||
const stdinResponseMsgs = stdin | ||
.filter(isChildMessage.bind(executeRequest)) | ||
.publish() | ||
.refCount(); | ||
const inputRequests = stdinResponseMsgs | ||
.filter(msg => msg.header.msg_type === 'input_request') | ||
.map(msg => msg.content); | ||
inputRequests.subscribe(msg => { | ||
rl.question(chalk.green(msg.prompt), response => { | ||
const inputReply = createMessage(sessionID, 'input_reply'); | ||
inputReply.content = { | ||
value: response, | ||
}; | ||
stdin.next(inputReply); | ||
}); | ||
}); | ||
shell.next(executeRequest); | ||
@@ -182,2 +220,3 @@ | ||
iopub.complete(); | ||
stdin.complete(); | ||
process.stdin.destroy(); | ||
@@ -184,0 +223,0 @@ fs.unlink(c.connFile); |
{ | ||
"name": "ick", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Interactive Console Experiment", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"marked-terminal": "^1.6.1", | ||
"spawnteract": "0.0.4", | ||
"spawnteract": "0.1.0", | ||
"temp": "^0.8.3", | ||
@@ -24,0 +24,0 @@ "uuid": "^2.0.1" |
11875
12.58%195
18.9%+ Added
+ Added
- Removed
- Removed
Updated