bunmicro 0.8.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/LICENSE +22 -0
- package/PORTING.md +34 -0
- package/README.md +153 -0
- package/bmi +5 -0
- package/bun.lock +17 -0
- package/bunmicro +5 -0
- package/hlw.md +5 -0
- package/package.json +18 -0
- package/runtime/colorschemes/atom-dark.micro +33 -0
- package/runtime/colorschemes/bubblegum.micro +31 -0
- package/runtime/colorschemes/cmc-16.micro +47 -0
- package/runtime/colorschemes/cmc-tc.micro +43 -0
- package/runtime/colorschemes/darcula.micro +34 -0
- package/runtime/colorschemes/default.micro +1 -0
- package/runtime/colorschemes/dracula-tc.micro +49 -0
- package/runtime/colorschemes/dukedark-tc.micro +38 -0
- package/runtime/colorschemes/dukelight-tc.micro +38 -0
- package/runtime/colorschemes/dukeubuntu-tc.micro +38 -0
- package/runtime/colorschemes/geany.micro +29 -0
- package/runtime/colorschemes/gotham.micro +29 -0
- package/runtime/colorschemes/gruvbox-tc.micro +29 -0
- package/runtime/colorschemes/gruvbox.micro +26 -0
- package/runtime/colorschemes/material-tc.micro +36 -0
- package/runtime/colorschemes/monokai-dark.micro +28 -0
- package/runtime/colorschemes/monokai.micro +34 -0
- package/runtime/colorschemes/one-dark.micro +39 -0
- package/runtime/colorschemes/railscast.micro +37 -0
- package/runtime/colorschemes/simple.micro +33 -0
- package/runtime/colorschemes/solarized-tc.micro +31 -0
- package/runtime/colorschemes/solarized.micro +30 -0
- package/runtime/colorschemes/sunny-day.micro +29 -0
- package/runtime/colorschemes/twilight.micro +40 -0
- package/runtime/colorschemes/zenburn.micro +30 -0
- package/runtime/help/actions.md +161 -0
- package/runtime/help/colors.md +421 -0
- package/runtime/help/commands.md +161 -0
- package/runtime/help/copypaste.md +149 -0
- package/runtime/help/defaultkeys.md +141 -0
- package/runtime/help/help.md +63 -0
- package/runtime/help/keybindings.md +760 -0
- package/runtime/help/linter.md +90 -0
- package/runtime/help/options.md +701 -0
- package/runtime/help/plugins.md +544 -0
- package/runtime/help/tutorial.md +112 -0
- package/runtime/jsplugins/chapter/chapter.js +108 -0
- package/runtime/jsplugins/diff/diff.js +46 -0
- package/runtime/jsplugins/example/example.js +108 -0
- package/runtime/jsplugins/linter/linter.js +281 -0
- package/runtime/plugins/autoclose/autoclose.lua +75 -0
- package/runtime/plugins/ftoptions/ftoptions.lua +17 -0
- package/runtime/plugins/literate/README.md +5 -0
- package/runtime/plugins/literate/literate.lua +55 -0
- package/runtime/plugins/status/help/status.md +21 -0
- package/runtime/plugins/status/status.lua +62 -0
- package/runtime/syntax/LICENSE +22 -0
- package/runtime/syntax/PowerShell.yaml +128 -0
- package/runtime/syntax/README.md +63 -0
- package/runtime/syntax/ada.yaml +43 -0
- package/runtime/syntax/apacheconf.yaml +59 -0
- package/runtime/syntax/arduino.yaml +101 -0
- package/runtime/syntax/asciidoc.yaml +51 -0
- package/runtime/syntax/asm.yaml +123 -0
- package/runtime/syntax/ats.yaml +99 -0
- package/runtime/syntax/awk.yaml +44 -0
- package/runtime/syntax/b.yaml +87 -0
- package/runtime/syntax/bat.yaml +57 -0
- package/runtime/syntax/c.yaml +60 -0
- package/runtime/syntax/caddyfile.yaml +23 -0
- package/runtime/syntax/cake.yaml +7 -0
- package/runtime/syntax/clojure.yaml +38 -0
- package/runtime/syntax/cmake.yaml +42 -0
- package/runtime/syntax/coffeescript.yaml +56 -0
- package/runtime/syntax/colortest.yaml +19 -0
- package/runtime/syntax/conky.yaml +17 -0
- package/runtime/syntax/cpp.yaml +91 -0
- package/runtime/syntax/crontab.yaml +36 -0
- package/runtime/syntax/crystal.yaml +72 -0
- package/runtime/syntax/csharp.yaml +52 -0
- package/runtime/syntax/css.yaml +44 -0
- package/runtime/syntax/csx.yaml +8 -0
- package/runtime/syntax/cuda.yaml +68 -0
- package/runtime/syntax/cython.yaml +52 -0
- package/runtime/syntax/d.yaml +121 -0
- package/runtime/syntax/dart.yaml +46 -0
- package/runtime/syntax/default.yaml +10 -0
- package/runtime/syntax/dockerfile.yaml +36 -0
- package/runtime/syntax/dot.yaml +29 -0
- package/runtime/syntax/elixir.yaml +30 -0
- package/runtime/syntax/elm.yaml +38 -0
- package/runtime/syntax/erb.yaml +42 -0
- package/runtime/syntax/erlang.yaml +45 -0
- package/runtime/syntax/fish.yaml +48 -0
- package/runtime/syntax/forth.yaml +34 -0
- package/runtime/syntax/fortran.yaml +64 -0
- package/runtime/syntax/freebsd-kernel.yaml +14 -0
- package/runtime/syntax/fsharp.yaml +48 -0
- package/runtime/syntax/gdscript.yaml +61 -0
- package/runtime/syntax/gemini.yaml +19 -0
- package/runtime/syntax/gentoo-ebuild.yaml +48 -0
- package/runtime/syntax/gentoo-etc-portage.yaml +23 -0
- package/runtime/syntax/git-commit.yaml +35 -0
- package/runtime/syntax/git-config.yaml +14 -0
- package/runtime/syntax/git-rebase-todo.yaml +19 -0
- package/runtime/syntax/gleam.yaml +69 -0
- package/runtime/syntax/glsl.yaml +26 -0
- package/runtime/syntax/gnuplot.yaml +15 -0
- package/runtime/syntax/go.yaml +62 -0
- package/runtime/syntax/godoc.yaml +17 -0
- package/runtime/syntax/golo.yaml +73 -0
- package/runtime/syntax/gomod.yaml +31 -0
- package/runtime/syntax/graphql.yaml +47 -0
- package/runtime/syntax/groff.yaml +30 -0
- package/runtime/syntax/groovy.yaml +111 -0
- package/runtime/syntax/haml.yaml +16 -0
- package/runtime/syntax/hare.yaml +52 -0
- package/runtime/syntax/haskell.yaml +52 -0
- package/runtime/syntax/hc.yaml +52 -0
- package/runtime/syntax/html.yaml +70 -0
- package/runtime/syntax/html4.yaml +25 -0
- package/runtime/syntax/html5.yaml +25 -0
- package/runtime/syntax/ini.yaml +23 -0
- package/runtime/syntax/inputrc.yaml +14 -0
- package/runtime/syntax/java.yaml +37 -0
- package/runtime/syntax/javascript.yaml +76 -0
- package/runtime/syntax/jinja2.yaml +19 -0
- package/runtime/syntax/json.yaml +39 -0
- package/runtime/syntax/jsonnet.yaml +92 -0
- package/runtime/syntax/julia.yaml +57 -0
- package/runtime/syntax/justfile.yaml +40 -0
- package/runtime/syntax/keymap.yaml +27 -0
- package/runtime/syntax/kickstart.yaml +16 -0
- package/runtime/syntax/kotlin.yaml +66 -0
- package/runtime/syntax/kvlang.yaml +67 -0
- package/runtime/syntax/ledger.yaml +14 -0
- package/runtime/syntax/lfe.yaml +17 -0
- package/runtime/syntax/lilypond.yaml +26 -0
- package/runtime/syntax/lisp.yaml +17 -0
- package/runtime/syntax/log.yaml +92 -0
- package/runtime/syntax/lua.yaml +111 -0
- package/runtime/syntax/mail.yaml +25 -0
- package/runtime/syntax/makefile.yaml +38 -0
- package/runtime/syntax/man.yaml +12 -0
- package/runtime/syntax/markdown.yaml +49 -0
- package/runtime/syntax/mc.yaml +23 -0
- package/runtime/syntax/meson.yaml +51 -0
- package/runtime/syntax/micro.yaml +34 -0
- package/runtime/syntax/mpdconf.yaml +13 -0
- package/runtime/syntax/msbuild.yaml +6 -0
- package/runtime/syntax/nanorc.yaml +16 -0
- package/runtime/syntax/nftables.yaml +30 -0
- package/runtime/syntax/nginx.yaml +22 -0
- package/runtime/syntax/nim.yaml +27 -0
- package/runtime/syntax/nix.yaml +32 -0
- package/runtime/syntax/nu.yaml +114 -0
- package/runtime/syntax/objc.yaml +60 -0
- package/runtime/syntax/ocaml.yaml +43 -0
- package/runtime/syntax/octave.yaml +83 -0
- package/runtime/syntax/odin.yaml +64 -0
- package/runtime/syntax/pascal.yaml +45 -0
- package/runtime/syntax/patch.yaml +14 -0
- package/runtime/syntax/peg.yaml +16 -0
- package/runtime/syntax/perl.yaml +58 -0
- package/runtime/syntax/php.yaml +60 -0
- package/runtime/syntax/pkg-config.yaml +12 -0
- package/runtime/syntax/po.yaml +12 -0
- package/runtime/syntax/pony.yaml +37 -0
- package/runtime/syntax/pov.yaml +21 -0
- package/runtime/syntax/privoxy-action.yaml +14 -0
- package/runtime/syntax/privoxy-config.yaml +10 -0
- package/runtime/syntax/privoxy-filter.yaml +12 -0
- package/runtime/syntax/proto.yaml +40 -0
- package/runtime/syntax/prql.yaml +84 -0
- package/runtime/syntax/puppet.yaml +22 -0
- package/runtime/syntax/python2.yaml +60 -0
- package/runtime/syntax/python3.yaml +62 -0
- package/runtime/syntax/r.yaml +32 -0
- package/runtime/syntax/raku.yaml +42 -0
- package/runtime/syntax/reST.yaml +18 -0
- package/runtime/syntax/renpy.yaml +15 -0
- package/runtime/syntax/rpmspec.yaml +43 -0
- package/runtime/syntax/ruby.yaml +73 -0
- package/runtime/syntax/rust.yaml +78 -0
- package/runtime/syntax/sage.yaml +60 -0
- package/runtime/syntax/scad.yaml +53 -0
- package/runtime/syntax/scala.yaml +33 -0
- package/runtime/syntax/sed.yaml +13 -0
- package/runtime/syntax/sh.yaml +69 -0
- package/runtime/syntax/sls.yaml +15 -0
- package/runtime/syntax/smalltalk.yaml +55 -0
- package/runtime/syntax/solidity.yaml +41 -0
- package/runtime/syntax/sql.yaml +35 -0
- package/runtime/syntax/stata.yaml +67 -0
- package/runtime/syntax/svelte.yaml +27 -0
- package/runtime/syntax/swift.yaml +103 -0
- package/runtime/syntax/systemd.yaml +16 -0
- package/runtime/syntax/tcl.yaml +18 -0
- package/runtime/syntax/terraform.yaml +87 -0
- package/runtime/syntax/tex.yaml +32 -0
- package/runtime/syntax/toml.yaml +56 -0
- package/runtime/syntax/twig.yaml +55 -0
- package/runtime/syntax/typescript.yaml +49 -0
- package/runtime/syntax/v.yaml +80 -0
- package/runtime/syntax/vala.yaml +26 -0
- package/runtime/syntax/verilog.yaml +60 -0
- package/runtime/syntax/vhdl.yaml +37 -0
- package/runtime/syntax/vi.yaml +31 -0
- package/runtime/syntax/vue.yaml +64 -0
- package/runtime/syntax/xml.yaml +37 -0
- package/runtime/syntax/xresources.yaml +14 -0
- package/runtime/syntax/yaml.yaml +34 -0
- package/runtime/syntax/yum.yaml +12 -0
- package/runtime/syntax/zig.yaml +52 -0
- package/runtime/syntax/zscript.yaml +72 -0
- package/runtime/syntax/zsh.yaml +52 -0
- package/src/buffer/buffer.js +126 -0
- package/src/buffer/loc.js +38 -0
- package/src/buffer/message.js +29 -0
- package/src/config/colorscheme.js +109 -0
- package/src/config/config.js +118 -0
- package/src/config/defaults.js +102 -0
- package/src/display/ansi-style.js +60 -0
- package/src/highlight/highlighter.js +237 -0
- package/src/highlight/parser.js +137 -0
- package/src/index.js +5942 -0
- package/src/lua/engine.js +38 -0
- package/src/platform/archive.js +50 -0
- package/src/platform/clipboard.js +160 -0
- package/src/platform/commands.js +140 -0
- package/src/plugins/js-bridge.js +902 -0
- package/src/plugins/manager.js +619 -0
- package/src/runtime/registry.js +89 -0
- package/src/screen/cell-buffer.js +81 -0
- package/src/screen/events.js +263 -0
- package/src/screen/screen.js +118 -0
- package/src/screen/vt100.js +391 -0
- package/src/shell/shell.js +70 -0
- package/todo.txt +359 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
filetype: vi
|
|
2
|
+
|
|
3
|
+
detect:
|
|
4
|
+
filename: "(^|/|\\.)(ex|vim)rc$|\\.vim"
|
|
5
|
+
|
|
6
|
+
rules:
|
|
7
|
+
- identifier: "[A-Za-z_][A-Za-z0-9_]*[(]+[A-Za-z0-9_:.,\\s]*[)]+"
|
|
8
|
+
- special: "[()]+"
|
|
9
|
+
- statement: "\\b([nvxsoilc]?(nore|un)?map|[nvlx]n|[ico]?no|[cilovx][um]|s?unm)\\b"
|
|
10
|
+
- statement: "\\b(snor|nun|nm|set|if|endif|let|unlet|source)\\b"
|
|
11
|
+
- statement: "[!&=?]"
|
|
12
|
+
- constant.number: "\\b[0-9]+\\b"
|
|
13
|
+
|
|
14
|
+
- comment:
|
|
15
|
+
start: "(^\"|[ \t]+\" |[ \t]+\"$)"
|
|
16
|
+
end: "$"
|
|
17
|
+
rules: []
|
|
18
|
+
|
|
19
|
+
- constant.string:
|
|
20
|
+
start: "\""
|
|
21
|
+
end: "\""
|
|
22
|
+
skip: "\\\\."
|
|
23
|
+
rules:
|
|
24
|
+
- constant.specialChar: "\\\\."
|
|
25
|
+
|
|
26
|
+
- constant.string:
|
|
27
|
+
start: "'"
|
|
28
|
+
end: "'"
|
|
29
|
+
skip: "\\\\."
|
|
30
|
+
rules:
|
|
31
|
+
- constant.specialChar: "\\\\."
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
filetype: vue
|
|
2
|
+
|
|
3
|
+
detect:
|
|
4
|
+
filename: "\\.vue$"
|
|
5
|
+
|
|
6
|
+
rules:
|
|
7
|
+
- default:
|
|
8
|
+
start: "<template.*?>"
|
|
9
|
+
end: "</template.*?>"
|
|
10
|
+
limit-group: symbol.tag
|
|
11
|
+
rules:
|
|
12
|
+
- error: "<[^!].*?>"
|
|
13
|
+
- symbol.tag: "(?i)<[/]?(a|a(bbr|ddress|rea|rticle|side|udio)|b|b(ase|d(i|o)|lockquote|r|utton)|ca(nvas|ption)|center|cite|co(de|l|lgroup)|d(ata|atalist|d|el|etails|fn|ialog|l|t)|em|embed|fieldset|fig(caption|ure)|form|iframe|h[1-6]|hr|i|img|in(put|s)|kbd|keygen|label|legend|li|link|ma(in|p|rk)|menu|menuitem|met(a|er)|nav|noscript|o(bject|l|pt(group|ion)|utput)|p|param|picture|pre|progress|q|r(p|t|uby)|s|samp|se(ction|lect)|svg|small|source|span|strong|su(b|p|mmary)|textarea|time|track|u|ul|var|video|wbr)( .*)*?>"
|
|
14
|
+
- symbol.tag.extended: "(?i)<[/]?(body|div|html|head(er)?|footer|title|table|t(body|d|h(ead)?|r|foot))( .*)*?>"
|
|
15
|
+
- preproc: "(?i)<[/]?(script|style)( .*)*?>"
|
|
16
|
+
- special: "&[^;[[:space:]]]*;"
|
|
17
|
+
|
|
18
|
+
- identifier: "(alt|bgcolor|class|height|href|id|label|longdesc|name|on(click|focus|load|mouseover)|placeholder|size|span|src|style|target|type|value|width)="
|
|
19
|
+
- symbol: "[:=]"
|
|
20
|
+
- constant.string: "\"[^\"]*\""
|
|
21
|
+
- constant.number: "(?i)#[0-9a-fA-F]{6,6}"
|
|
22
|
+
|
|
23
|
+
- symbol.tag: "<|>"
|
|
24
|
+
- constant.string.url: "(ftp(s)?|http(s)?|git|chrome)://[^ ]+"
|
|
25
|
+
- comment: "<!--.+?-->"
|
|
26
|
+
#- preproc: "<!DOCTYPE.+?>"
|
|
27
|
+
- comment.block:
|
|
28
|
+
start: "<!\\-\\-"
|
|
29
|
+
end: "\\-\\->"
|
|
30
|
+
rules: []
|
|
31
|
+
|
|
32
|
+
# Bootstrap
|
|
33
|
+
- symbol.tag.extended: "(?i)<[/]?(b-alert|b-aspect|b-avatar|b-badge|b-icon|b-breadcrumb|b-button-group|b-button-toolbar|b-button|b-calendar|b-card-text|b-card-input|b-card|b-carousel-slide|b-carousel|b-collapse|b-dropdown|b-dropdown-item|b-dropdown-divider|b-embed|b-form-checkbox-group|b-form-checkbox|b-form-datepicker|b-form-file|b-form-group|b-form-input|b-form-radio|b-form-rating|b-form-select|b-form-spinbutton|b-form-tags|b-form-textarea|b-form|b-form-timepicker|b-img-lazy|b-img|b-input-group|b-jumbotron|b-input|b-container|b-row|b-col|b-link|b-list-group|b-list-group-item|b-media|b-modal|b-nav|b-nav-item|b-nav-item-dropdown|b-nav-text|b-nav-form|b-navbar|b-navbar-brand|b-navbar-toggle|b-navbar-nav|b-overlay|b-pagination|b-pagination-nav|b-popover|b-progress|b-progress-bar|b-sidebar|b-skeleton-wrapper|b-skeleton|b-spinner|b-table|b-table-lite|b-table-simple|b-tabs|b-tab|b-time|b-toast|b-tooltip)\\b"
|
|
34
|
+
- identifier: "(variant|title|show|shadow|icon|align-h|align-v|label-for|@submit|tag|img-alt|img-src|data-toggle|data-target|aria-controls|aria-expanded|aria-label|aria-disabled|tabindex|:interval|background|img-width|img-height|@sliding-start|@sliding-end|cols|header|@reset)="
|
|
35
|
+
- symbol: "[:=]"
|
|
36
|
+
# Vue
|
|
37
|
+
- symbol.tag.extended: "(?i)<[/]?(component|transition|transition-group|keep-alive|slot)\\b"
|
|
38
|
+
- identifier: "(v-text|v-html|v-show|v-if|v-else|v-else-if|v-for|v-on|v-bind|v-model|v-slot|v-pre|v-cloak|v-once|key|ref|is|@click)="
|
|
39
|
+
- symbol: "[:=]"
|
|
40
|
+
# Vue-router
|
|
41
|
+
- symbol.tag.extended: "(?i)<[/]?(router-link|router-view)\\b"
|
|
42
|
+
- identifier: "(to|v-slot)="
|
|
43
|
+
- symbol: "[:=]"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
- default:
|
|
47
|
+
start: "<script>"
|
|
48
|
+
end: "</script>"
|
|
49
|
+
limit-group: symbol.tag
|
|
50
|
+
rules:
|
|
51
|
+
- include: "javascript"
|
|
52
|
+
|
|
53
|
+
- default:
|
|
54
|
+
start: "<script[ ]+lang=(\"ts\"|'ts')>"
|
|
55
|
+
end: "</script>"
|
|
56
|
+
rules:
|
|
57
|
+
- include: "typescript"
|
|
58
|
+
|
|
59
|
+
- default:
|
|
60
|
+
start: "<style.*?>"
|
|
61
|
+
end: "</style.*?>"
|
|
62
|
+
limit-group: symbol.tag
|
|
63
|
+
rules:
|
|
64
|
+
- include: "css"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
filetype: xml
|
|
2
|
+
|
|
3
|
+
detect:
|
|
4
|
+
filename: "\\.(xml|sgml?|rng|svg|plist)$"
|
|
5
|
+
header: "<\\?xml.*\\?>"
|
|
6
|
+
|
|
7
|
+
rules:
|
|
8
|
+
- preproc:
|
|
9
|
+
start: "<!DOCTYPE"
|
|
10
|
+
end: "[/]?>"
|
|
11
|
+
rules: []
|
|
12
|
+
|
|
13
|
+
- comment:
|
|
14
|
+
start: "<!--"
|
|
15
|
+
end: "-->"
|
|
16
|
+
rules: []
|
|
17
|
+
|
|
18
|
+
- symbol.tag:
|
|
19
|
+
start: "<\\??"
|
|
20
|
+
end: "\\??>"
|
|
21
|
+
rules:
|
|
22
|
+
- identifier:
|
|
23
|
+
start: " "
|
|
24
|
+
end: "="
|
|
25
|
+
rules: []
|
|
26
|
+
- constant.string:
|
|
27
|
+
start: "\""
|
|
28
|
+
end: "\""
|
|
29
|
+
skip: "\\\\."
|
|
30
|
+
rules:
|
|
31
|
+
- constant.specialChar: "\\\\."
|
|
32
|
+
- constant.string:
|
|
33
|
+
start: "'"
|
|
34
|
+
end: "'"
|
|
35
|
+
skip: "\\\\."
|
|
36
|
+
rules:
|
|
37
|
+
- constant.specialChar: "\\\\."
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
filetype: xresources
|
|
2
|
+
|
|
3
|
+
detect:
|
|
4
|
+
filename: "X(defaults|resources)$"
|
|
5
|
+
|
|
6
|
+
rules:
|
|
7
|
+
- special: "^[[:alnum:]]+\\*"
|
|
8
|
+
- identifier.var: "\\*[[:alnum:]]+\\:"
|
|
9
|
+
- constant.number: "\\b[0-9]+\\b"
|
|
10
|
+
- symbol.operator: "[*:=]"
|
|
11
|
+
- constant.bool: "\\b(true|false)\\b"
|
|
12
|
+
- comment: "(^|[[:space:]])!([^{].*)?$"
|
|
13
|
+
- indent-char.whitespace: "[[:space:]]+$"
|
|
14
|
+
- indent-char: " + +| + +"
|
|
@@ -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,126 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { Loc } from "./loc.js";
|
|
3
|
+
|
|
4
|
+
export const BTDefault = { Kind: 0, Scratch: false, Readonly: false };
|
|
5
|
+
export const BTHelp = { Kind: 1, Scratch: true, Readonly: true };
|
|
6
|
+
export const BTLog = { Kind: 2, Scratch: true, Readonly: true };
|
|
7
|
+
export const BTScratch = { Kind: 3, Scratch: true, Readonly: false };
|
|
8
|
+
export const BTRaw = { Kind: 4, Scratch: true, Readonly: false };
|
|
9
|
+
export const BTInfo = { Kind: 5, Scratch: true, Readonly: true };
|
|
10
|
+
|
|
11
|
+
export class BufferCore {
|
|
12
|
+
constructor({ text = "", path = "", type = BTDefault, settings = {} } = {}) {
|
|
13
|
+
this.Path = path;
|
|
14
|
+
this.AbsPath = path;
|
|
15
|
+
this.Name = path ? basename(path) : "No name";
|
|
16
|
+
this.Type = type;
|
|
17
|
+
this.Settings = { filetype: "unknown", tabstospaces: false, tabsize: 4, ...settings };
|
|
18
|
+
this.lines = normalizeText(text).split("\n");
|
|
19
|
+
if (this.lines.length === 0) this.lines = [""];
|
|
20
|
+
this.Messages = [];
|
|
21
|
+
this.diffBase = "";
|
|
22
|
+
this.modified = false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Line(n) {
|
|
26
|
+
return this.lines[n] ?? "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
LineBytes(n) {
|
|
30
|
+
return new TextEncoder().encode(this.Line(n));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
LinesNum() {
|
|
34
|
+
return this.lines.length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Size() {
|
|
38
|
+
return new TextEncoder().encode(this.Bytes()).byteLength;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Bytes() {
|
|
42
|
+
return this.lines.join("\n");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
FileType() {
|
|
46
|
+
return this.Settings.filetype ?? "unknown";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
SetOption(option, value) {
|
|
50
|
+
this.Settings[option] = parseOption(value);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
DoSetOptionNative(option, value) {
|
|
54
|
+
this.Settings[option] = value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Insert(loc, text) {
|
|
58
|
+
const pos = normalizeLoc(loc);
|
|
59
|
+
const line = this.Line(pos.Y);
|
|
60
|
+
const before = line.slice(0, pos.X);
|
|
61
|
+
const after = line.slice(pos.X);
|
|
62
|
+
const parts = normalizeText(text).split("\n");
|
|
63
|
+
if (parts.length === 1) {
|
|
64
|
+
this.lines[pos.Y] = before + parts[0] + after;
|
|
65
|
+
} else {
|
|
66
|
+
const replacement = [before + parts[0], ...parts.slice(1, -1), parts.at(-1) + after];
|
|
67
|
+
this.lines.splice(pos.Y, 1, ...replacement);
|
|
68
|
+
}
|
|
69
|
+
this.modified = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Replace(start, end, text) {
|
|
73
|
+
const s = normalizeLoc(start);
|
|
74
|
+
const e = normalizeLoc(end);
|
|
75
|
+
if (s.Y === e.Y) {
|
|
76
|
+
const line = this.Line(s.Y);
|
|
77
|
+
this.lines[s.Y] = line.slice(0, s.X) + text + line.slice(e.X);
|
|
78
|
+
} else {
|
|
79
|
+
const first = this.Line(s.Y).slice(0, s.X);
|
|
80
|
+
const last = this.Line(e.Y).slice(e.X);
|
|
81
|
+
const parts = normalizeText(text).split("\n");
|
|
82
|
+
const replacement = parts.length === 1 ? [first + parts[0] + last] : [first + parts[0], ...parts.slice(1, -1), parts.at(-1) + last];
|
|
83
|
+
this.lines.splice(s.Y, e.Y - s.Y + 1, ...replacement);
|
|
84
|
+
}
|
|
85
|
+
this.modified = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
SetDiffBase(text) {
|
|
89
|
+
this.diffBase = String(text);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
AddMessage(message) {
|
|
93
|
+
this.Messages.push(message);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
ClearMessages(owner) {
|
|
97
|
+
this.Messages = this.Messages.filter((message) => message.Owner !== owner);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
ClearAllMessages() {
|
|
101
|
+
this.Messages = [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function byteOffset(pos, buffer) {
|
|
106
|
+
const loc = normalizeLoc(pos);
|
|
107
|
+
let offset = 0;
|
|
108
|
+
for (let y = 0; y < loc.Y; y++) offset += buffer.Line(y).length + 1;
|
|
109
|
+
return offset + buffer.Line(loc.Y).slice(0, loc.X).length;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function normalizeLoc(value) {
|
|
113
|
+
if (value instanceof Loc) return value;
|
|
114
|
+
return new Loc(value?.X ?? value?.x ?? 0, value?.Y ?? value?.y ?? 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function normalizeText(text) {
|
|
118
|
+
return String(text).replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseOption(value) {
|
|
122
|
+
if (value === "on" || value === "true") return true;
|
|
123
|
+
if (value === "off" || value === "false") return false;
|
|
124
|
+
if (/^-?\d+(\.\d+)?$/.test(String(value))) return Number(value);
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class Loc {
|
|
2
|
+
constructor(x = 0, y = 0) {
|
|
3
|
+
this.X = x;
|
|
4
|
+
this.Y = y;
|
|
5
|
+
this.x = x;
|
|
6
|
+
this.y = y;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
lessThan(other) {
|
|
10
|
+
return this.Y < other.Y || (this.Y === other.Y && this.X < other.X);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
greaterThan(other) {
|
|
14
|
+
return this.Y > other.Y || (this.Y === other.Y && this.X > other.X);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
greaterEqual(other) {
|
|
18
|
+
return this.greaterThan(other) || (this.X === other.X && this.Y === other.Y);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
lessEqual(other) {
|
|
22
|
+
return this.lessThan(other) || (this.X === other.X && this.Y === other.Y);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
clamp(start, end) {
|
|
26
|
+
if (this.greaterEqual(end)) return end;
|
|
27
|
+
if (this.lessThan(start)) return start;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toJSON() {
|
|
32
|
+
return { X: this.X, Y: this.Y };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function loc(x = 0, y = 0) {
|
|
37
|
+
return new Loc(x, y);
|
|
38
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Loc } from "./loc.js";
|
|
2
|
+
|
|
3
|
+
export const MTInfo = 0;
|
|
4
|
+
export const MTWarning = 1;
|
|
5
|
+
export const MTError = 2;
|
|
6
|
+
|
|
7
|
+
export class BufferMessage {
|
|
8
|
+
constructor(owner, msg, start, end, kind) {
|
|
9
|
+
this.Owner = owner;
|
|
10
|
+
this.Msg = msg;
|
|
11
|
+
this.Start = start;
|
|
12
|
+
this.End = end;
|
|
13
|
+
this.Kind = kind;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function newMessage(owner, msg, start, end, kind) {
|
|
18
|
+
return new BufferMessage(owner, msg, normalizeLoc(start), normalizeLoc(end), kind);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function newMessageAtLine(owner, msg, line, kind) {
|
|
22
|
+
const pos = new Loc(-1, Number(line) - 1);
|
|
23
|
+
return newMessage(owner, msg, pos, pos, kind);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeLoc(value) {
|
|
27
|
+
if (value instanceof Loc) return value;
|
|
28
|
+
return new Loc(value?.X ?? value?.x ?? 0, value?.Y ?? value?.y ?? 0);
|
|
29
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export const DEFAULT_STYLE = {
|
|
2
|
+
fg: "default",
|
|
3
|
+
bg: "default",
|
|
4
|
+
bold: false,
|
|
5
|
+
italic: false,
|
|
6
|
+
reverse: false,
|
|
7
|
+
underline: false,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// Built-in fallback styles for color groups not defined in a colorscheme.
|
|
11
|
+
// Matches Go micro's default group colours.
|
|
12
|
+
const BUILTIN_GROUPS = {
|
|
13
|
+
"diff-added": { ...DEFAULT_STYLE, fg: "green" },
|
|
14
|
+
"diff-modified": { ...DEFAULT_STYLE, fg: "yellow" },
|
|
15
|
+
"diff-deleted": { ...DEFAULT_STYLE, fg: "red" },
|
|
16
|
+
"gutter-error": { ...DEFAULT_STYLE, fg: "red" },
|
|
17
|
+
"gutter-warning":{ ...DEFAULT_STYLE, fg: "yellow" },
|
|
18
|
+
"gutter-info": { ...DEFAULT_STYLE, fg: "brightblue" },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const COLOR_LINK = /color-link\s+(\S*)\s+"(.*)"/;
|
|
22
|
+
const INCLUDE = /include\s+"(.*)"/;
|
|
23
|
+
|
|
24
|
+
export class Colorscheme {
|
|
25
|
+
constructor(runtime) {
|
|
26
|
+
this.runtime = runtime;
|
|
27
|
+
this.styles = new Map();
|
|
28
|
+
this.defaultStyle = { ...DEFAULT_STYLE };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async load(name = "default", parsed = new Set()) {
|
|
32
|
+
const file = this.runtime.find(0, name);
|
|
33
|
+
if (!file) throw new Error(`${name} is not a valid colorscheme`);
|
|
34
|
+
parsed.add(name);
|
|
35
|
+
const parsedStyles = await this.parse(name, await file.text(), parsed);
|
|
36
|
+
this.styles = parsedStyles;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async parse(name, text, parsed = new Set()) {
|
|
41
|
+
const styles = new Map();
|
|
42
|
+
for (const rawLine of String(text).split("\n")) {
|
|
43
|
+
const line = rawLine.trim();
|
|
44
|
+
if (!line || line.startsWith("#")) continue;
|
|
45
|
+
|
|
46
|
+
const include = line.match(INCLUDE);
|
|
47
|
+
if (include) {
|
|
48
|
+
const includeName = include[1];
|
|
49
|
+
if (!parsed.has(includeName)) {
|
|
50
|
+
const child = new Colorscheme(this.runtime);
|
|
51
|
+
await child.load(includeName, parsed);
|
|
52
|
+
for (const [key, value] of child.styles) styles.set(key, value);
|
|
53
|
+
if (child.styles.has("default")) this.defaultStyle = child.styles.get("default");
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const match = line.match(COLOR_LINK);
|
|
59
|
+
if (!match) throw new Error(`Color-link statement is not valid: ${rawLine}`);
|
|
60
|
+
const style = stringToStyle(match[2], this.defaultStyle);
|
|
61
|
+
styles.set(match[1], style);
|
|
62
|
+
if (match[1] === "default") this.defaultStyle = style;
|
|
63
|
+
}
|
|
64
|
+
if (styles.has("default")) this.defaultStyle = styles.get("default");
|
|
65
|
+
return styles;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get(group) {
|
|
69
|
+
if (!group) return this.defaultStyle;
|
|
70
|
+
const parts = String(group).split(".");
|
|
71
|
+
let style = this.styles.get(group);
|
|
72
|
+
if (parts.length > 1) {
|
|
73
|
+
let cur = "";
|
|
74
|
+
for (const part of parts) {
|
|
75
|
+
cur = cur ? `${cur}.${part}` : part;
|
|
76
|
+
if (this.styles.has(cur)) style = this.styles.get(cur);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return style ?? BUILTIN_GROUPS[group] ?? stringToStyle(group, this.defaultStyle);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function stringToStyle(input, base = DEFAULT_STYLE) {
|
|
84
|
+
const text = String(input);
|
|
85
|
+
const colorPart = text.split(/\s+/).at(-1) ?? "";
|
|
86
|
+
const [fgRaw = "default", bgRaw = "default"] = colorPart.split(",");
|
|
87
|
+
return {
|
|
88
|
+
fg: stringToColor(fgRaw.trim(), base.fg),
|
|
89
|
+
bg: stringToColor(bgRaw.trim(), base.bg),
|
|
90
|
+
bold: text.includes("bold"),
|
|
91
|
+
italic: text.includes("italic"),
|
|
92
|
+
reverse: text.includes("reverse"),
|
|
93
|
+
underline: text.includes("underline"),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function stringToColor(value, fallback = "default") {
|
|
98
|
+
const color = String(value || "default").trim();
|
|
99
|
+
if (color === "default" || color === "") return fallback;
|
|
100
|
+
if (/^\d+$/.test(color)) return Number(color);
|
|
101
|
+
if (/^#[0-9a-fA-F]{6}$/.test(color)) return color;
|
|
102
|
+
const names = new Set([
|
|
103
|
+
"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",
|
|
104
|
+
"brightblack", "brightred", "brightgreen", "brightyellow", "brightblue",
|
|
105
|
+
"brightmagenta", "brightcyan", "brightwhite", "lightblack", "lightred",
|
|
106
|
+
"lightgreen", "lightyellow", "lightblue", "lightmagenta", "lightcyan", "lightwhite",
|
|
107
|
+
]);
|
|
108
|
+
return names.has(color) ? color : fallback;
|
|
109
|
+
}
|