Skip to content

Commit 2df7296

Browse files
committed
Update notebook
1 parent faea62c commit 2df7296

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/notebook.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ class RKernel {
5656
if (this.process) {
5757
const client = net.createConnection({ port: this.port }, () => {
5858
console.log('connected to server!');
59-
const json = `{"time":"${Date.now().toString()}","expr":"rnorm(3)"}\n`;
60-
console.log(`Send: ${json}`);
61-
client.write(json);
59+
const request = JSON.stringify({
60+
time: Date.now(),
61+
expr: cell.document.getText(),
62+
}).concat('\n');
63+
console.log(`Send: ${request}`);
64+
client.write(request);
6265
});
6366

6467
client.on('end', () => {
@@ -67,10 +70,12 @@ class RKernel {
6770

6871
return new Promise((resolve, reject) => {
6972
client.on('data', (data) => {
70-
const result = data.toString();
71-
console.log(result);
73+
const response = data.toString();
74+
console.log(response);
7275
client.end();
73-
resolve(result);
76+
const output = JSON.parse(response);
77+
const result: string[] = output.result;
78+
resolve(result.join('\n'));
7479
});
7580

7681
client.on('error', (err) => {

0 commit comments

Comments
 (0)