jsmdcui 0.3.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.
Files changed (258) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +22 -0
  3. package/README.md +285 -0
  4. package/package.json +17 -0
  5. package/project_structure.txt +35 -0
  6. package/runmd.mjs +240 -0
  7. package/runtime/colorschemes/atom-dark.micro +33 -0
  8. package/runtime/colorschemes/bubblegum.micro +31 -0
  9. package/runtime/colorschemes/cmc-16.micro +47 -0
  10. package/runtime/colorschemes/cmc-tc.micro +43 -0
  11. package/runtime/colorschemes/darcula.micro +34 -0
  12. package/runtime/colorschemes/default.micro +1 -0
  13. package/runtime/colorschemes/dracula-tc.micro +49 -0
  14. package/runtime/colorschemes/dukedark-tc.micro +38 -0
  15. package/runtime/colorschemes/dukelight-tc.micro +38 -0
  16. package/runtime/colorschemes/dukeubuntu-tc.micro +38 -0
  17. package/runtime/colorschemes/geany.micro +29 -0
  18. package/runtime/colorschemes/gotham.micro +29 -0
  19. package/runtime/colorschemes/gruvbox-tc.micro +29 -0
  20. package/runtime/colorschemes/gruvbox.micro +26 -0
  21. package/runtime/colorschemes/material-tc.micro +36 -0
  22. package/runtime/colorschemes/monokai-dark.micro +28 -0
  23. package/runtime/colorschemes/monokai.micro +34 -0
  24. package/runtime/colorschemes/one-dark.micro +39 -0
  25. package/runtime/colorschemes/railscast.micro +37 -0
  26. package/runtime/colorschemes/simple.micro +33 -0
  27. package/runtime/colorschemes/solarized-tc.micro +31 -0
  28. package/runtime/colorschemes/solarized.micro +30 -0
  29. package/runtime/colorschemes/sunny-day.micro +29 -0
  30. package/runtime/colorschemes/twilight.micro +40 -0
  31. package/runtime/colorschemes/zenburn.micro +30 -0
  32. package/runtime/help/actions.md +161 -0
  33. package/runtime/help/cdp.md +119 -0
  34. package/runtime/help/colors.md +421 -0
  35. package/runtime/help/commands.md +161 -0
  36. package/runtime/help/copypaste.md +149 -0
  37. package/runtime/help/defaultkeys.md +148 -0
  38. package/runtime/help/help.md +285 -0
  39. package/runtime/help/keybindings.md +355 -0
  40. package/runtime/help/linter.md +90 -0
  41. package/runtime/help/options.md +709 -0
  42. package/runtime/help/plugins.md +544 -0
  43. package/runtime/help/tutorial.md +112 -0
  44. package/runtime/jsplugins/cdp/cdp-server.js +1161 -0
  45. package/runtime/jsplugins/cdp/cdp.js +192 -0
  46. package/runtime/jsplugins/chapter/chapter.js +108 -0
  47. package/runtime/jsplugins/diff/diff.js +46 -0
  48. package/runtime/jsplugins/example/example.js +110 -0
  49. package/runtime/jsplugins/linter/linter.js +281 -0
  50. package/runtime/plugins/autoclose/autoclose.lua +75 -0
  51. package/runtime/plugins/ftoptions/ftoptions.lua +17 -0
  52. package/runtime/plugins/literate/README.md +5 -0
  53. package/runtime/plugins/literate/literate.lua +55 -0
  54. package/runtime/plugins/status/help/status.md +21 -0
  55. package/runtime/plugins/status/status.lua +62 -0
  56. package/runtime/syntax/LICENSE +22 -0
  57. package/runtime/syntax/PowerShell.yaml +128 -0
  58. package/runtime/syntax/README.md +63 -0
  59. package/runtime/syntax/ada.yaml +43 -0
  60. package/runtime/syntax/apacheconf.yaml +59 -0
  61. package/runtime/syntax/arduino.yaml +101 -0
  62. package/runtime/syntax/asciidoc.yaml +51 -0
  63. package/runtime/syntax/asm.yaml +123 -0
  64. package/runtime/syntax/ats.yaml +99 -0
  65. package/runtime/syntax/awk.yaml +44 -0
  66. package/runtime/syntax/b.yaml +87 -0
  67. package/runtime/syntax/bat.yaml +57 -0
  68. package/runtime/syntax/c.yaml +60 -0
  69. package/runtime/syntax/caddyfile.yaml +23 -0
  70. package/runtime/syntax/cake.yaml +7 -0
  71. package/runtime/syntax/clojure.yaml +38 -0
  72. package/runtime/syntax/cmake.yaml +42 -0
  73. package/runtime/syntax/coffeescript.yaml +56 -0
  74. package/runtime/syntax/colortest.yaml +19 -0
  75. package/runtime/syntax/conky.yaml +17 -0
  76. package/runtime/syntax/cpp.yaml +91 -0
  77. package/runtime/syntax/crontab.yaml +36 -0
  78. package/runtime/syntax/crystal.yaml +72 -0
  79. package/runtime/syntax/csharp.yaml +52 -0
  80. package/runtime/syntax/css.yaml +44 -0
  81. package/runtime/syntax/csx.yaml +8 -0
  82. package/runtime/syntax/cuda.yaml +68 -0
  83. package/runtime/syntax/cython.yaml +52 -0
  84. package/runtime/syntax/d.yaml +121 -0
  85. package/runtime/syntax/dart.yaml +46 -0
  86. package/runtime/syntax/default.yaml +10 -0
  87. package/runtime/syntax/dockerfile.yaml +36 -0
  88. package/runtime/syntax/dot.yaml +29 -0
  89. package/runtime/syntax/elixir.yaml +30 -0
  90. package/runtime/syntax/elm.yaml +38 -0
  91. package/runtime/syntax/erb.yaml +42 -0
  92. package/runtime/syntax/erlang.yaml +45 -0
  93. package/runtime/syntax/fish.yaml +48 -0
  94. package/runtime/syntax/forth.yaml +34 -0
  95. package/runtime/syntax/fortran.yaml +64 -0
  96. package/runtime/syntax/freebsd-kernel.yaml +14 -0
  97. package/runtime/syntax/fsharp.yaml +48 -0
  98. package/runtime/syntax/gdscript.yaml +61 -0
  99. package/runtime/syntax/gemini.yaml +19 -0
  100. package/runtime/syntax/gentoo-ebuild.yaml +48 -0
  101. package/runtime/syntax/gentoo-etc-portage.yaml +23 -0
  102. package/runtime/syntax/git-commit.yaml +35 -0
  103. package/runtime/syntax/git-config.yaml +14 -0
  104. package/runtime/syntax/git-rebase-todo.yaml +19 -0
  105. package/runtime/syntax/gleam.yaml +69 -0
  106. package/runtime/syntax/glsl.yaml +26 -0
  107. package/runtime/syntax/gnuplot.yaml +15 -0
  108. package/runtime/syntax/go.yaml +62 -0
  109. package/runtime/syntax/godoc.yaml +17 -0
  110. package/runtime/syntax/golo.yaml +73 -0
  111. package/runtime/syntax/gomod.yaml +31 -0
  112. package/runtime/syntax/graphql.yaml +47 -0
  113. package/runtime/syntax/groff.yaml +30 -0
  114. package/runtime/syntax/groovy.yaml +111 -0
  115. package/runtime/syntax/haml.yaml +16 -0
  116. package/runtime/syntax/hare.yaml +52 -0
  117. package/runtime/syntax/haskell.yaml +52 -0
  118. package/runtime/syntax/hc.yaml +52 -0
  119. package/runtime/syntax/html.yaml +70 -0
  120. package/runtime/syntax/html4.yaml +25 -0
  121. package/runtime/syntax/html5.yaml +25 -0
  122. package/runtime/syntax/ini.yaml +23 -0
  123. package/runtime/syntax/inputrc.yaml +14 -0
  124. package/runtime/syntax/java.yaml +37 -0
  125. package/runtime/syntax/javascript.yaml +124 -0
  126. package/runtime/syntax/jinja2.yaml +19 -0
  127. package/runtime/syntax/json.yaml +39 -0
  128. package/runtime/syntax/jsonnet.yaml +92 -0
  129. package/runtime/syntax/julia.yaml +57 -0
  130. package/runtime/syntax/justfile.yaml +40 -0
  131. package/runtime/syntax/keymap.yaml +27 -0
  132. package/runtime/syntax/kickstart.yaml +16 -0
  133. package/runtime/syntax/kotlin.yaml +66 -0
  134. package/runtime/syntax/kvlang.yaml +67 -0
  135. package/runtime/syntax/ledger.yaml +14 -0
  136. package/runtime/syntax/lfe.yaml +17 -0
  137. package/runtime/syntax/lilypond.yaml +26 -0
  138. package/runtime/syntax/lisp.yaml +17 -0
  139. package/runtime/syntax/log.yaml +92 -0
  140. package/runtime/syntax/lua.yaml +111 -0
  141. package/runtime/syntax/mail.yaml +25 -0
  142. package/runtime/syntax/makefile.yaml +38 -0
  143. package/runtime/syntax/man.yaml +12 -0
  144. package/runtime/syntax/markdown.yaml +49 -0
  145. package/runtime/syntax/mc.yaml +23 -0
  146. package/runtime/syntax/meson.yaml +51 -0
  147. package/runtime/syntax/micro.yaml +34 -0
  148. package/runtime/syntax/mpdconf.yaml +13 -0
  149. package/runtime/syntax/msbuild.yaml +6 -0
  150. package/runtime/syntax/nanorc.yaml +16 -0
  151. package/runtime/syntax/nftables.yaml +30 -0
  152. package/runtime/syntax/nginx.yaml +22 -0
  153. package/runtime/syntax/nim.yaml +27 -0
  154. package/runtime/syntax/nix.yaml +32 -0
  155. package/runtime/syntax/nu.yaml +114 -0
  156. package/runtime/syntax/objc.yaml +60 -0
  157. package/runtime/syntax/ocaml.yaml +43 -0
  158. package/runtime/syntax/octave.yaml +83 -0
  159. package/runtime/syntax/odin.yaml +64 -0
  160. package/runtime/syntax/pascal.yaml +45 -0
  161. package/runtime/syntax/patch.yaml +14 -0
  162. package/runtime/syntax/peg.yaml +16 -0
  163. package/runtime/syntax/perl.yaml +58 -0
  164. package/runtime/syntax/php.yaml +60 -0
  165. package/runtime/syntax/pkg-config.yaml +12 -0
  166. package/runtime/syntax/po.yaml +12 -0
  167. package/runtime/syntax/pony.yaml +37 -0
  168. package/runtime/syntax/pov.yaml +21 -0
  169. package/runtime/syntax/privoxy-action.yaml +14 -0
  170. package/runtime/syntax/privoxy-config.yaml +10 -0
  171. package/runtime/syntax/privoxy-filter.yaml +12 -0
  172. package/runtime/syntax/proto.yaml +40 -0
  173. package/runtime/syntax/prql.yaml +84 -0
  174. package/runtime/syntax/puppet.yaml +22 -0
  175. package/runtime/syntax/python2.yaml +60 -0
  176. package/runtime/syntax/python3.yaml +80 -0
  177. package/runtime/syntax/r.yaml +32 -0
  178. package/runtime/syntax/raku.yaml +42 -0
  179. package/runtime/syntax/reST.yaml +18 -0
  180. package/runtime/syntax/renpy.yaml +15 -0
  181. package/runtime/syntax/rpmspec.yaml +43 -0
  182. package/runtime/syntax/ruby.yaml +73 -0
  183. package/runtime/syntax/rust.yaml +78 -0
  184. package/runtime/syntax/sage.yaml +60 -0
  185. package/runtime/syntax/scad.yaml +53 -0
  186. package/runtime/syntax/scala.yaml +33 -0
  187. package/runtime/syntax/sed.yaml +13 -0
  188. package/runtime/syntax/sh.yaml +69 -0
  189. package/runtime/syntax/sls.yaml +15 -0
  190. package/runtime/syntax/smalltalk.yaml +55 -0
  191. package/runtime/syntax/solidity.yaml +41 -0
  192. package/runtime/syntax/sql.yaml +35 -0
  193. package/runtime/syntax/stata.yaml +67 -0
  194. package/runtime/syntax/svelte.yaml +27 -0
  195. package/runtime/syntax/swift.yaml +103 -0
  196. package/runtime/syntax/systemd.yaml +16 -0
  197. package/runtime/syntax/tcl.yaml +18 -0
  198. package/runtime/syntax/terraform.yaml +87 -0
  199. package/runtime/syntax/tex.yaml +32 -0
  200. package/runtime/syntax/toml.yaml +56 -0
  201. package/runtime/syntax/twig.yaml +55 -0
  202. package/runtime/syntax/typescript.yaml +49 -0
  203. package/runtime/syntax/v.yaml +80 -0
  204. package/runtime/syntax/vala.yaml +26 -0
  205. package/runtime/syntax/verilog.yaml +60 -0
  206. package/runtime/syntax/vhdl.yaml +37 -0
  207. package/runtime/syntax/vi.yaml +31 -0
  208. package/runtime/syntax/vue.yaml +64 -0
  209. package/runtime/syntax/xml.yaml +37 -0
  210. package/runtime/syntax/xresources.yaml +14 -0
  211. package/runtime/syntax/yaml.yaml +34 -0
  212. package/runtime/syntax/yum.yaml +12 -0
  213. package/runtime/syntax/zig.yaml +52 -0
  214. package/runtime/syntax/zscript.yaml +72 -0
  215. package/runtime/syntax/zsh.yaml +52 -0
  216. package/single-exe/README.md +80 -0
  217. package/single-exe/assetsHelper.js +90 -0
  218. package/single-exe/assetsLoader.mjs +85 -0
  219. package/single-exe/compiled.js +149 -0
  220. package/single-exe/entry.mjs +9 -0
  221. package/single-exe/packAssets.sh +7 -0
  222. package/src/buffer/backup.js +160 -0
  223. package/src/buffer/buffer.js +126 -0
  224. package/src/buffer/fixed3-codec.js +140 -0
  225. package/src/buffer/loc.js +38 -0
  226. package/src/buffer/message.js +29 -0
  227. package/src/config/clean.js +172 -0
  228. package/src/config/colorscheme.js +99 -0
  229. package/src/config/config.js +122 -0
  230. package/src/config/defaults.js +109 -0
  231. package/src/cui/rpc.mjs +259 -0
  232. package/src/cui/server.mjs +116 -0
  233. package/src/display/ansi-style.js +60 -0
  234. package/src/highlight/highlighter.js +243 -0
  235. package/src/highlight/parser.js +225 -0
  236. package/src/index.js +8009 -0
  237. package/src/lua/engine.js +71 -0
  238. package/src/platform/archive.js +50 -0
  239. package/src/platform/clipboard.js +278 -0
  240. package/src/platform/commands.js +137 -0
  241. package/src/plugins/js-bridge.js +983 -0
  242. package/src/plugins/manager.js +674 -0
  243. package/src/runtime/assets.js +90 -0
  244. package/src/runtime/compiled.js +25 -0
  245. package/src/runtime/encodings.js +10 -0
  246. package/src/runtime/registry.js +134 -0
  247. package/src/screen/cell-buffer.js +81 -0
  248. package/src/screen/events.js +263 -0
  249. package/src/screen/screen.js +142 -0
  250. package/src/screen/vt100.js +571 -0
  251. package/src/shell/shell.js +70 -0
  252. package/testapp.md +55 -0
  253. package/tests/backup.test.js +133 -0
  254. package/tests/cmphex3b64.js +95 -0
  255. package/tests/pty-demo.js +492 -0
  256. package/tests/wv-client.js +96 -0
  257. package/tui +5 -0
  258. package/wui +5 -0
