pinokiod 3.12.3 → 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,27 +324,38 @@ class Shell {
323
324
  this.ptyProcess.resize(cols, rows)
324
325
  this.vt.resize(cols, rows)
325
326
  }
326
- emit2(message) {
327
- let i = 0;
328
- let total = message.length
329
- const interval = setInterval(() => {
330
- if (i >= message.length) {
331
- clearInterval(interval);
332
- return;
333
- }
334
- let chunk = message.slice(i, i+1024)
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)
335
343
  this.ptyProcess.write(chunk)
336
- i += 1024;
337
- this.ondata({ i, total, type: "emit2" })
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(Buffer.from(message))
356
+ if (message.length > 1024) {
357
+ this.emit2(message)
358
+ } else {
347
359
  this.ptyProcess.write(message)
348
360
  }
349
361
  }
@@ -908,6 +920,7 @@ class Shell {
908
920
  return params
909
921
  }
910
922
  async exec(params) {
923
+ this.watermark = 0
911
924
  params = await this.activate(params)
912
925
  this.cmd = this.build(params)
913
926
  let res = await new Promise((resolve, reject) => {
@@ -927,6 +940,9 @@ class Shell {
927
940
 
928
941
  config.env = this.env
929
942
 
943
+
944
+
945
+
930
946
  if (!this.ptyProcess) {
931
947
  // ptyProcess doesn't exist => create
932
948
  this.done = false
@@ -936,9 +952,9 @@ class Shell {
936
952
  this.queue.push(data)
937
953
  }
938
954
  });
939
- // this.ptyProcess.onExit((result) => {
940
- // console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
941
- // })
955
+ this.ptyProcess.onExit((result) => {
956
+ console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
957
+ })
942
958
  }
943
959
  } catch (e) {
944
960
  console.log("** Error", e)
@@ -964,6 +980,8 @@ class Shell {
964
980
  }
965
981
  kill(message, force, cb) {
966
982
 
983
+ console.log("KILL", { message })
984
+
967
985
  this.done = true
968
986
  this.ready = false
969
987
 
@@ -1107,6 +1125,7 @@ ${cleaned}
1107
1125
  callback()
1108
1126
  return
1109
1127
  }
1128
+
1110
1129
  this.vt.write(msg, () => {
1111
1130
  let buf = this.vts.serialize()
1112
1131
  let cleaned = this.stripAnsi(buf)
@@ -1118,7 +1137,9 @@ ${cleaned}
1118
1137
  shell_id: this.id
1119
1138
  }
1120
1139
  this.state = cleaned
1121
- if (this.cb) this.cb(response)
1140
+ if (this.cb) {
1141
+ this.cb(response)
1142
+ }
1122
1143
 
1123
1144
  // Decide whether to kill or continue
1124
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,9 +92,8 @@ const parse_env = async (filename) => {
92
92
  }
93
93
  }
94
94
  const run = (cmd, cwd, kernel) => {
95
- console.log("Util.run", { cmd, cwd })
96
- child_process.exec(cmd, { cwd })
97
- /*
95
+ // console.log("Util.run", { cmd, cwd })
96
+ // child_process.exec(cmd, { cwd })
98
97
  if (kernel) {
99
98
  kernel.exec({
100
99
  message: cmd,
@@ -107,8 +106,6 @@ const run = (cmd, cwd, kernel) => {
107
106
  } else {
108
107
  child_process.exec(command)
109
108
  }
110
- */
111
-
112
109
  }
113
110
  const openURL = (url) => {
114
111
  const platform = os.platform()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.12.3",
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",
@@ -29,7 +29,6 @@ const open_url = (href, target, features) => {
29
29
  }
30
30
  }
31
31
  document.addEventListener("click", async (e) => {
32
- debugger
33
32
  // [data-filepath] should open in file explorer
34
33
  let el = e.target.closest("[data-filepath]")
35
34
  if (!el) {
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>
@@ -298,7 +331,15 @@ document.addEventListener("DOMContentLoaded", async () => {
298
331
  }
299
332
  if (packet.data.type === "emit2") {
300
333
  // long text => still posting to the shell => show progress
301
- console.log("emit2", { packet.data })
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%"
302
343
  }
303
344
  document.querySelector(".play-btn").classList.add("hidden")
304
345
  document.querySelector(".starting-btn").classList.add("hidden")
@@ -667,11 +708,18 @@ document.addEventListener("DOMContentLoaded", async () => {
667
708
  if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
668
709
  navigator.clipboard.readText().then((text) => {
669
710
  console.log({ text })
711
+ //this.socket.run({
712
+ // //key: "\x1b[200~" + text + "\x1b[201~",
713
+ // key: text,
714
+ // id: shell_id
715
+ //})
670
716
  this.socket.run({
671
717
  //key: "\x1b[200~" + text + "\x1b[201~",
672
718
  key: text,
673
- id: shell_id
719
+ id: shell_id,
720
+ paste: true
674
721
  })
722
+
675
723
  })
676
724
  return false
677
725
  }
@@ -813,6 +861,8 @@ document.addEventListener("DOMContentLoaded", async () => {
813
861
  <div class='hidden btn stopped-btn'>
814
862
  <span class='stopped'><i class="fa-solid fa-hand"></i> Stopped</span>
815
863
  </div>
864
+ <div id='status-window'></div>
865
+ <div id='progress-window' class='hidden'><div id='progress-bar'></div></div>
816
866
  </h1>
817
867
  </header>
818
868
  <div class='terminal-container'>
@@ -112,7 +112,7 @@ header {
112
112
  padding: 0 10px;
113
113
  }
114
114
  #status-window strong {
115
- color: yellowgreen;
115
+ color: royalblue;
116
116
  }
117
117
  #status-window b {
118
118
  color: black;
@@ -134,7 +134,7 @@ body.dark #status-window b {
134
134
  #progress-bar {
135
135
  width: 0%;
136
136
  height: 100%;
137
- background: yellowgreen;
137
+ background: royalblue;
138
138
  transition: width 0.2s;
139
139
  }
140
140
  #del-bin {
@@ -722,12 +722,20 @@ document.addEventListener("DOMContentLoaded", async () => {
722
722
  if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
723
723
  navigator.clipboard.readText().then((text) => {
724
724
  console.log({ text })
725
- debugger
725
+
726
726
  this.socket.run({
727
727
  //key: "\x1b[200~" + text + "\x1b[201~",
728
728
  key: text,
729
- id: shell_id
729
+ id: shell_id,
730
+ paste: true
730
731
  })
732
+
733
+
734
+ // this.socket.run({
735
+ // //key: "\x1b[200~" + text + "\x1b[201~",
736
+ // key: text,
737
+ // id: shell_id
738
+ // })
731
739
  })
732
740
  return false
733
741
  }
@@ -741,7 +749,7 @@ document.addEventListener("DOMContentLoaded", async () => {
741
749
  //term.resize(cols, rows);
742
750
 
743
751
  term.onKey(({ key }) => {
744
- console.log({ key })
752
+ console.log({ key, shell_id })
745
753
  if (this.socket) {
746
754
  if (shell_id) {
747
755
  this.socket.run({