pinokiod 3.12.2 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/kernel/plugin.js CHANGED
@@ -4,9 +4,7 @@ class Plugin {
4
4
  this.kernel = kernel
5
5
  }
6
6
  async init() {
7
- console.log("Plugin.init")
8
7
  if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
9
- console.log("INSTALLED")
10
8
  // if ~/pinokio/prototype doesn't exist, clone
11
9
  let exists = await this.kernel.exists("plugin")
12
10
  if (!exists) {
@@ -18,13 +16,9 @@ class Plugin {
18
16
  process.stdout.write(e.raw)
19
17
  })
20
18
  }
21
- console.log("#################")
22
-
23
19
  let plugin_dir = path.resolve(this.kernel.homedir, "plugin")
24
20
  let pinokiojs = path.resolve(plugin_dir, "pinokio.js")
25
- console.log("pinokiojs", pinokiojs)
26
21
  this.config = await this.kernel.require(pinokiojs)
27
- console.log("this.config", this.config)
28
22
  }
29
23
  }
30
24
  async update() {
@@ -27,7 +27,6 @@ class Proto {
27
27
 
28
28
  let pinokiojs_path = this.kernel.path("prototype/system/pinokio.js")
29
29
  let config = await this.kernel.require(pinokiojs_path)
30
- console.log("--config", config)
31
30
  this.config = config
32
31
 
33
32
  if (this.config && this.config.menu) {
package/kernel/shell.js CHANGED
@@ -55,7 +55,6 @@ class Shell {
55
55
  }
56
56
  this.queue = fastq((data, cb) => {
57
57
  this.stream(data, cb)
58
- // cb()
59
58
  }, 1)
60
59
 
61
60
  }
@@ -201,6 +200,8 @@ class Shell {
201
200
  }
202
201
  }
203
202
  async start(params, ondata) {
203
+ this.written = 0;
204
+ this.pendingCallbacks = 0;
204
205
  this.ondata = ondata
205
206
 
206
207
  /*
@@ -323,28 +324,38 @@ class Shell {
323
324
  this.ptyProcess.resize(cols, rows)
324
325
  this.vt.resize(cols, rows)
325
326
  }
326
- emit2(message) {
327
- console.log("emit2", message)
328
- let i = 0;
329
- const interval = setInterval(() => {
330
- if (i >= message.length) {
331
- clearInterval(interval);
332
- return;
333
- }
334
- let chunk = message.slice(i, i+1024)
335
- console.log("chunk", i, chunk)
327
+ async emit2(message) {
328
+ /*
329
+ // buffer size
330
+ 1. default:256
331
+ 2. "interactive": true => 1024
332
+ 3. "buffer": n => n
333
+ */
334
+ let chunk_size = 256 // default buffer: 256
335
+ if (this.params && this.params.buffer) {
336
+ chunk_size = this.params.buffer
337
+ } else if (this.params.interactive) {
338
+ chunk_size = 1024
339
+ }
340
+ console.log({ interactive: this.params.interactive, chunk_size })
341
+ for(let i=0; i<message.length; i+=chunk_size) {
342
+ let chunk = message.slice(i, i+chunk_size)
336
343
  this.ptyProcess.write(chunk)
337
- i += 1024;
338
- }, 10);
344
+ this.ondata({ i, total: message.length, type: "emit2" })
345
+ await new Promise(r => setTimeout(r, 10));
346
+ // if (interactive) {
347
+ // await new Promise(queueMicrotask); // zero-delay yield to avoid blocking
348
+ // } else {
349
+ // await new Promise(r => setTimeout(r, 1));
350
+ // }
351
+ }
339
352
  }