@@ -0,0 +1,34 @@
1
+ filetype: yaml
2
+
3
+ detect:
4
+ filename: "\\.ya?ml$"
5
+ header: "%YAML"
6
+
7
+ rules:
8
+ - type: "(^| )!!(binary|bool|float|int|map|null|omap|seq|set|str) "
9
+ - constant: "\\b(YES|yes|Y|y|ON|on|TRUE|True|true|NO|no|N|n|OFF|off|FALSE|False|false)\\b"
10
+ - statement: "(:[[:space:]]|\\[|\\]|:[[:space:]]+[|>]|^[[:space:]]*- )"
11
+ - identifier: "[[:space:]][\\*&][A-Za-z0-9]+"
12
+ - type: "[-.\\w]+:"
13
+ - statement: ":"
14
+ - special: "(^---|^\\.\\.\\.|^%YAML|^%TAG)"
15
+
16
+ - constant.string:
17
+ start: "(^| )\""
18
+ end: "\""
19
+ skip: "\\\\."
20
+ rules:
21
+ - constant.specialChar: "\\\\."
22
+
23
+ - constant.string:
24
+ start: "(^| )'"
25
+ end: "'"
26
+ skip: "(\\\\.)|('')"
27
+ rules:
28
+ - constant.specialChar: "\\\\."
29
+
30
+ - comment:
31
+ start: "#"
32
+ end: "$"
33
+ rules:
34
+ - todo: "(TODO|XXX|FIXME):?"
@@ -0,0 +1,12 @@
1
+ filetype: yum
2
+
3
+ detect:
4
+ filename: "\\.repo$|yum.*\\.conf$"
5
+
6
+ rules:
7
+ - identifier: "^[[:space:]]*[^=]*="
8
+ - constant.specialChar: "^[[:space:]]*\\[.*\\]$"
9
+ - statement: "\\$(releasever|arch|basearch|uuid|YUM[0-9])"
10
+ - comment: "(^|[[:space:]])#([^{].*)?$"
11
+ - indent-char.whitespace: "[[:space:]]+$"
12
+ - indent-char: " + +| + +"
@@ -0,0 +1,52 @@
1
+ filetype: zig
2
+
3
+ detect:
4
+ filename: "\\.z(ig|on)$"
5
+
6
+ rules:
7
+ # Reserved words
8
+ - statement: "\\b(addrspace|align|allowzero|and|asm|async|await|break|callconv|catch|comptime|const|continue|defer|else|errdefer|error|export|extern|fn|for|if|inline|noalias|noinline|nosuspend|or|orelse|packed|pub|resume|return|linksection|suspend|switch|test|threadlocal|try|unreachable|usingnamespace|var|volatile|while)\\b"
9
+ # builtin functions
10
+ - special: "@[a-zA-Z_]+"
11
+ # Primitive Types
12
+ - type: "\\b(anyframe|anytype|anyerror|anyopaque|bool|comptime_int|comptime_float|enum|f(16|32|64|80|128)|i(8|16|32|64|128)|isize|noreturn|opaque|struct|type|union|u(8|16|32|64|128)|usize|void)\\b"
13
+ - type: "\\b(c_u?(short|int|long(long)?)|c_longdouble|c_void)\\b"
14
+
15
+ # Operators
16
+ - symbol.operator: "[-!|=;%.+^*:&?<>~]"
17
+
18
+ # Parenthesis
19
+ - symbol.brackets: "[(){}]|\\[|\\]"
20
+
21
+ # Constants
22
+ - constant: "\\b(null|undefined)\\b"
23
+ - constant.number: "\\b(0b[01_]+|0o[0-7_]+|[0-9_]+|0x[a-fA-F0-9_]+)\\b"
24
+ - constant.bool: "\\b(true|false)\\b"
25
+
26
+ - constant.string:
27
+ start: "\""
28
+ end: "\""
29
+ skip: "\\\\."
30
+ rules:
31
+ - constant.specialChar: "\\\\([nrt\\\\'\"]|x[a-fA-F0-9]{2}|u{[a-fA-F0-9]+})"
32
+
33
+ - constant.string:
34
+ start: "'"
35
+ end: "'"
36
+ skip: "\\\\."
37
+ rules:
38
+ - error: "..+"
39
+ - constant.specialChar: "\\\\([nrt\\\\'\"]|x[a-fA-F0-9]{2}|u{[a-fA-F0-9]+})"
40
+
41
+ - constant.string:
42
+ start: "\\\\\\\\"
43
+ end: "$"
44
+ skip: "\\\\."
45
+ rules:
46
+ - constant.specialChar: "\\\\([nrt\\\\'\"]|x[a-fA-F0-9]{2}|u{[a-fA-F0-9]+})"
47
+
48
+ - comment:
49
+ start: "//"
50
+ end: "$"
51
+ rules:
52
+ - todo: "(TODO|XXX|FIXME):?"
@@ -0,0 +1,72 @@
1
+ filetype: zscript
2
+ # Loosely based on the csharp.yaml definition
3
+ # (?i) on everything because ZScript isn't case sensitive
4
+
5
+ detect:
6
+ filename: "(?i)\\.z(c|sc)$"
7
+
8
+ rules:
9
+
10
+ # ZScript only has one preprocessor directive and a required engine version declaration
11
+ - preproc: "(?i)#include"
12
+ - preproc: "(?i)version"
13
+
14
+ # State labels ("goto" word overridden by state logic rule below)
15
+ - symbol.tag: "(?i)[a-z0-9.]+:"
16
+ - symbol.tag: "(?i)goto [a-z0-9]+[\\+0-9]*"
17
+
18
+ # Classes
19
+ - identifier.class: "(?i)class +[a-z0-9_]+ *((:) +[a-z0-9.]+)?"
20
+
21
+ # Functions (open paren overridden by symbol.brackets rule because perl regex apparently doesn't support postive lookahead)
22
+ - identifier: "(?i)[\\.]*[a-z0-9_]+[ ]*[(]+"
23
+
24
+ # Variable types
25
+ - type: "(?i)\\b(actor|object|vector2|vector3|name|string|color|sound|void|double|bool|int|float|float64|uint8|uint16|uint|int8|int16|TextureID|SpriteID|Array|voidptr|short|action|state|statelabel)\\b"
26
+
27
+ # Keywords
28
+ - statement: "(?i)\\b(class|default|private|static|native|return|if|else|for|while|do|deprecated|null|readonly|true|false|struct|extend|clearscope|vararg|ui|play|virtual|virtualscope|meta|Property|in|out|states|override|super|is|let|const|replaces|protected|self|abstract|enum|switch|case)\\b"
29
+
30
+ # State logic keywords
31
+ - special: "(?i)\\b(goto|loop|stop|break|continue|fail)\\b"
32
+
33
+ # Symbols
34
+ - symbol.operator: "[\\-+/*=<>?:!~%&|]"
35
+ - symbol.brackets: "[(){}]|\\[|\\]"
36
+
37
+ # Constants
38
+ - constant.bool: "(?i)(\\b(true|false)\\b|NULL)"
39
+ - constant.number: "(?i)\\b([0-9][.]*[0-9]*)+?\\b"
40
+ - constant.number: "(?i)\\b(0x[A-Fa-f0-9_]+)?\\b"
41
+ - constant.number: "(?i)\\b(0b[0-1_]+)[FL]?\\b"
42
+ #- constant.number: "(?i)\\b(([0-9][.]*[0-9]*)+|0x[A-Fa-f0-9_]+|0b[0-1_]+)[FL]?\\b"
43
+
44
+ # Strings
45
+ - constant.string:
46
+ start: "\""
47
+ end: "\""
48
+ skip: "\\\\."
49
+ rules:
50
+ - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)"
51
+ - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}"
52
+
53
+ - constant.string:
54
+ start: "'"
55
+ end: "'"
56
+ skip: "\\\\."
57
+ rules:
58
+ - constant.specialChar: "\\\\([btnfr]|'|\\\"|\\\\)"
59
+ - constant.specialChar: "\\\\u[A-Fa-f0-9]{4}"
60
+
61
+ # Comments
62
+ - comment:
63
+ start: "//"
64
+ end: "$"
65
+ rules:
66
+ - todo: "(TODO|XXX|FIXME):?"
67
+
68
+ - comment:
69
+ start: "/\\*"
70
+ end: "\\*/"
71
+ rules:
72
+ - todo: "(TODO|XXX|FIXME):?"
@@ -0,0 +1,52 @@
1
+ filetype: zsh
2
+
3
+ detect:
4
+ filename: "(\\.zsh$|\\.?(zshenv|zprofile|zshrc|zlogin|zlogout)$)"
5
+ header: "^#!.*/(env +)?zsh( |$)"
6
+
7
+ rules:
8
+ ## Numbers
9
+ - constant.number: "\\b[0-9]+\\b"
10
+
11
+ ## Conditionals and control flow
12
+ - statement: "\\b(always|break|bye|case|continue|disown|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\\b"
13
+
14
+ - statement: "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)"
15
+ ## Conditional flags
16
+ - special: "-[Ldefgruwx]\\b"
17
+ - special: "-(eq|ne|gt|lt|ge|le|s|n|z)\\b"
18
+
19
+ ## Bash-inherited
20
+ - statement: "\\b((un)?alias|bindkey|builtin|cd|declare|eval|exec|export|jobs|let|popd|pushd|set|source|typeset|umask|unset)\\b"
21
+ ## ZSH-specific
22
+ - type: "\\b(add-zsh-hook|autoload|chdir|compinit|dirs|(dis|en)able|echotc|emulate|print|prompt(init)?|(un)?setopt|zle|zmodload|zstyle|whence)\\b"
23
+
24
+ ## Common linux commands
25
+ - statement: "\\b((g|ig)?awk|find|\\w{0,4}grep|kill|killall|\\w{0,4}less|make|pkill|sed|tar)\\b"
26
+
27
+ ## Coreutils commands
28
+ - statement: "\\b(base64|basename|cat|chcon|chgrp|chmod|chown|chroot|cksum|comm|cp|csplit|cut|date|dd|df|dir|dircolors|dirname|du|echo|env|expand|expr|factor|false|fmt|fold|head|hostid|id|install|join|link|ln|logname|ls|md5sum|mkdir|mkfifo|mknod|mktemp|mv|nice|nl|nohup|nproc|numfmt|od|paste|pathchk|pinky|pr|printenv|printf|ptx|pwd|readlink|realpath|rm|rmdir|runcon|seq|(sha1|sha224|sha256|sha384|sha512)sum|shred|shuf|sleep|sort|split|stat|stdbuf|stty|sum|sync|tac|tail|tee|test|timeout|touch|tr|true|truncate|tsort|tty|uname|unexpand|uniq|unlink|users|vdir|wc|who|whoami|yes)\\b"
29
+
30
+ ## Function definition
31
+ - identifier: "^\\s+(function\\s+)[0-9A-Z_]+\\s+\\(\\)" # (i)
32
+
33
+ ## Variables
34
+ - identifier: "\\$\\{?[0-9A-Z_!@#$*?-]+\\}?" #(i)
35
+
36
+ - constant.string:
37
+ start: "\""
38
+ end: "\""
39
+ skip: "\\\\."
40
+ rules:
41
+ - constant.specialChar: "\\\\."
42
+
43
+ - constant.string:
44
+ start: "'"
45
+ end: "'"
46
+ rules: []
47
+
48
+ - comment:
49
+ start: "(^|\\s)#"
50
+ end: "$"
51
+ rules: []
52
+
@@ -0,0 +1,80 @@
1
+ # This is completely optional
2
+ - I still recommend using the methods in the root README.md
3
+ - Bun's Android build is currently not supported
4
+
5
+ # Usage
6
+ - First run `bun ./packAssets.sh` to bundle the assets into `assets.tar`
7
+ - Then run the build script like this
8
+
9
+ ```shell
10
+ bun build --compile --bytecode --minify ./entry.mjs --outfile=binname
11
+ ```
12
+
13
+ - You'll get a binname executable
14
+
15
+ # Single Executable Intro
16
+
17
+ This folder contains the Bun single-exe bootstrap used by the project.
18
+
19
+ ## Entry Flow
20
+
21
+ - `entry.mjs` imports `assetsLoader.mjs` first
22
+ - `assetsLoader.mjs` loads `assets.tar` with `Bun.Archive` and mounts it as `globalThis.internalAssets`
23
+ - `assetsLoaderPromise` is exposed on `globalThis`
24
+ - The main program waits for `assetsLoaderPromise` if it exists
25
+
26
+ That keeps the main program bootable even if asset loading reports errors.
27
+
28
+ ## Assets Loading
29
+
30
+ - Bundled assets are loaded sequentially with `await file.bytes()`
31
+ - Load failures are collected and printed to `stderr`
32
+ - Asset loading never rejects the bootstrap promise
33
+ - When loading succeeds, the archive is available through `globalThis.internalAssets`
34
+
35
+ ## CLI Flags
36
+
37
+ - `--assets-list`
38
+ - Lists all entries inside bundled `assets.tar`
39
+ - Exits early before the main program starts
40
+
41
+ - `--assets-extract`
42
+ - Extracts bundled assets to the same directory as the executable
43
+ - Exits early before the main program starts
44
+
45
+ - `--assets-external`
46
+ - Skips loading bundled assets into `globalThis.internalAssets`
47
+ - Forces the main program and runtime helpers to use the external file tree
48
+ - Keeps the bootstrap alive while leaving `internalAssets` falsy
49
+
50
+ ## Adapting this folder
51
+
52
+ This single-exe folder is intended for reuse by other projects. Usually you
53
+ only need to edit these project-specific files first:
54
+
55
+ - `entry.mjs`
56
+ - `packAssets.sh`
57
+
58
+ Then the main program can import `buildEarlyExit` from `compiled.js` and call
59
+ it before normal CLI parsing. `--build-exe` and `--build-for <target>` will run
60
+ `packAssets.sh` first, so `assets.tar` is generated as part of the build flow.
61
+
62
+ ```js
63
+ const compiledHelper = await import("./single-exe/compiled.js").catch(() => null);
64
+ await compiledHelper?.buildEarlyExit?.(process.argv, "my-bin");
65
+ ```
66
+
67
+ - `--build-exe` builds with no Bun target.
68
+ - `--build-for <target>` passes `<target>` to `bun build --target=<target>`.
69
+ - The second argument is the output filename. If omitted, it defaults to `single.exe`.
70
+
71
+ The main program should also switch its repo/resource root when running as a
72
+ compiled binary. Use `IS_COMPILED` and `REPO_ROOT` from
73
+ `compiled.js`; when compiled, treat the executable directory as the repo root
74
+ used for external fallback files such as `static/`, `README.md`, or other files
75
+ packed by `packAssets.sh`.
76
+
77
+ ```js
78
+ const compiledHelper = await import("./single-exe/compiled.js").catch(() => null);
79
+ const repoRoot = compiledHelper?.REPO_ROOT
80
+ ```
@@ -0,0 +1,90 @@
1
+ const textDecoder = new TextDecoder();
2
+ const textEncoder = new TextEncoder();
3
+
4
+ export function hasInternalAssets() {
5
+ return Boolean(getAssetStore());
6
+ }
7
+
8
+ export function assetPath(...parts) {
9
+ return parts
10
+ .flatMap((part) => String(part).split(/[\\/]+/))
11
+ .filter(Boolean)
12
+ .join("/");
13
+ }
14
+
15
+ export function listInternalAssetPaths(prefix = "") {
16
+ const store = getAssetStore();
17
+ if (!store) return [];
18
+
19
+ const normalizedPrefix = assetPath(prefix);
20
+ const entries = iterateAssetKeys(store);
21
+ if (!normalizedPrefix) {
22
+ return entries.sort();
23
+ }
24
+
25
+ const base = `${normalizedPrefix}/`;
26
+ return entries.filter((path) => path === normalizedPrefix || path.startsWith(base)).sort();
27
+ }
28
+
29
+ export function listInternalAssetDirs(prefix = "") {
30
+ const normalizedPrefix = assetPath(prefix);
31
+ const base = normalizedPrefix ? `${normalizedPrefix}/` : "";
32
+ const dirs = new Set();
33
+
34
+ for (const path of listInternalAssetPaths(prefix)) {
35
+ const rest = normalizedPrefix ? path.slice(base.length) : path;
36
+ const [dir] = rest.split("/");
37
+ if (dir) dirs.add(dir);
38
+ }
39
+
40
+ return [...dirs].sort();
41
+ }
42
+
43
+ export function getInternalAsset(path) {
44
+ const store = getAssetStore();
45
+ if (!store) return null;
46
+ const key = assetPath(path);
47
+ if (store instanceof Map) return store.get(key) ?? null;
48
+ return store[key] ?? store[path] ?? null;
49
+ }
50
+
51
+ export function readInternalAssetBytes(path) {
52
+ const value = getInternalAsset(path);
53
+ if (value == null) return null;
54
+ if (value instanceof Uint8Array) return value;
55
+ if (ArrayBuffer.isView(value)) {
56
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
57
+ }
58
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
59
+ if (typeof value === "string") return textEncoder.encode(value);
60
+ return textEncoder.encode(String(value));
61
+ }
62
+
63
+ export function readInternalAssetText(path) {
64
+ const bytes = readInternalAssetBytes(path);
65
+ if (!bytes) return null;
66
+ return textDecoder.decode(bytes);
67
+ }
68
+
69
+ export function internalAssetSource(path) {
70
+ return {
71
+ name: path.split("/").pop() ?? path,
72
+ path,
73
+ async text() {
74
+ return readInternalAssetText(path) ?? "";
75
+ },
76
+ };
77
+ }
78
+
79
+ function getAssetStore() {
80
+ const store = globalThis.internalAssets;
81
+ if (!store) return null;
82
+ if (store instanceof Map) return store;
83
+ if (typeof store === "object") return store;
84
+ return null;
85
+ }
86
+
87
+ function iterateAssetKeys(store) {
88
+ if (store instanceof Map) return [...store.keys()].map(String);
89
+ return Object.keys(store);
90
+ }
@@ -0,0 +1,85 @@
1
+ import assets from "./assets.tar" with { type: "file" };
2
+ import { getExeDirname, isCompiledBinary } from "./compiled.js";
3
+
4
+ const forceExternalAssets = process.argv.includes("--assets-external");
5
+ const debugAssetsLoader = Boolean(process.env.BUNMICRO_DEBUG);
6
+ if (forceExternalAssets) {
7
+ const flagIndex = process.argv.indexOf("--assets-external");
8
+ if (flagIndex >= 0) process.argv.splice(flagIndex, 1);
9
+ }
10
+
11
+ globalThis.internalAssets = forceExternalAssets ? null : Object.create(null);
12
+ globalThis.assetsLoaderPromise = main(process.argv).catch((error) => {
13
+ console.error("# assets loader failed");
14
+ console.error(error);
15
+ return globalThis.internalAssets;
16
+ });
17
+
18
+ async function main(argv) {
19
+
20
+ if (forceExternalAssets &&
21
+ !argv.includes("--assets-list") &&
22
+ !argv.includes("--assets-extract")) {
23
+ return null;
24
+ }
25
+
26
+ const startedAt = debugAssetsLoader ? Bun.nanoseconds() : 0;
27
+
28
+ const tarball = await Bun.file(assets).bytes();
29
+ const archive = new Bun.Archive(tarball);
30
+
31
+ await cliEarlyExit(archive, argv);
32
+
33
+ const files = await archive.files();
34
+ const entries = [...files.entries()];
35
+ const assetsByPath = Object.create(null);
36
+ const errors = [];
37
+
38
+ for (const [path, file] of entries) {
39
+ try {
40
+ assetsByPath[path] = await file.bytes();
41
+ } catch (reason) {
42
+ errors.push({ path, reason });
43
+ }
44
+ }
45
+
46
+ if (errors.length > 0) {
47
+ console.error(`# Failed to load ${errors.length} bundled asset(s):`);
48
+ for (const { path, reason } of errors) {
49
+ console.error(`- ${path}`);
50
+ if (reason) {
51
+ console.error(reason);
52
+ }
53
+ }
54
+ }
55
+ if (debugAssetsLoader) {
56
+ const elapsedMs = (Bun.nanoseconds() - startedAt) / 1e6;
57
+ console.error(`Loaded assets: ${elapsedMs.toFixed(3)} ms`);
58
+ }
59
+
60
+ globalThis.internalAssets = assetsByPath;
61
+ return assetsByPath;
62
+ }
63
+
64
+ async function cliEarlyExit(archive, argv) {
65
+ if (argv.includes("--assets-list")) {
66
+ const files = await archive.files();
67
+ for (const path of [...files.keys()].sort()) {
68
+ console.log(path);
69
+ }
70
+ process.exit(0);
71
+ }
72
+
73
+ if (argv.includes("--assets-extract")) {
74
+ if (isCompiledBinary())
75
+ {
76
+ const targetDir = getExeDirname();
77
+ const extracted = await archive.extract(targetDir);
78
+ console.log(`Extracted ${extracted} asset(s) to ${targetDir}`);
79
+ } // if isCompiled
80
+ else
81
+ console.log("Assets extraction should only be used in a Bun compiled single-file executable");
82
+
83
+ process.exit(0);
84
+ }
85
+ }
@@ -0,0 +1,149 @@
1
+ import { basename, dirname, resolve } from "node:path";
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import child_process from "node:child_process";
5
+
6
+
7
+ export const IS_COMPILED = isCompiledBinary();
8
+ export const REPO_ROOT = IS_COMPILED
9
+ ? getExeDirname()
10
+ : resolve(import.meta.dirname, "..");
11
+ const SINGLE_EXE_DIR = resolve(REPO_ROOT, "single-exe");
12
+ const SINGLE_EXE_ENTRY = resolve(SINGLE_EXE_DIR, "entry.mjs");
13
+
14
+
15
+ export function isCompiledBinary() {
16
+ const argv = process.argv
17
+ return Boolean(argv?.[1]?.startsWith?.("/$bunfs/"));
18
+ }
19
+
20
+ export function getExeDirname() {
21
+ const argv = process.argv
22
+ const execPath = process.execPath
23
+
24
+ const bn = basename(execPath);
25
+ if (bn.startsWith("ld") ||
26
+ bn.startsWith("libld") ||
27
+ bn.startsWith("linker") ) {
28
+ const realArgv = readFileSync("/proc/self/cmdline", "utf8").match(/[^\0]+/g);
29
+ return dirname(realArgv?.[1] ?? execPath);
30
+ }
31
+ return dirname(execPath) || process.cwd();
32
+ }
33
+
34
+ export function getDirnameFromUrl(importMetaUrl) {
35
+ return dirname(fileURLToPath(importMetaUrl));
36
+ }
37
+
38
+ export async function buildExecutable(target = "",build_outfile="single.exe") {
39
+
40
+ const outfile = resolve(process.cwd(), build_outfile);
41
+ const normalizedTarget = String(target || "").trim();
42
+ if(!globalThis.Bun || IS_COMPILED)
43
+ {
44
+ console.log("Build exe can only be run by Bun in the source tree");
45
+ return 1;
46
+ }
47
+
48
+ let bunBin=Bun.which('bun') || process.argv0;
49
+
50
+ const steps = [
51
+ {
52
+ label: "Pack assets",
53
+ cwd: SINGLE_EXE_DIR,
54
+ cmd: bunBin,
55
+ args: ["./packAssets.sh"],
56
+ },
57
+ {
58
+ label: "Compile executable",
59
+ cwd: SINGLE_EXE_DIR,
60
+ cmd: bunBin,
61
+ args: [
62
+ "build",
63
+ "--format=esm",
64
+ "--compile",
65
+ "--minify",
66
+ "--bytecode",
67
+ "./entry.mjs",
68
+ `--outfile=${outfile}`,
69
+ `--metafile-md=${outfile}.meta.md`,
70
+ ...(normalizedTarget ? [`--target=${normalizedTarget}`] : []),
71
+ ],
72
+ },
73
+ ];
74
+
75
+ for (const step of steps) {
76
+
77
+ console.log('');
78
+ console.log(Bun?.markdown?.ansi?.('## '+step.label)||step.label);
79
+
80
+ console.log("Running: ",step.cmd,step.args)
81
+
82
+ const result = child_process.spawnSync(step.cmd, step.args, {
83
+ cwd: step.cwd,
84
+ stdio: "inherit",
85
+ env: process.env,
86
+ });
87
+
88
+ console.log("");
89
+ console.log(Bun?.markdown?.ansi?.(
90
+ '- Status: '+result.status+' for '+step.label
91
+ )||result.status);
92
+
93
+
94
+
95
+ if (result.error || result.status !== 0) {
96
+
97
+ if (result.error) {
98
+ console.error(result.error);
99
+ }
100
+
101
+ if (step.label == "Pack assets") {
102
+ console.log("Pack assets failed; continuing with the existing assets.tar if available");
103
+ }
104
+
105
+ }
106
+
107
+
108
+ } // for steps of build
109
+
110
+ if(await Bun.file(outfile).exists())
111
+ {
112
+ console.log(`Built executable: ${outfile}`);
113
+ return 0;
114
+ }
115
+ else
116
+ {
117
+ console.log(`Error while building executable: ${outfile}`);
118
+ return 1;
119
+ }
120
+ }
121
+
122
+ export const buildExe = buildExecutable;
123
+
124
+ export async function buildEarlyExit(argv,build_outfile) {
125
+ argv = argv || process.argv
126
+
127
+ const buildExeIndex = argv.indexOf("--build-exe");
128
+ const buildForIndex = argv.indexOf("--build-for");
129
+
130
+ if (buildExeIndex === -1 && buildForIndex === -1) {
131
+ return false;
132
+ }
133
+
134
+ if (IS_COMPILED) {
135
+ console.error("--build-exe & --build-for are only available in the source tree");
136
+ process.exit(1);
137
+ }
138
+
139
+ if (buildForIndex !== -1) {
140
+ const target = argv[buildForIndex + 1];
141
+ if (!target || target.startsWith("-")) {
142
+ console.error("Missing target value for --build-for");
143
+ process.exit(2);
144
+ }
145
+ process.exit(await buildExe(target,build_outfile));
146
+ }
147
+
148
+ process.exit(await buildExe(null,build_outfile));
149
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bun
2
+
3
+ // 1. Injects assets to global.internalAssets
4
+ // as { "./path/in/tar":file.bytes() }
5
+ // 2. Sets global.assetsLoaderPromise
6
+ import "./assetsLoader.mjs"
7
+
8
+ import "../src/index.js"
9
+
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ sd=$(dirname "$0")
4
+
5
+ cd "$sd"/..
6
+
7
+ tar -cvf single-exe/assets.tar runtime README.md CHANGELOG.md src/cui/server.mjs src/cui/rpc.mjs testapp.md