Comparing version
83
index.js
@@ -10,2 +10,4 @@ #! /usr/bin/env node | ||
const Rx = require('@reactivex/rxjs'); | ||
const readline = require('readline'); | ||
@@ -32,3 +34,3 @@ | ||
// const stdinChannel = enchannel.createStdinSubject(identity, kernel); | ||
function createMessage(session, msg_type) { | ||
@@ -51,20 +53,22 @@ const username = process.env.LOGNAME || process.env.USER || | ||
} | ||
const sessionID = uuid.v4(); | ||
function isChildMessage(msg) { | ||
return this.header.msg_id === msg.parent_header.msg_id; | ||
} | ||
function startREPL(langInfo) { | ||
const rl = readline.createInterface(process.stdin, process.stdout); | ||
const iopub = enchannel.createIOPubSubject(identity, c.config); | ||
marked.setOptions({ | ||
renderer: new TerminalRenderer(), | ||
}); | ||
rl.setPrompt(`ick${langInfo.file_extension}> `); | ||
var counter = 1; | ||
rl.setPrompt(`ick${langInfo.file_extension}:${counter}> `); | ||
rl.prompt(); | ||
rl.on('line', (line) => { | ||
@@ -80,7 +84,7 @@ const executeRequest = createMessage(sessionID, 'execute_request'); | ||
}; | ||
const childMessages = iopub.filter(isChildMessage.bind(executeRequest)) | ||
.publish() | ||
.refCount(); | ||
const displayData = childMessages | ||
@@ -91,11 +95,17 @@ .filter(msg => msg.header.msg_type === 'execute_result' || | ||
.map(msg => msg.content.data); | ||
const executeResult = childMessages.filter(msg => msg.header.msg_type === 'execute_result') | ||
.map(msg => msg.content); | ||
const executeReply = childMessages | ||
.filter(msg => msg.header.msg_type === 'execute_reply') | ||
.map(msg => msg.content); | ||
const status = childMessages.filter(msg => msg.header.msg_type === 'status') | ||
.map(msg => msg.content.execution_state); | ||
const streamReply = childMessages | ||
.filter(msg => msg.header.msg_type === 'stream') | ||
.map(msg => msg.content); | ||
streamReply.subscribe(content => { | ||
@@ -111,3 +121,3 @@ switch(content.name) { | ||
}); | ||
displayData.subscribe(data => { | ||
@@ -137,22 +147,32 @@ if(data['image/png']) { | ||
}); | ||
executeReply.subscribe(content => { | ||
rl.setPrompt(`ick${langInfo.file_extension}:${content.execution_count}> `); | ||
rl.prompt(); | ||
}); | ||
shell.send(executeRequest); | ||
Rx.Observable.merge(executeResult, executeReply) | ||
.map(content => content.execution_count) | ||
.take(1) | ||
.subscribe(ct => { | ||
counter = ct + 1; | ||
}); | ||
status.filter(x => x === 'idle') | ||
.subscribe(() => { | ||
rl.setPrompt(`ick${langInfo.file_extension}:${counter}> `); | ||
rl.prompt(); | ||
}, console.error); | ||
shell.next(executeRequest); | ||
}).on('close', () => { | ||
console.log('Have a great day!'); | ||
shell.close(); | ||
iopub.close(); | ||
c.spawn.kill(); | ||
shell.complete(); | ||
iopub.complete(); | ||
process.stdin.destroy(); | ||
fs.unlink(c.connFile); | ||
}); | ||
} | ||
const kernelInfoRequest = createMessage(sessionID, 'kernel_info_request'); | ||
const kernelReply = shell.filter(msg => msg.parent_header.msg_id === kernelInfoRequest.header.msg_id) | ||
.map(msg => msg.content); | ||
kernelReply.subscribe(content => { | ||
@@ -162,10 +182,11 @@ process.stdout.write(chalk.green(content.banner)); | ||
}); | ||
shell.send(kernelInfoRequest); | ||
shell.next(kernelInfoRequest); | ||
} | ||
// TODO: Launch a kernel | ||
// For now, rely on an argument for a kernel runtime | ||
const kernelName = process.argv[2]; | ||
spawnteract.launch(kernelName).then(main) | ||
spawnteract.launch(kernelName) | ||
.then(main) | ||
.catch(e => { | ||
console.error(e); | ||
}); |
{ | ||
"name": "ick", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Interactive Console Experiment", | ||
@@ -15,4 +15,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"@reactivex/rxjs": "^5.0.0-beta.1", | ||
"chalk": "^1.1.1", | ||
"enchannel-zmq-backend": "^0.4.0", | ||
"enchannel-zmq-backend": "^1.0.0", | ||
"image-to-ascii": "^2.3.1", | ||
@@ -24,3 +25,18 @@ "marked": "^0.3.5", | ||
"uuid": "^2.0.1" | ||
} | ||
}, | ||
"devDependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/nteract/ick.git" | ||
}, | ||
"keywords": [ | ||
"interactive", | ||
"console", | ||
"jupyter", | ||
"nteract" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/nteract/ick/issues" | ||
}, | ||
"homepage": "https://github.com/nteract/ick#readme" | ||
} |
@@ -10,4 +10,3 @@ # Interactive Console Experiments | ||
Make sure you have zmq headers for your platform, build tools, yada yada. | ||
(Editor's Note: Surely there's a more substantive way to express this.) | ||
Make sure you have [zmq headers for your platform, build tools, yada yada](https://github.com/nteract/enchannel-zmq-backend#zeromq-dependency). | ||
@@ -18,3 +17,3 @@ ``` | ||
:warning: This is full of bugs! Files aren't cleaned up yet! :warning: | ||
:warning: This is full of bugs. Check out the issues to find out how to help! | ||
@@ -21,0 +20,0 @@ ## Running |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9871
11.89%152
12.59%1
-50%2
-33.33%5
-16.67%9
12.5%41
-2.38%+ Added
+ Added
- Removed
- Removed
Updated