340
353
  emit(message) {
341
- if (message.length > 1024) {
342
- this.emit2(message)
343
- } else {
354
+ if (this.input) {
344
355
  if (this.ptyProcess) {
345
- if (this.input) {
346
- console.log("emit", { message })
347
- console.log(Buffer.from(message))
356
+ if (message.length > 1024) {
357
+ this.emit2(message)
358
+ } else {
348
359
  this.ptyProcess.write(message)
349
360
  }
350
361
  }
@@ -909,6 +920,7 @@ class Shell {
909
920
  return params
910
921
  }
911
922
  async exec(params) {
923
+ this.watermark = 0
912
924
  params = await this.activate(params)
913
925
  this.cmd = this.build(params)
914
926
  let res = await new Promise((resolve, reject) => {
@@ -928,20 +940,21 @@ class Shell {
928
940
 
929
941
  config.env = this.env
930
942
 
943
+
944
+
945
+
931
946
  if (!this.ptyProcess) {
932
947
  // ptyProcess doesn't exist => create
933
948
  this.done = false
934
949
  this.ptyProcess = pty.spawn(this.shell, this.args, config)
935
950
  this.ptyProcess.onData((data) => {
936
- console.log("onData", { data })
937
- console.log([...data].map(c => c.charCodeAt(0)));
938
951
  if (!this.done) {
939
952
  this.queue.push(data)
940
953
  }
941
954
  });
942
- // this.ptyProcess.onExit((result) => {
943
- // console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
944
- // })
955
+ this.ptyProcess.onExit((result) => {
956
+ console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
957
+ })
945
958
  }
946
959
  } catch (e) {
947
960
  console.log("** Error", e)
@@ -967,6 +980,8 @@ class Shell {
967
980
  }
968
981
  kill(message, force, cb) {
969
982
 
983
+ console.log("KILL", { message })
984
+
970
985
  this.done = true
971
986
  this.ready = false
972
987
 
@@ -1110,6 +1125,7 @@ ${cleaned}
1110
1125
  callback()
1111
1126
  return
1112
1127
  }
1128
+
1113
1129
  this.vt.write(msg, () => {
1114
1130
  let buf = this.vts.serialize()
1115
1131
  let cleaned = this.stripAnsi(buf)
@@ -1121,7 +1137,9 @@ ${cleaned}
1121
1137
  shell_id: this.id
1122
1138
  }
1123
1139
  this.state = cleaned
1124
- if (this.cb) this.cb(response)
1140
+ if (this.cb) {
1141
+ this.cb(response)
1142
+ }
1125
1143
 
1126
1144
  // Decide whether to kill or continue
1127
1145
  if (this.ready) {
package/kernel/shells.js CHANGED
@@ -281,7 +281,12 @@ class Shells {
281
281
  */
282
282
  let session = this.get(params.id)
283
283
  if (session) {
284
- session.emit(params.emit)
284
+ if (params.paste) {
285
+ //session.emit("\x1b[?2004h\x1b[200~" + params.emit+ "\x1b[201~")
286
+ session.emit(params.emit)
287
+ } else {
288
+ session.emit(params.emit)
289
+ }
285
290
  }
286
291
  }
287
292
  async send(params, ondata, enter) {
package/kernel/util.js CHANGED
@@ -92,8 +92,8 @@ const parse_env = async (filename) => {
92
92
  }
93
93
  }
94
94
  const run = (cmd, cwd, kernel) => {
95
- child_process.exec(cmd, { cwd })
96
- /*
95
+ // console.log("Util.run", { cmd, cwd })
96
+ // child_process.exec(cmd, { cwd })
97
97
  if (kernel) {
98
98
  kernel.exec({
99
99
  message: cmd,
@@ -106,8 +106,6 @@ const run = (cmd, cwd, kernel) => {
106
106
  } else {
107
107
  child_process.exec(command)
108
108
  }
109
- */
110
-
111
109
  }
112
110
  const openURL = (url) => {
113
111
  const platform = os.platform()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.12.2",
3
+ "version": "3.13.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -146,7 +146,6 @@ class Server {
146
146
  } else {
147
147
  newIndexPath = "" + i
148
148
  }
149
- console.log({ item, i, indexPath, newIndexPath })
150
149
  traverse(item, newIndexPath);
151
150
  }
152
151
  } else if (obj !== null && typeof obj === 'object') {
@@ -175,9 +174,7 @@ class Server {
175
174
  }
176
175
  }
177
176
  } else if (key === "shell") {
178
- console.log("shell", key, obj[key], indexPath)
179
177
  let shell_id = this.get_shell_id(name, indexPath, obj[key])
180
- console.log("shell_id", shell_id, this.kernel.api.running[shell_id], this.kernel.api.running)
181
178
  if (this.kernel.api.running[shell_id]) {
182
179
  obj.display = "indent"
183
180
  running_dynamic.push(obj)
@@ -3702,13 +3699,9 @@ class Server {
3702
3699
  res.redirect(href)
3703
3700
  } else {
3704
3701
  let run_path = "/run/prototype/system/" + config.href + "?cwd=" + req.query.path
3705
- console.log({ config, run_path, query: req.query })
3706
3702
  let readme_path = this.kernel.path("prototype/system", config.readme)
3707
- console.log("config.readme.split", config.readme.split("/").slice(0, -1))
3708
3703
  let md = await fs.promises.readFile(readme_path, "utf8")
3709
- console.log({ readme_path, md })
3710
3704
  let baseUrl = "/asset/prototype/system/" + (config.readme.split("/").slice(0, -1).join("/")) + "/"
3711
- console.log("baseUrl", baseUrl)
3712
3705
  let readme = marked.parse(md, {
3713
3706
  baseUrl
3714
3707
  })
@@ -3747,7 +3740,6 @@ class Server {
3747
3740
  href: "/prototype/show",
3748
3741
  path: "/asset/prototype/system"
3749
3742
  })
3750
- console.log("FINAL CONFIG", JSON.stringify(config, null, 2))
3751
3743
 
3752
3744
  // {
3753
3745
  // "icon": "fa-solid fa-power-off",
package/server/socket.js CHANGED
@@ -25,7 +25,6 @@ class Socket {
25
25
  });
26
26
  ws.on('message', async (message, isBinary) => {
27
27
  let req
28
- console.log({ message, isBinary })
29
28
  if (isBinary) {
30
29
  const buffer = Buffer.from(message);
31
30
  const sepIndex = buffer.indexOf(0);
@@ -152,7 +151,8 @@ class Socket {
152
151
  } else if (req.key && req.id) {
153
152
  this.parent.kernel.shell.emit({
154
153
  id: req.id,
155
- emit: req.key
154
+ emit: req.key,
155
+ paste: req.paste
156
156
  })
157
157
  } else if (req.resize && req.id) {
158
158
  this.parent.kernel.shell.resize({
@@ -134,6 +134,39 @@ body.frozen {
134
134
  .terminal-container {
135
135
  padding: 0;
136
136
  }
137
+ #status-window {
138
+ /*
139
+ flex-grow: 1;
140
+ text-align: right;
141
+ */
142
+ padding: 0 10px;
143
+ }
144
+ #status-window strong {
145
+ color: royalblue;
146
+ }
147
+ #status-window b {
148
+ color: black;
149
+ font-weight: normal;
150
+ }
151
+ body.dark #status-window b {
152
+ color: white;
153
+ }
154
+ #progress-window {
155
+ flex-shrink: 0;
156
+ width: 100px;
157
+ background: #eee;
158
+ height: 15px;
159
+ /*
160
+ border-radius: 5px;
161
+ */
162
+ overflow: hidden;
163
+ }
164
+ #progress-bar {
165
+ width: 0%;
166
+ height: 100%;
167
+ background: royalblue;
168
+ transition: width 0.2s;
169
+ }
137
170
  </style>
138
171
  <link href="/terminal.css" rel="stylesheet"/>
139
172
  <script>
@@ -296,6 +329,18 @@ document.addEventListener("DOMContentLoaded", async () => {
296
329
  if (packet.data.type === "shell.kill") {
297
330
  this.socket.close()
298
331
  }
332
+ if (packet.data.type === "emit2") {
333
+ // long text => still posting to the shell => show progress
334
+ console.log("emit2", packet.data)
335
+ document.querySelector("#status-window").innerHTML = `<strong>Pasting... (${Math.floor(100 * packet.data.i/packet.data.total)}%)</strong>`
336
+ let percent = Math.floor(100 * packet.data.i/packet.data.total)
337
+ document.querySelector("#progress-window").classList.remove("hidden")
338
+ document.querySelector("#progress-bar").style.width = "" + percent + "%";
339
+ } else {
340
+ document.querySelector("#status-window").innerHTML = "<b>Ready</b>"
341
+ document.querySelector("#progress-window").classList.add("hidden")
342
+ document.querySelector("#progress-bar").style.width = "0%"
343
+ }
299
344
  document.querySelector(".play-btn").classList.add("hidden")
300
345
  document.querySelector(".starting-btn").classList.add("hidden")
301
346
  document.querySelector(".stop-btn").classList.remove("hidden")
@@ -663,11 +708,18 @@ document.addEventListener("DOMContentLoaded", async () => {
663
708
  if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
664
709
  navigator.clipboard.readText().then((text) => {
665
710
  console.log({ text })
711
+ //this.socket.run({
712
+ // //key: "\x1b[200~" + text + "\x1b[201~",
713
+ // key: text,
714
+ // id: shell_id
715
+ //})
666
716
  this.socket.run({
667
717
  //key: "\x1b[200~" + text + "\x1b[201~",
668
718
  key: text,
669
- id: shell_id
719
+ id: shell_id,
720
+ paste: true
670
721
  })
722
+
671
723
  })
672
724
  return false
673
725
  }
@@ -809,6 +861,8 @@ document.addEventListener("DOMContentLoaded", async () => {
809
861
  <div class='hidden btn stopped-btn'>
810
862
  <span class='stopped'><i class="fa-solid fa-hand"></i> Stopped</span>
811
863
  </div>
864
+ <div id='status-window'></div>
865
+ <div id='progress-window' class='hidden'><div id='progress-bar'></div></div>
812
866
  </h1>
813
867
  </header>
814
868
  <div class='terminal-container'>
@@ -105,10 +105,15 @@ header {
105
105
  }
106
106
  */
107
107
  #status-window {
108
+ /*
108
109
  flex-grow: 1;
109
110
  text-align: right;
111
+ */
110
112
  padding: 0 10px;
111
113
  }
114
+ #status-window strong {
115
+ color: royalblue;
116
+ }
112
117
  #status-window b {
113
118
  color: black;
114
119
  font-weight: normal;
@@ -116,6 +121,22 @@ header {
116
121
  body.dark #status-window b {
117
122
  color: white;
118
123
  }
124
+ #progress-window {
125
+ flex-shrink: 0;
126
+ width: 100px;
127
+ background: #eee;
128
+ height: 15px;
129
+ /*
130
+ border-radius: 5px;
131
+ */
132
+ overflow: hidden;
133
+ }
134
+ #progress-bar {
135
+ width: 0%;
136
+ height: 100%;
137
+ background: royalblue;
138
+ transition: width 0.2s;
139
+ }
119
140
  #del-bin {
120
141
  color: royalblue;
121
142
  cursor: pointer;
@@ -297,6 +318,18 @@ document.addEventListener("DOMContentLoaded", async () => {
297
318
  this.write(JSON.stringify(packet.data.json2, null, 2).replace(/\n/g, "\r\n"))
298
319
  this.write("\r\n")
299
320
  }
321
+ if (packet.data.type === "emit2") {
322
+ // long text => still posting to the shell => show progress
323
+ console.log("emit2", packet.data)
324
+ document.querySelector("#status-window").innerHTML = `<strong>Pasting... (${Math.floor(100 * packet.data.i/packet.data.total)}%)</strong>`
325
+ let percent = Math.floor(100 * packet.data.i/packet.data.total)
326
+ document.querySelector("#progress-window").classList.remove("hidden")
327
+ document.querySelector("#progress-bar").style.width = "" + percent + "%";
328
+ } else {
329
+ document.querySelector("#status-window").innerHTML = "<b>Ready</b>"
330
+ document.querySelector("#progress-window").classList.add("hidden")
331
+ document.querySelector("#progress-bar").style.width = "0%"
332
+ }
300
333
  document.querySelector(".run .play").classList.add("hidden")
301
334
  document.querySelector(".run .starting").classList.add("hidden")
302
335
  document.querySelector(".run .stop").classList.remove("hidden")
@@ -689,12 +722,20 @@ document.addEventListener("DOMContentLoaded", async () => {
689
722
  if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
690
723
  navigator.clipboard.readText().then((text) => {
691
724
  console.log({ text })
692
- debugger
725
+
693
726
  this.socket.run({
694
727
  //key: "\x1b[200~" + text + "\x1b[201~",
695
728
  key: text,
696
- id: shell_id
729
+ id: shell_id,
730
+ paste: true
697
731
  })
732
+
733
+
734
+ // this.socket.run({
735
+ // //key: "\x1b[200~" + text + "\x1b[201~",
736
+ // key: text,
737
+ // id: shell_id
738
+ // })
698
739
  })
699
740
  return false
700
741
  }
@@ -708,7 +749,7 @@ document.addEventListener("DOMContentLoaded", async () => {
708
749
  //term.resize(cols, rows);
709
750
 
710
751
  term.onKey(({ key }) => {
711
- console.log({ key })
752
+ console.log({ key, shell_id })
712
753
  if (this.socket) {
713
754
  if (shell_id) {
714
755
  this.socket.run({
@@ -934,6 +975,9 @@ const reloadMemory = async () => {
934
975
  <button class='btn' id='open-fs' data-filepath="<%=filepath%>"><i class="fa-solid fa-eye"></i> View File</button>
935
976
  <% } %>
936
977
  <div id='status-window'></div>
978
+ <div id='progress-window' class='hidden'><div id='progress-bar'></div></div>
979
+ </div>
980
+
937
981
  </div>
938
982
  </header>
939
983
  <% } %>