15 Commits

62 changed files with 4071 additions and 1857 deletions

View File

@@ -1,7 +1,8 @@
CompileFlags: CompileFlags:
Add: [-I/home/syed/main/crib/include, -I/home/syed/main/crib/libs, c++20] Add: [
-I/home/syed/main/crib/include,
-I/home/syed/main/crib/libs,
-std=c++23
]
Remove: [] Remove: []
Compiler: clang++ Compiler: clang++
HeaderInsertion:
Policy: Never

2
.gitattributes vendored
View File

@@ -1 +1 @@
/libs/unicode_width/** linguist-vendored /libs/** linguist-vendored

3
.gitignore vendored
View File

@@ -3,6 +3,7 @@
*.a *.a
*.o *.o
*.so *.so
!libs/libruby/libruby.so
*.yml *.yml
.vscode .vscode
@@ -13,5 +14,7 @@ build
bin bin
.thinlto-cache/ .thinlto-cache/
Gemfile*
.ruby-lsp/
__old__ __old__

View File

@@ -9,23 +9,28 @@ TARGET_RELEASE := $(BIN_DIR)/crib
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
GENERATED_HEADER := $(INCLUDE_DIR)/scripting/ruby_compiled.h
CCACHE := ccache CCACHE := ccache
CXX := $(CCACHE) clang++ CXX := $(CCACHE) clang++
CC := $(CCACHE) musl-clang
CFLAGS_DEBUG :=\ CFLAGS_DEBUG :=\
-std=c++20 -Wall -Wextra \ -std=c++20 -Wall -Wextra \
-O0 -fno-inline -gsplit-dwarf\ -O0 -fno-inline -gsplit-dwarf \
-g -fsanitize=address -fno-omit-frame-pointer\ -g -fno-omit-frame-pointer \
-Wno-unused-command-line-argument \ -Wno-unused-command-line-argument \
-fsanitize=address \
-I./include -I./libs -I./include -I./libs
CFLAGS_RELEASE :=\ CFLAGS_RELEASE :=\
-std=c++20 -O3 -march=native \ -static --target=x86_64-linux-musl \
-fno-exceptions -fno-rtti -fstrict-aliasing \ -std=c++20 -O3 -march=x86-64 -mtune=generic \
-fno-rtti \
-ffast-math -flto=thin \ -ffast-math -flto=thin \
-fvisibility=hidden -fuse-ld=lld \ -fvisibility=hidden \
-fomit-frame-pointer -DNDEBUG -s \ -fomit-frame-pointer -DNDEBUG -s \
-mllvm -vectorize-loops \ -mllvm -vectorize-loops \
-fno-unwind-tables -fno-asynchronous-unwind-tables\
-Wno-unused-command-line-argument \ -Wno-unused-command-line-argument \
-I./include -I./libs -I./include -I./libs
@@ -37,9 +42,13 @@ UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC)) UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC)) UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
LIBS := \ LIBS_RELEASE := \
libs/libgrapheme/libgrapheme.a \ libs/libgrapheme/libgrapheme.a \
-lpcre2-8 -lmagic -Wl,-Bstatic,--gc-sections -lpcre2-8 -lmruby
LIBS_DEBUG := \
libs/libgrapheme/libgrapheme.a \
-Wl,-Bdynamic -lpcre2-8 -lmruby
SRC := $(wildcard $(SRC_DIR)/**/*.cc) $(wildcard $(SRC_DIR)/*.cc) SRC := $(wildcard $(SRC_DIR)/**/*.cc) $(wildcard $(SRC_DIR)/*.cc)
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC)) OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
@@ -56,6 +65,9 @@ test: $(TARGET_DEBUG)
release: $(TARGET_RELEASE) release: $(TARGET_RELEASE)
$(GENERATED_HEADER): $(INCLUDE_DIR)/syntax/tokens.def $(INCLUDE_DIR)/scripting/libcrib.rb src/ruby_compile.sh
src/ruby_compile.sh
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h $(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CXX) $(PCH_CFLAGS_DEBUG) -o $@ $< $(CXX) $(PCH_CFLAGS_DEBUG) -o $@ $<
@@ -66,27 +78,27 @@ $(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS) $(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS_DEBUG)
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS) $(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS_RELEASE)
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG) $(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG) $(GENERATED_HEADER)
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CXX) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@ $(CXX) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE) $(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE) $(GENERATED_HEADER)
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CXX) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@ $(CXX) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c $(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CXX) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@ $(CC) -MMD -MP -c $< -o $@
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c $(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CXX) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@ $(CC) -MMD -MP -c $< -o $@
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d) DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d) DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)

169
README.md
View File

@@ -12,6 +12,18 @@ It aims to be complete general purpose IDE.<br>
(It is still very much a work in progress so a lot of things may seem incomplete)<br> (It is still very much a work in progress so a lot of things may seem incomplete)<br>
For now it is just a single file editor. I plan to add a multi-file support with file pickers and tabs soon.<br> For now it is just a single file editor. I plan to add a multi-file support with file pickers and tabs soon.<br>
## Installation
Binary can be installed with the following command:
```bash
curl https://syedm.dev/crib | sh
```
It requires `libmagic` to be installed (most systems have it preinstalled).<br>
Currently only for Linux.<br>
*Tested with arch linux and ubuntu*<br>
## Building ## Building
### Get started ### Get started
@@ -40,10 +52,10 @@ Make sure you have the following dependencies installed (apart from the standard
#include <pcre2.h> #include <pcre2.h>
``` ```
* **libmagic** * **[mruby](https://github.com/mruby/mruby)**
Install it so that you can include it in your code (most *nix systems have it installed): Install it via your package manager. Once installed, the header should be available as:
```cpp ```cpp
#include <magic.h> #include <mruby.h>
``` ```
It also uses `xclip` at runtime for copying/pasting *(TODO: make it os portable)*. It also uses `xclip` at runtime for copying/pasting *(TODO: make it os portable)*.
@@ -51,16 +63,18 @@ And any modern terminal should work fine - preferably `kitty` or `wezterm`.<br>
#### `./libs` folder #### `./libs` folder
Some other dependancies like `libgrapheme` and `unicode_width` are added as submodules or copied.<br> Some other dependancies are added as submodules or copied.<br>
`unicode_width` is compiled by the makefile so nothing to do there.<br> - `unicode_width` is compiled by the makefile so nothing to do there.<br>
`libgrapheme` needs to be compiled using `make` in it's folder.<br> - `libgrapheme` needs to be compiled using `make` in it's folder.<br>
#### LSPs #### LSPs
The following lsp's are supported and can be installed anywhere in your `$PATH`<br> Lsp's are defined in the `libcrib.rb` file and you can use your `config/main.rb` file to add more.<br>
The following lsp's are added by default and can be installed anywhere in your `$PATH`<br>
* [clangd](https://clangd.llvm.org/) * [clangd](https://clangd.llvm.org/)
* [solargraph](https://solargraph.org/) * [ruby-lsp](https://shopify.github.io/ruby-lsp/)
* [bash-language-server](https://github.com/bash-lsp/bash-language-server) * [bash-language-server](https://github.com/bash-lsp/bash-language-server)
* [vscode-css-language-server](https://github.com/hrsh7th/vscode-langservers-extracted) * [vscode-css-language-server](https://github.com/hrsh7th/vscode-langservers-extracted)
* [vscode-json-language-server](https://github.com/hrsh7th/vscode-langservers-extracted) * [vscode-json-language-server](https://github.com/hrsh7th/vscode-langservers-extracted)
@@ -81,14 +95,11 @@ The following lsp's are supported and can be installed anywhere in your `$PATH`<
* [make-language-server](https://github.com/Freed-Wu/autotools-language-server) * [make-language-server](https://github.com/Freed-Wu/autotools-language-server)
> As it is still in development, some of these may not work as expected or that well.<br> > As it is still in development, some of these may not work as expected or that well.<br>
> But for c/ruby/lua/python it should work fine (I test more with these).<br>
> It should work even if the lsp is not installed but lsp features will not work.<br> > It should work even if the lsp is not installed but lsp features will not work.<br>
> See `include/config.h` & `include/ts/decl.h` if you want to add your own lsp and/or tree-sitter grammar.<br>
#### Compiler #### Compiler
`g++` and `clang++` should both work fine but `c++20+` is required. `clang++` should work fine but `c++23+` is required.<br>
The makefile uses `clang++` by default.<br>
Can remove `ccache` if you want from the makefile.<br> Can remove `ccache` if you want from the makefile.<br>
#### Compliling #### Compliling
@@ -100,9 +111,6 @@ make release
### Running ### Running
Preferably add the `bin` folder to PATH or move `bin/crib` to somewhere in PATH.<br> Preferably add the `bin` folder to PATH or move `bin/crib` to somewhere in PATH.<br>
But make sure that `scripts/` are at `../` relative to the binary or it will crash.<br>
`scripts/init.sh` and `scripts/exit.sh` can be used to add hooks to the editor on startup and exit
(Make sure to remove my `kitty` hooks from them if you want).<br>
For some LSP's to work properly `crib` needs to be run from the root folder of the project. *To be fixed*<br> For some LSP's to work properly `crib` needs to be run from the root folder of the project. *To be fixed*<br>
then do -<br> then do -<br>
@@ -110,127 +118,12 @@ then do -<br>
crib ./filename.ext crib ./filename.ext
``` ```
*If `filename.ext` does not exist, it will fail to load the editor - use `touch filename.ext` to create it - to be fixed*<br> *If `filename.ext` does not exist, it will be created*<br>
*Try out with files in `samples/`*<br>
## Keybindings ## Keybindings
### Mouse Interactions TODO: add keybind information on how to set in `config/main.rb`
and default / unchangeable keybinds
These interactions work globally or generally across the editor canvas.
| Action | Function |
| --- | --- |
| **Scroll Up/Down** | Scrolls the view. |
| **Scroll Left/Right** | Moves the cursor left or right. |
| **Left Click (Press)** | Moves cursor to position; resets selection. |
| **Left Click (Double)** | Selects the **word** under the cursor (enters SELECT mode). |
| **Left Click (Triple)** | Selects the **line** under the cursor (enters SELECT mode). |
| **Left Click (Drag)** | Selects text (Character, Word, or Line based on initial click type). |
| **Left Click (Release)** | If cursor and selection start are the same, returns to NORMAL mode. |
### Navigation (Global / Special Keys)
These keys work primarily in Normal mode but handle movement logic.
| Key | Modifier | Function |
| --- | --- | --- |
| **Arrows** (Up/Down/Left/Right) | None | Move cursor 1 step in that direction. |
| **Arrows** (Up/Down) | `CTRL` | Move cursor **5 steps** in that direction. |
| **Arrows** (Left/Right) | `CTRL` | Jump to the previous/next **word boundary**. |
| **Arrows** (Up/Down) | `ALT` | **Move the current line** Up or Down. |
| **Arrows** (Left/Right) | `ALT` | Move cursor **8 steps** in that direction. |
### NORMAL Mode
This is the default navigation and command mode.
| Key | Function |
| --- | --- |
| **i** | Enter **INSERT** mode (at current position). |
| **a** | Enter **INSERT** mode (append: moves cursor right by 1 first). |
| **s** or **v** | Enter **SELECT** mode (start character selection). |
| **:** or **;** | Enter **RUNNER** mode (Command Bar). |
| **u** | Select the **last line** of the file (Jumps to bottom). |
| **h** | Trigger **LSP Hover** information for the symbol under cursor. |
| **Ctrl + h** | Scroll the hover window **Up**. |
| **Ctrl + l** | Scroll the hover window **Down**. |
| **Ctrl + s** | **Save** the file. |
| **Ctrl + d** | Scroll Page **Down** (1 unit). |
| **Ctrl + u** | Scroll Page **Up** (1 unit). |
| **p** | **Paste** from clipboard at cursor position (moves cursor to end of paste). |
| **>** or **.** | **Indent** the current line. |
| **<** or **,** | **Dedent** (un-indent) the current line. |
| **Space** | Move cursor Right. |
| **Backspace** (`0x7F`) | Move cursor Left. |
| **Enter** (`\n`, `\r`) | Move cursor Down. |
| **\| or \\** | Move cursor Up. |
| **n** | Enter **JUMPER** mode (Set Bookmark). |
| **m** | Enter **JUMPER** mode (Jump to Bookmark). |
| **N** | Clear specific Jumper hook (logic attempts to clear hook at current line). |
### INSERT Mode
Used for typing text.
| Key | Function |
| --- | --- |
| **Esc** (`0x1B`) | Return to **NORMAL** mode. |
| **Tab** (`\t`) | Inserts 2 spaces. |
| **Enter** | Inserts newline + **Auto-indents** based on previous line/context. |
| **Backspace** | Deletes previous character or auto-collapses empty pairs (e.g., `{` -> `}`). |
| **Ctrl + w** | **Delete Previous Word**. |
| **Del** | Delete character under cursor. |
| **Ctrl + Del** | Delete **Next Word**. |
| **Typing** | Inserts characters. |
| **Ctrl + Shift + v or as configured in your terminal** | System pasting. |
| **{ ( [ " '** | Auto-inserts closing pair (e.g., typing `{` inserts `{}`). |
| **} ) ] " '** | If the next char matches the typed char, skip insertion (overwrite), otherwise insert. |
#### Autocompletion (Inside Insert Mode)
These function only if LSP and completion are active.
| Key | Function |
| --- | --- |
| **Ctrl + p** | Select **Next** completion item. |
| **Ctrl + o** | Select **Previous** completion item. |
| **Ctrl + \\** | **Accept** selected completion OR trigger new completion request. |
| **Trigger Chars** | (e.g., `.`, `>`) Automatically triggers completion popup. |
### SELECT Mode
Used for highlighting text.
| Key | Function |
| --- | --- |
| **Esc**, **s**, **v** | Cancel selection and return to **NORMAL** mode. |
| **y** | **Yank (Copy)** selection to clipboard → Return to Normal. |
| **x** | **Cut** selection to clipboard → Return to Normal. |
| **p** | **Paste** over selection (Replace text) → Return to Normal. |
| **f** | **Fold** the selected range (collapses code) → Return to Normal. |
### JUMPER Mode
This mode uses a bookmarking system mapped to keyboard characters.
* **Entered via `n` (Set Mode):**
* Pressing any key `!` through `~` assigns the current line number to that key.
* **Entered via `m` (Jump Mode):**
* Pressing any key `!` through `~` jumps the cursor to the line previously assigned to that key.
### RUNNER Mode (Command Bar)
Activated by `:` or `;`.
| Key | Function |
| --- | --- |
| **Esc** | Cancel and return to **NORMAL** mode. |
| **Enter** | Execute the typed command. |
| **Left / Right** | Move cursor within the command bar. |
| **Up / Down** | Intended for command history. (Not implemented) |
| **Typing** | Insert characters into the command bar. (Not implemented) |
## Features Implemented ## Features Implemented
@@ -250,9 +143,9 @@ Activated by `:` or `;`.
- hooks jumping (bookmarking) - hooks jumping (bookmarking)
- color hex code highlighting - color hex code highlighting
- current line highlighting - current line highlighting
<!-- - TODO: current word under cursor highlighting --> - all instances of current word under cursor highlighting
#### syntax highlighting and filetype detection (using extention or libmagic) for: #### syntax highlighting and filetype detection for:
- ruby - ruby
<!-- TODO: --> <!-- TODO: -->
<!-- - bash --> <!-- - bash -->
@@ -286,11 +179,13 @@ Activated by `:` or `;`.
#### LSP-powered features: #### LSP-powered features:
- diagnostics - diagnostics
- autocompletion - autocompletion
- hover docs (with markdown support) - hover docs
- formatting support - formatting support
- Full file formatting on save - Full file formatting on save
- Ontype formatting when inserting special characters defined by the language server - Ontype formatting when inserting special characters defined by the language server
- *(few lsp's actually support this - try to configure a few more which can but need configuration and for others need to add support for external formatters)* - *(few lsp's actually support this - try to configure a few more which can but need configuration and for others need to add support for external formatters)*
- A list of all supported lsp's can be found [here](#lsps). - A list of some lsp's can be found [here](#lsps).
- Any lsp can be added to the `config/main.rb` file.
- Though not all might work well. Open an issue if you find a lsp that doesn't work well.
**A lot lot more to come** **A lot lot more to come**

85
TODO.md
View File

@@ -2,16 +2,15 @@ Copyright 2025 Syed Daanish
# TODO # TODO
### Critical Fixes ##### BTW Check each lsp with each of the features implemented
##### Check each lsp with each of the features implemented
* [ ] Make a proper qeued system for bar contents from ruby
* [ ] Allow clipbaord setting & alpha in ini files
* [ ] Make warning before ctrl+q for saving
* [ ] **LSP Bug:** Check why `fish-lsp` is behaving so off with completions filtering. * [ ] **LSP Bug:** Check why `fish-lsp` is behaving so off with completions filtering.
* [ ] **File IO:** Normalize/validate unicode on file open (enforce UTF-8, handle other types gracefully).
* [ ] **Critical Crash:** Fix bug where closing immediately while LSP is still loading hangs and then segfaults (especially on slow ones like fish-lsp where quick edits and exit can hang).
* [ ] **Line move:** fix the move line functions to work without the calculations from folds as folds are removed. * [ ] **Line move:** fix the move line functions to work without the calculations from folds as folds are removed.
* [ ] **Modularize handle_events and renderer functions:** The function is over 700 lines with a lot of repeating blocks. Split into smaller functions.
* [ ] **Editor Indentation Fix:** - Main : merger indentation with the parser for more accurate results. * [ ] **Editor Indentation Fix:** - Main : merger indentation with the parser for more accurate results.
* [ ] Fix bug where enter at start of line with ending type crashes
* [ ] Keep cache of language maps in engine to reduce lookup time. * [ ] Keep cache of language maps in engine to reduce lookup time.
* [ ] In indents add function to support tab which indents if before any content and inserts a pure \t otherwise. * [ ] In indents add function to support tab which indents if before any content and inserts a pure \t otherwise.
* [ ] And backspace which undents if before any content. * [ ] And backspace which undents if before any content.
@@ -20,23 +19,46 @@ Copyright 2025 Syed Daanish
* [ ] These will dedent when the block immediately after them is dedented * [ ] These will dedent when the block immediately after them is dedented
* [ ] Dont dedent if ending is valid starting is invalid but also empty * [ ] Dont dedent if ending is valid starting is invalid but also empty
* [ ] Just leave asis if starting is empty * [ ] Just leave asis if starting is empty
* [ ] **Readme:** Update readme to show indetation mechanics. * [ ] **Readme:** Update readme to show ruby based config.
* [ ] **LSP Bug:** Try to find out why emojis are breaking lsp edits. (check the ruby sample)
* [ ] **UI Refinement:** * [ ] **UI Refinement:**
* [ ] Allow completion list to be scrolled; show only `x` max items. * [ ] Allow completion list to be scrolled; show only `x` max items.
* [ ] Finish autocomplete box style functions. * [ ] Finish autocomplete box style functions.
* [ ] **Documentation UI:** Capture `Ctrl+h` / `Ctrl+l` for scrolling documentation windows. * [ ] **Documentation UI:** Capture `Ctrl+h` / `Ctrl+l` for scrolling documentation windows.
* [ ] **Redo hooks and folding as proper engines**: With functions to checkstate/cursor like function and edits application. * [ ] Redo hooks as a struct.
* [ ] Do trextmate like regex grammar parsing with lsp symbols for semantic highlighting. * [ ] breakdown the render function into smaller functions.
* Probably remove tre--sitter or just keep it for context tree.
* Making bracket matching andignoring strings/comments easier.
* remove tree-sitter mention from everywhere especially submodules
* make it faster for line inserts/deletes too (treeify the vector)
* Try to make all functions better now that folds have been purged * Try to make all functions better now that folds have been purged
* Cleanup syntax and renderer files * Cleanup syntax and renderer files
* Fix ruby regexp not living across lines when edits are made
* for ruby regex use hueristic where is a space is seen after the / it is not a regexp * Add a thing called view which is a rect with speacial type editor . but otherwise a ruby or c++ view
* can be used for stuff like file manager/git manager/theme picker.
* allow flushing functions in ruby to tell c++ to refresh keybinds/themes etc.
* allow keybinds to be set in ruby
check::
pull diagnostics for ruby-lsp
lsp selection range - use to highlight start / end of range maybe?
goto definiton
signature help
document symbol for the top bar maybe? (or workspace symbol)
also setup workspaces
Semantic highlighting
Quick fixes
Rename symbols
probably remove solargraph support and use ruby-lsp (or sorbet?) instead because it is a pain for utf stuff
ruby-lsp also supports erb so thats a plus
move lsp configs to json and also allow configs for windows-style vs unix-style line endings and utf-8 vs utf-16
* the ruby should have an api to be able to draw windows and add mappings to them
* finish bash then do all the directive-like ones like jsonc (first to help with theme files) / toml / yaml / ini / nginx
* then markdown / html
* then gitignore / gitattributes
* then fish then sql then css and [jt]sx? then python then lua (make with type annotations for lsp results)
* then [ch](++)? then gdscript then erb then php
* then haskell then gomod then go then rust
* [ ] **Undo/Redo:** Add support for undo/redo history. * [ ] **Undo/Redo:** Add support for undo/redo history.
@@ -45,7 +67,7 @@ Copyright 2025 Syed Daanish
* [ ] **Tree-sitter Indent:** Attempt to allow Tree-sitter to handle indentation if possible. * [ ] **Tree-sitter Indent:** Attempt to allow Tree-sitter to handle indentation if possible.
* [ ] **Scrolling:** Add logic where selecting at the end of the screen scrolls down (and vice versa). * [ ] **Scrolling:** Add logic where selecting at the end of the screen scrolls down (and vice versa).
* *Implementation:* Update `main.cc` to send drag events to the selected editor. * *Implementation:* Update `main.cc` to send drag events to the selected editor even if coordinates are out of bounds.
### UX ### UX
@@ -62,11 +84,6 @@ Copyright 2025 Syed Daanish
* [ ] Handle snippets properly in autocomplete: use only the last word in signature when replacing and set cursor to the first one. * [ ] Handle snippets properly in autocomplete: use only the last word in signature when replacing and set cursor to the first one.
* [ ] **Basic Autocomplete:** Keep a list of words in the current buffer for non-LSP fallback. * [ ] **Basic Autocomplete:** Keep a list of words in the current buffer for non-LSP fallback.
* [ ] **Language Support:**
* [ ] Add ECMA to JS and make TSX support.
* [ ] Add formatting for files where LSP doesn't provide it.
* [ ] Redo grammar files properly (especially cpp).
### Major Features ### Major Features
@@ -83,21 +100,12 @@ Copyright 2025 Syed Daanish
* [ ] **Block Selection:** * [ ] **Block Selection:**
* [ ] Double-clicking a bracket selects the whole block (first time only) and sets mode to `WORD`. * [ ] Double-clicking a bracket selects the whole block (first time only) and sets mode to `WORD`.
* [ ] **Tree-sitter Context:**
* [ ] Get code context from Tree-sitter.
* [ ] Get node path of current cursor and add indicator bar (breadcrumbs).
* [ ] Highlight block edges when cursor is on/in a bracket.
### Visuals, UI & Extensions? ### Visuals, UI & Extensions?
*Focus: Aesthetics and external integrations.*
* [ ] **Status Bar:** Complete status bar and command runner. * [ ] **Status Bar:** Complete status bar and command runner.
* [ ] **Visual Aids:** * [ ] Add color picker/palette.
* [ ] Expand color regex to match CSS colors in CSS files.
* [ ] Add color picker/palette.
* [ ] **Git:** Add Git integration (status, diffs). * [ ] **Git:** Add Git integration (status, diffs).
* [ ] **AI/Snippets:** * [ ] **AI/Snippets:**
@@ -110,21 +118,8 @@ Copyright 2025 Syed Daanish
### Optimizations & Fluff ### Optimizations & Fluff
* [ ] **Event Loop:**
* [ ] Make the whole engine event-driven rather than clock-driven.
* [ ] Mybe keep background thread with dirty flag.
* [ ] But merge input and render into a single loop that only renders when input affects render or background thread needs refresh and try to couple multiple renders.
* [ ] LSP and inputs should be blocking (lsp on its fd) and inputs in io/input.cc
* [ ] **Performance:** * [ ] **Performance:**
* [ ] Switch JSON parser to `RapidJSON` (or similar high-performance lib). * [ ] Switch JSON parser to `RapidJSON` (or similar high-performance lib).
* [ ] Decrease usage of `std::string` in UI, LSP, and warnings. * [ ] Decrease usage of `std::string` in UI, LSP, and warnings.
* [ ] Also for vectors into managed memory especially for completions/lsp-stuff. * [ ] Also for vectors into managed memory especially for completions/lsp-stuff.
* [ ] **Folding:** Redo folding system and its relation to `move_line_*` functions.
* [ ] **Grammars:**
* [ ] Manually add redo SCM files (especially cpp/c/h).
* [ ] Create `lua-typed` and `man pages` Tree-sitter grammars.
* [ ] **Repo Maintenance:** Once renderer is proven check commit `43f443e`.

128
config/main.rb Normal file
View File

@@ -0,0 +1,128 @@
# basic configuration
# This can also be used to do speacail configs for different projects.
# its ruby guys script whatever you want.
# puts "Loading main config..."
C.startup do
puts "Starting crib..."
end
C.shutdown do
puts "Exiting crib..."
end
# this can be modified by the user during runtime through keybindings
# But i need to know how to ever read this value only when needed.
# maybe i can write a function that notifies if theme maybe changed then reload
# It can also be scripted to load different theme formats into a hash usable by crib
C.theme = {
:default => { fg: 0xEEEEEE },
:shebang => { fg: 0x7DCFFF },
:error => { fg: 0xEF5168 },
:comment => { fg: 0xAAAAAA, italic: true },
:string => { fg: 0xAAD94C },
:escape => { fg: 0x7DCFFF },
:interpolation => { fg: 0x7DCFFF },
:regexp => { fg: 0xD2A6FF },
:number => { fg: 0xE6C08A },
# rubocop:disable Lint/BooleanSymbol
:true => { fg: 0x7AE93C },
:false => { fg: 0xEF5168 },
# rubocop:enable Lint/BooleanSymbol
:char => { fg: 0xFFAF70 },
:keyword => { fg: 0xFF8F40 },
:keywordoperator => { fg: 0xF07178 },
:operator => { fg: 0xFFFFFF, italic: true },
:function => { fg: 0xFFAF70 },
:type => { fg: 0xF07178 },
:constant => { fg: 0x7DCFFF },
:variableinstance => { fg: 0x95E6CB },
:variableglobal => { fg: 0xF07178 },
:annotation => { fg: 0x7DCFFF },
:directive => { fg: 0xFF8F40 },
:label => { fg: 0xD2A6FF },
:brace1 => { fg: 0xD2A6FF },
:brace2 => { fg: 0xFFAFAF },
:brace3 => { fg: 0xFFFF00 },
:brace4 => { fg: 0x0FFF0F },
:brace5 => { fg: 0xFF0F0F }
}
# TODO: to be done once a proper api for binding and window drawing is made
# The binds will be connected to either `editor` or windows where editor can
# only use a preset set of stuff to bind while teh windows are purely custom
# # this part uses dsl bindings to define the bind function
# # Hopefully extend to give more context/power to bindings
# # but try to keep simple for performance
# # for default keybindings
# C.bind [:normal, :select], :a => "insert_mode"
# # for custom keybindings
# C.bind :select, [:x, :c] do
# puts "cut"
# end
# C.bind :jumper do
# set [:x, :c] do
# puts "jump to first bookmark"
# end
# end
# # they can also be defined conditionally
# # This code is just an example and doesnt actually work
# if using_tmux?
# bind :C-p do
# system("tmux select-pane -U")
# end
# end
# This can, for example, be modified by user bindings during runtime
# TODO: dynamic registration to actually be implemented once keybinds and extentions are implemented
# A predefined list already exists and can be found in libcrib.rb
# C.lsp_config["solargraph"] = ["stdio"]
#
# C.languages[:ruby] = {
# color: 0xff8087,
# symbol: "󰴭 ",
# extensions: ["rb"],
# filenames: ["Gemfile"],
# lsp: "solargraph"
# }
C.line_endings = :auto_unix # or :unix or :windows or :auto_windows
C.extra_highlights do |_line, _idx|
# the return can be an array of
# [fg, bg. flags, start, end]
# where fg and bg are integers (using 24 bit color)
# and flags is a bitmask of bold/underline/italic etc
# and start and end are integers strictly inside the line
return []
end
# The highlighter will be aplied to the language as long as the langauge is defined in C.languages
C.highlighters[:ruby_n] = {
parser: ->(line, state, line_idx) {
# the return value is a hash
# it contains the state and the highlights
# state can be of any type but will be consistent between calls
# initially nil is sent for uninitialized state the returned must be anything but nil
# the same state can be used for multiple lines
# the highlights can be an array of
# [K_type, start, end]
# K_type is a constant from the constants defined in libcrib.rb
# for ex: for strings it would be Tokens::K_STRING or for numbers Tokens::K_NUMBER etc.
# and start and end are integers strictly inside the line
return {
state: "",
tokens: [
# This will highlight the entire line as a string
# Any wrong format will not be handled and lead to crashes
{ type: Tokens::K_STRING, start: 0, end: line.length }
]
}
},
matcher: ->(state1, state2) {
# returns true if the states are equal
# And so would not need recomputation for further lines
return state1 == state2
}
}

View File

@@ -1,291 +0,0 @@
#ifndef CONFIG_H
#define CONFIG_H
#include "lsp/lsp.h"
#include "pch.h"
static const std::unordered_map<uint8_t, LSP> kLsps = {
{1,
{"clangd",
{
"clangd",
"--background-index",
"--clang-tidy",
"--completion-style=detailed",
"--header-insertion=never",
"--pch-storage=memory",
"--limit-results=50",
"--log=error",
nullptr,
}}},
{2,
{"ruby-lsp",
{
"ruby-lsp",
nullptr,
}}},
{3,
{"solargraph",
{
"solargraph",
"stdio",
nullptr,
}}},
{4,
{"bash-language-server",
{
"bash-language-server",
"start",
nullptr,
}}},
{5,
{"vscode-css-language-server",
{
"vscode-css-language-server",
"--stdio",
nullptr,
}}},
{6,
{"vscode-json-language-server",
{
"vscode-json-language-server",
"--stdio",
nullptr,
}}},
{7,
{"fish-lsp",
{
"fish-lsp",
"start",
nullptr,
}}},
{8,
{"gopls",
{
"gopls",
"serve",
nullptr,
}}},
{9,
{"haskell-language-server",
{
"haskell-language-server",
"lsp",
nullptr,
}}},
{10,
{"emmet-language-server",
{
"emmet-language-server",
"--stdio",
nullptr,
}}},
{11,
{"typescript-language-server",
{
"typescript-language-server",
"--stdio",
nullptr,
}}},
#define LUA_LS 12
{12,
{"lua-language-server",
{
"lua-language-server",
nullptr,
}}},
{13,
{"pyright-langserver",
{
"pyright-langserver",
"--stdio",
nullptr,
}}},
{14,
{"rust-analyzer",
{
"rust-analyzer",
nullptr,
}}},
{15,
{"intelephense",
{
"intelephense",
"--stdio",
nullptr,
}}},
{16,
{"marksman",
{
"marksman",
"server",
nullptr,
}}},
{17,
{"nginx-language-server",
{
"nginx-language-server",
nullptr,
}}},
{18,
{"taplo",
{
"taplo",
"lsp",
"stdio",
nullptr,
}}},
{19,
{"yaml-language-server",
{
"yaml-language-server",
"--stdio",
nullptr,
}}},
{20,
{"sqls",
{
"sqls",
"serve",
nullptr,
}}},
{21,
{"make-language-server",
{
"make-language-server",
nullptr,
}}},
{22,
{"sql-language-server",
{
"sql-language-server",
"up",
"--method",
"stdio",
nullptr,
}}},
};
static const std::unordered_map<std::string, Language> kLanguages = {
{"bash", {"bash", 4, 0x4d5a5e, ""}},
{"c", {"c", 1, 0x555555, ""}},
{"cpp", {"cpp", 1, 0x00599C, ""}},
{"h", {"h", 1, 0xA8B9CC, ""}},
{"css", {"css", 5, 0x36a3d9, ""}},
{"fish", {"fish", 7, 0x4d5a5e, ""}},
{"go", {"go", 8, 0x00add8, ""}},
{"gomod", {"gomod", 8, 0x00add8, ""}},
{"haskell", {"haskell", 9, 0xa074c4, ""}},
{"html", {"html", 10, 0xef8a91, ""}},
{"javascript", {"javascript", 11, 0xf0df8a, ""}},
{"typescript", {"typescript", 11, 0x36a3d9, ""}},
{"json", {"json", 6, 0xcbcb41, "{}"}},
{"jsonc", {"jsonc", 6, 0xcbcb41, "{}"}},
{"erb", {"erb", 10, 0x6e1516, ""}},
{"ruby", {"ruby", 3, 0xff8087, "󰴭 "}},
{"lua", {"lua", 12, 0x36a3d9, "󰢱 "}},
{"python", {"python", 13, 0x95e6cb, "󰌠 "}},
{"rust", {"rust", 14, 0xdea584, "󱘗 "}},
{"php", {"php", 15, 0xa074c4, "󰌟 "}},
{"markdown", {"markdown", 16, 0x36a3d9, ""}},
{"markdown_inline", {"markdown_inline", 16, 0x36a3d9, ""}},
{"nginx", {"nginx", 17, 0x6d8086, ""}},
{"toml", {"toml", 18, 0x36a3d9, ""}},
{"yaml", {"yaml", 19, 0x6d8086, ""}},
{"sql", {"sql", 20, 0xdad8d8, ""}},
{"make", {"make", 21, 0x4e5c61, ""}},
{"gdscript", {"gdscript", 0, 0x6d8086, ""}},
{"man", {"man", 0, 0xdad8d8, ""}},
{"diff", {"diff", 0, 0xDD4C35, ""}},
{"gitattributes", {"gitattributes", 0, 0xF05032, ""}},
{"gitignore", {"gitignore", 0, 0xF05032, ""}},
{"query", {"query", 0, 0x7E57C2, ""}},
{"regex", {"regex", 0, 0x9E9E9E, ".*"}},
{"ini", {"ini", 0, 0x6d8086, ""}},
};
static const std::unordered_map<std::string, std::string> kExtToLang = {
{"sh", "bash"},
{"bash", "bash"},
{"c", "c"},
{"cpp", "cpp"},
{"cxx", "cpp"},
{"cc", "cpp"},
{"hpp", "h"},
{"hh", "h"},
{"hxx", "h"},
{"h", "h"},
{"css", "css"},
{"fish", "fish"},
{"go", "go"},
{"hs", "haskell"},
{"html", "html"},
{"htm", "html"},
{"js", "javascript"},
{"jsx", "javascript"},
{"ts", "typescript"},
{"tsx", "typescript"},
{"json", "json"},
{"jsonc", "jsonc"},
{"lua", "lua"},
{"make", "make"},
{"mk", "make"},
{"makefile", "make"},
{"man", "man"},
{"py", "python"},
{"rb", "ruby"},
{"rs", "rust"},
{"diff", "diff"},
{"patch", "diff"},
{"erb", "erb"},
{"gd", "gdscript"},
{"gitattributes", "gitattributes"},
{"gitignore", "gitignore"},
{"mod", "gomod"},
{"ini", "ini"},
{"gitmodules", "ini"},
{"md", "markdown"},
{"markdown", "markdown"},
{"conf", "nginx"},
{"php", "php"},
{"scm", "query"},
{"regex", "regex"},
{"sql", "sql"},
{"toml", "toml"},
{"yaml", "yaml"},
{"yml", "yaml"},
{"clangd", "yaml"},
};
static const std::unordered_map<std::string, std::string> kMimeToLang = {
{"text/x-c", "c"},
{"text/x-c++", "cpp"},
{"text/x-shellscript", "bash"},
{"application/json", "json"},
{"text/javascript", "javascript"},
{"text/html", "html"},
{"text/css", "css"},
{"text/x-python", "python"},
{"text/x-ruby", "ruby"},
{"text/x-go", "go"},
{"text/x-haskell", "haskell"},
{"text/x-rust", "rust"},
{"text/x-lua", "lua"},
{"text/x-diff", "diff"},
{"text/x-gdscript", "gdscript"},
{"text/x-gitattributes", "gitattributes"},
{"text/x-gitignore", "gitignore"},
{"text/x-gomod", "gomod"},
{"text/x-ini", "ini"},
{"text/markdown", "markdown"},
{"text/x-nginx-conf", "nginx"},
{"application/x-php", "php"},
{"text/x-tree-sitter-query", "query"},
{"text/x-regex", "regex"},
{"text/x-sql", "sql"},
{"text/x-toml", "toml"},
{"text/x-yaml", "yaml"},
{"text/x-man", "man"},
};
#endif

View File

@@ -27,9 +27,10 @@ struct CompletionSession {
bool active = false; bool active = false;
Coord hook; Coord hook;
std::optional<std::string> prefix; std::optional<std::string> prefix;
uint8_t select = 0; uint32_t select = 0;
uint32_t scroll = 0;
std::vector<CompletionItem> items; std::vector<CompletionItem> items;
std::vector<uint8_t> visible; std::vector<uint32_t> visible;
bool complete = true; bool complete = true;
std::optional<char> trigger_char; std::optional<char> trigger_char;
uint8_t trigger = 0; uint8_t trigger = 0;

View File

@@ -5,21 +5,21 @@
#include "editor/indents.h" #include "editor/indents.h"
#include "io/knot.h" #include "io/knot.h"
#include "io/sysio.h" #include "io/sysio.h"
#include "syntax/extras.h"
#include "syntax/parser.h" #include "syntax/parser.h"
#include "ui/completionbox.h" #include "ui/completionbox.h"
#include "ui/diagnostics.h" #include "ui/diagnostics.h"
#include "ui/hover.h" #include "ui/hover.h"
#include "utils/utils.h" #include "utils/utils.h"
#include <cstdint>
#define CHAR 0 #define CHAR 0
#define WORD 1 #define WORD 1
#define LINE 2 #define LINE 2
#define EXTRA_META 4 #define EXTRA_META 2
#define INDENT_WIDTH 2 #define INDENT_WIDTH 2
// autocomplete lua// Bracket closing / tab on enter
struct Editor { struct Editor {
std::string filename; std::string filename;
std::string uri; std::string uri;
@@ -29,6 +29,7 @@ struct Editor {
uint32_t cursor_preffered; uint32_t cursor_preffered;
Coord selection; Coord selection;
bool selection_active; bool selection_active;
bool unix_eol;
int selection_type; int selection_type;
Coord position; Coord position;
Coord size; Coord size;
@@ -50,9 +51,12 @@ struct Editor {
CompletionSession completion; CompletionSession completion;
IndentationEngine indents; IndentationEngine indents;
Parser *parser; Parser *parser;
ExtraHighlighter extra_hl;
bool is_css_color;
}; };
Editor *new_editor(const char *filename_arg, Coord position, Coord size); Editor *new_editor(const char *filename_arg, Coord position, Coord size,
uint8_t eol);
void save_file(Editor *editor); void save_file(Editor *editor);
void free_editor(Editor *editor); void free_editor(Editor *editor);
void render_editor(Editor *editor); void render_editor(Editor *editor);
@@ -73,6 +77,7 @@ void edit_replace(Editor *editor, Coord start, Coord end, const char *text,
uint32_t len); uint32_t len);
Coord editor_hit_test(Editor *editor, uint32_t x, uint32_t y); Coord editor_hit_test(Editor *editor, uint32_t x, uint32_t y);
char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start); char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start);
void selection_bounds(Editor *editor, Coord *out_start, Coord *out_end);
void editor_worker(Editor *editor); void editor_worker(Editor *editor);
void move_line_down(Editor *editor); void move_line_down(Editor *editor);
void move_line_up(Editor *editor); void move_line_up(Editor *editor);
@@ -124,12 +129,12 @@ inline static void utf8_normalize_edit(Editor *editor, TextEdit *edit) {
return; return;
} }
if (edit->start.col < len) if (edit->start.col < len)
edit->start.col = utf16_offset_to_utf8(line, edit->start.col); edit->start.col = utf16_offset_to_utf8(line, len, edit->start.col);
else else
edit->start.col = len; edit->start.col = len;
if (edit->end.row == edit->start.row) { if (edit->end.row == edit->start.row) {
if (edit->end.col < len) if (edit->end.col < len)
edit->end.col = utf16_offset_to_utf8(line, edit->end.col); edit->end.col = utf16_offset_to_utf8(line, len, edit->end.col);
else else
edit->end.col = len; edit->end.col = len;
free(it->buffer); free(it->buffer);
@@ -148,7 +153,7 @@ inline static void utf8_normalize_edit(Editor *editor, TextEdit *edit) {
return; return;
} }
if (edit->end.col < len) if (edit->end.col < len)
edit->end.col = utf16_offset_to_utf8(line, edit->end.col); edit->end.col = utf16_offset_to_utf8(line, len, edit->end.col);
else else
edit->end.col = len; edit->end.col = len;
free(it->buffer); free(it->buffer);

24
include/editor/helpers.h Normal file
View File

@@ -0,0 +1,24 @@
#ifndef EDITOR_HELPERS_H
#define EDITOR_HELPERS_H
#include "editor/editor.h"
void insert_str(Editor *editor, char *c, uint32_t len);
void insert_char(Editor *editor, char c);
void normal_mode(Editor *editor);
void backspace_edit(Editor *editor);
void delete_prev_word(Editor *editor);
void delete_next_word(Editor *editor);
void clear_hooks_at_line(Editor *editor, uint32_t line);
void cursor_prev_word(Editor *editor);
void cursor_next_word(Editor *editor);
void select_all(Editor *editor);
void fetch_lsp_hover(Editor *editor);
void handle_mouse(Editor *editor, KeyEvent event);
void indent_current_line(Editor *editor);
void dedent_current_line(Editor *editor);
void paste(Editor *editor);
void copy(Editor *editor);
void cut(Editor *editor);
#endif

View File

@@ -5,11 +5,6 @@
#include "pch.h" #include "pch.h"
#include "utils/utils.h" #include "utils/utils.h"
struct LSP {
const char *command;
std::vector<const char *> args;
};
struct LSPPending { struct LSPPending {
std::string method; std::string method;
Editor *editor = nullptr; Editor *editor = nullptr;
@@ -37,6 +32,7 @@ struct LSPInstance {
bool allow_resolve = false; bool allow_resolve = false;
bool allow_formatting = false; bool allow_formatting = false;
bool allow_formatting_on_type = false; bool allow_formatting_on_type = false;
bool is_utf8 = false;
std::vector<char> format_chars; std::vector<char> format_chars;
std::vector<char> trigger_chars; std::vector<char> trigger_chars;
std::vector<char> end_chars; std::vector<char> end_chars;
@@ -49,10 +45,12 @@ struct LSPInstance {
}; };
extern std::shared_mutex active_lsps_mtx; extern std::shared_mutex active_lsps_mtx;
extern std::unordered_map<uint8_t, std::shared_ptr<LSPInstance>> active_lsps; extern std::unordered_map<std::string, std::shared_ptr<LSPInstance>>
active_lsps;
extern Queue<LSPOpenRequest> lsp_open_queue; extern Queue<LSPOpenRequest> lsp_open_queue;
static json client_capabilities = { static json client_capabilities = {
{"general", {{"positionEncodings", {"utf-16"}}}},
{"textDocument", {"textDocument",
{{"publishDiagnostics", {{"relatedInformation", true}}}, {{"publishDiagnostics", {{"relatedInformation", true}}},
{"hover", {{"contentFormat", {"markdown", "plaintext"}}}}, {"hover", {{"contentFormat", {"markdown", "plaintext"}}}},
@@ -79,9 +77,10 @@ void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
LSPPending *pending); LSPPending *pending);
void lsp_worker(); void lsp_worker();
std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id); std::shared_ptr<LSPInstance> get_or_init_lsp(std::string lsp_id);
void clean_lsp(std::shared_ptr<LSPInstance> lsp, uint8_t lsp_id); void clean_lsp(std::shared_ptr<LSPInstance> lsp, std::string lsp_id);
void close_lsp(uint8_t lsp_id); void close_lsp(std::string lsp_id);
std::optional<json> read_lsp_message(int fd);
void open_editor(std::shared_ptr<LSPInstance> lsp, void open_editor(std::shared_ptr<LSPInstance> lsp,
std::pair<Language, Editor *> entry); std::pair<Language, Editor *> entry);

View File

@@ -2,6 +2,7 @@
#define MAIN_H #define MAIN_H
#include "pch.h" #include "pch.h"
#include "ui/bar.h"
#define NORMAL 0 #define NORMAL 0
#define INSERT 1 #define INSERT 1
@@ -13,5 +14,6 @@ extern std::atomic<bool> running;
extern std::atomic<uint8_t> mode; extern std::atomic<uint8_t> mode;
extern std::vector<struct Editor *> editors; extern std::vector<struct Editor *> editors;
extern uint8_t current_editor; extern uint8_t current_editor;
extern Bar bar;
#endif #endif

View File

@@ -4,7 +4,12 @@
#define PCRE2_CODE_UNIT_WIDTH 8 #define PCRE2_CODE_UNIT_WIDTH 8
#define PCRE_WORKSPACE_SIZE 512 #define PCRE_WORKSPACE_SIZE 512
#include <magic.h> #include <mruby.h>
#include <mruby/array.h>
#include <mruby/compile.h>
#include <mruby/hash.h>
#include <mruby/irep.h>
#include <mruby/string.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <pcre2.h> #include <pcre2.h>
extern "C" { extern "C" {

45
include/scripting/decl.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef SCRIPTING_DECL_H
#define SCRIPTING_DECL_H
#include "syntax/decl.h"
#include "utils/utils.h"
extern std::unordered_map<std::string, std::pair<mrb_value, mrb_value>>
custom_highlighters;
struct BarLight {
uint32_t start;
uint32_t end;
Highlight highlight;
};
struct BarLine {
std::string line;
std::vector<BarLight> highlights;
Highlight get_highlight(uint32_t x) {
for (auto &hl : highlights) {
if (hl.start <= x && x <= hl.end)
return hl.highlight;
}
return {0xFFFFFF, 0, 0};
}
};
void setup_ruby_bindings(mrb_state *mrb, RClass *C_module);
void ruby_start();
void ruby_shutdown();
void load_theme();
void load_languages_info();
uint8_t read_line_endings();
void load_custom_highlighters();
mrb_value parse_custom(std::vector<Token> *tokens, mrb_value parser_block,
const char *line, uint32_t len, mrb_value state,
uint32_t c_line);
bool custom_compare(mrb_value match_block, mrb_value state1, mrb_value state2);
BarLine bar_contents(uint8_t mode, std::string lang_name, uint32_t warnings,
std::string lsp_name, std::string filename,
std::string foldername, uint32_t line, uint32_t max_line,
uint32_t width);
#endif

View File

@@ -0,0 +1,354 @@
module C
@lsp_config = {
"clangd" => [
"--background-index",
"--clang-tidy",
"--completion-style=detailed",
"--header-insertion=never",
"--pch-storage=memory",
"--limit-results=50",
"--log=error"
],
"ruby-lsp" => [],
"solargraph" => ["stdio"],
"bash-language-server" => ["start"],
"vscode-css-language-server" => ["--stdio"],
"vscode-json-language-server" => ["--stdio"],
"fish-lsp" => ["start"],
"gopls" => ["serve"],
"haskell-language-server" => ["lsp"],
"emmet-language-server" => ["--stdio"],
"typescript-language-server" => ["--stdio"],
"lua-language-server" => [],
"pyright-langserver" => ["--stdio"],
"rust-analyzer" => [],
"intelephense" => ["--stdio"],
"marksman" => ["server"],
"nginx-language-server" => [],
"taplo" => ["lsp", "stdio"],
"yaml-language-server" => ["--stdio"],
"sqls" => ["serve"],
"make-language-server" => [],
"sql-language-server" => ["up", "--method", "stdio"]
}
@languages = {
c: {
color: 0x555555,
symbol: "",
extensions: ["c"],
lsp: "clangd"
},
cpp: {
color: 0x00599C,
symbol: "",
extensions: ["cpp", "cc", "cxx"],
lsp: "clangd"
},
h: {
color: 0xA8B9CC,
symbol: "",
extensions: ["h", "hpp"],
lsp: "clangd"
},
css: {
color: 0x36a3d9,
symbol: "",
extensions: ["css"],
lsp: "vscode-css-language-server"
},
fish: {
color: 0x4d5a5e,
symbol: "",
extensions: ["fish"],
lsp: "fish-lsp"
},
go: {
color: 0x00add8,
symbol: "",
extensions: ["go"],
lsp: "gopls"
},
gomod: {
color: 0x00add8,
symbol: "",
extensions: ["mod"],
lsp: "gopls"
},
haskell: {
color: 0xa074c4,
symbol: "",
extensions: ["hs", "lhs"],
lsp: "haskell-language-server"
},
html: {
color: 0xef8a91,
symbol: "",
extensions: ["html", "htm"],
lsp: "emmet-language-server"
},
javascript: {
color: 0xf0df8a,
symbol: "",
extensions: ["js"],
lsp: "typescript-language-server"
},
typescript: {
color: 0x36a3d9,
symbol: "",
extensions: ["ts"],
lsp: "typescript-language-server"
},
json: {
color: 0xcbcb41,
symbol: "{}",
extensions: ["json"],
lsp: "vscode-json-language-server"
},
jsonc: {
color: 0xcbcb41,
symbol: "{}",
extensions: ["jsonc"],
lsp: "vscode-json-language-server"
},
erb: {
color: 0x6e1516,
symbol: "",
extensions: ["erb"],
lsp: "ruby-lsp"
},
lua: {
color: 0x36a3d9,
symbol: "󰢱 ",
extensions: ["lua"],
lsp: "lua-language-server"
},
python: {
color: 0x95e6cb,
symbol: "󰌠 ",
extensions: ["py"],
lsp: "pyright"
},
rust: {
color: 0xdea584,
symbol: "󱘗 ",
extensions: ["rs"],
lsp: "rust-analyzer"
},
php: {
color: 0xa074c4,
symbol: "󰌟 ",
extensions: ["php"],
lsp: "intelephense"
},
markdown: {
color: 0x36a3d9,
symbol: "",
extensions: ["md", "markdown"],
lsp: "marksman"
},
nginx: {
color: 0x6d8086,
symbol: "",
extensions: ["conf"],
lsp: "nginx-language-server"
},
toml: {
color: 0x36a3d9,
symbol: "",
extensions: ["toml"],
lsp: "taplo"
},
yaml: {
color: 0x6d8086,
symbol: "",
extensions: ["yml", "yaml"],
lsp: "yaml-language-server"
},
sql: {
color: 0xdad8d8,
symbol: "",
extensions: ["sql"],
lsp: "sqls"
},
make: {
color: 0x4e5c61,
symbol: "",
extensions: ["Makefile", "makefile"],
lsp: "make-language-server"
},
gdscript: {
color: 0x6d8086,
symbol: "",
extensions: ["gd"]
},
man: {
color: 0xdad8d8,
symbol: "",
extensions: ["man"]
},
diff: {
color: 0xDD4C35,
symbol: "",
extensions: ["diff", "patch"]
},
gitattributes: {
color: 0xF05032,
symbol: "",
extensions: ["gitattributes"]
},
gitignore: {
color: 0xF05032,
symbol: "",
extensions: ["gitignore"]
},
regex: {
color: 0x9E9E9E,
symbol: ".*",
extensions: ["regex"]
},
ini: {
color: 0x6d8086,
symbol: "",
extensions: ["ini"]
},
ruby: {
color: 0xff8087,
symbol: "󰴭 ",
extensions: ["rb"],
filenames: ["Gemfile"],
lsp: "solargraph"
},
bash: {
color: 0x4d5a5e,
symbol: "",
extensions: ["sh"],
filenames: ["bash_profile", "bashrc"],
lsp: "bash-language-server"
}
}
@theme = {
:default => { fg: 0xEEEEEE },
:shebang => { fg: 0x7DCFFF },
:error => { fg: 0xEF5168 },
:comment => { fg: 0xAAAAAA, italic: true },
:string => { fg: 0xAAD94C },
:escape => { fg: 0x7DCFFF },
:interpolation => { fg: 0x7DCFFF },
:regexp => { fg: 0xD2A6FF },
:number => { fg: 0xE6C08A },
:true => { fg: 0x7AE93C },
:false => { fg: 0xEF5168 },
:char => { fg: 0xFFAF70 },
:keyword => { fg: 0xFF8F40 },
:keywordoperator => { fg: 0xF07178 },
:operator => { fg: 0xFFFFFF, italic: true },
:function => { fg: 0xFFAF70 },
:type => { fg: 0xF07178 },
:constant => { fg: 0x7DCFFF },
:variableinstance => { fg: 0x95E6CB },
:variableglobal => { fg: 0xF07178 },
:annotation => { fg: 0x7DCFFF },
:directive => { fg: 0xFF8F40 },
:label => { fg: 0xD2A6FF },
:brace1 => { fg: 0xD2A6FF },
:brace2 => { fg: 0xFFAFAF },
:brace3 => { fg: 0xFFFF00 },
:brace4 => { fg: 0x0FFF0F },
:brace5 => { fg: 0xFF0F0F }
}
@line_endings = :auto_unix
@key_handlers = {}
@key_binds = {}
@highlighters = {}
@b_startup = nil
@b_shutdown = nil
@b_bar = lambda do |info|
# mode, lang_name, warnings, lsp_name, filename, foldername, line, max_line, width
# puts info.inspect
mode_color = 0x82AAFF
mode_symbol = " "
case info[:mode]
when :normal
mode_color = 0x82AAFF
mode_symbol = ""
when :insert
mode_color = 0xFF8F40
mode_symbol = "󱓧 "
when :select
mode_color = 0x9ADE7A
mode_symbol = "󱩧 "
when :runner
mode_color = 0xFFD700
mode_symbol = ""
when :jumper
mode_color = 0xF29CC3
mode_symbol = ""
end
lang_info = C.languages[info[:lang_name]]
filename = File.basename(info[:filename])
starting = " #{mode_symbol} #{info[:mode].to_s.upcase}  #{lang_info[:symbol]}#{filename}"
highlights = []
highlights << { fg: 0x0b0e14, bg: mode_color, flags: 1 << 1, start: 0, length: 10 }
highlights << { fg: mode_color, bg: 0x33363c, start: 10, length: 1 }
highlights << { fg: 0x33363c, bg: 0x24272d, start: 11, length: 1 }
highlights << { fg: lang_info[:color], bg: 0x24272d, start: 13, length: 2 }
highlights << { fg: 0xced4df, bg: 0x24272d, start: 15, length: filename.length }
highlights << { fg: 0x24272d, bg: 0x000000, start: 15 + filename.length, length: 1 }
return {
text: starting,
highlights: highlights
}
end
class << self
attr_accessor :theme, :lsp_config, :languages,
:line_endings, :highlighters
attr_reader :b_startup, :b_shutdown, :b_extra_highlights, :b_bar
# def bar=(block)
# @b_bar = block
# end
def startup(&block)
@b_startup = block
end
def shutdown(&block)
@b_shutdown = block
end
def extra_highlights(&block)
@b_extra_highlights = block
end
def bind(modes, keys = nil, action = nil, &block)
modes = [modes] unless modes.is_a?(Array)
if keys.nil?
app = self
dsl = Object.new
dsl.define_singleton_method(:set) do |k, act = nil, &blk|
app.bind(modes, k, act, &blk)
end
dsl.instance_exec(&block) if block_given?
elsif block_given?
keys = [keys] unless keys.is_a?(Array)
modes.each do |mode|
keys.each do |key|
@key_handlers[mode] ||= {}
@key_handlers[mode][key] ||= []
@key_handlers[mode][key] << block
end
end
elsif action.is_a?(String)
keys = [keys] unless keys.is_a?(Array)
modes.each do |mode|
keys.each do |key|
@key_binds[mode] ||= {}
@key_binds[mode][key] ||= []
@key_binds[mode][key] << action
end
end
end
end
end
end

View File

@@ -0,0 +1,611 @@
#pragma once
constexpr unsigned char _tmp___crib_precompiled_mrb[] = {
0x52, 0x49, 0x54, 0x45, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x1c, 0x69,
0x4d, 0x41, 0x54, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x49, 0x52, 0x45, 0x50,
0x00, 0x00, 0x1b, 0x81, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x00, 0x34,
0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
0x11, 0x01, 0x5d, 0x01, 0x00, 0x5e, 0x01, 0x00, 0x11, 0x01, 0x5d, 0x01,
0x01, 0x5e, 0x01, 0x01, 0x38, 0x01, 0x69, 0x00, 0x00, 0x00, 0x02, 0x00,
0x06, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x00, 0x00, 0x01, 0x43, 0x00,
0x00, 0x00, 0x03, 0xfd, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x3c, 0x06, 0x01, 0x1e, 0x01, 0x00, 0x07, 0x01, 0x1e,
0x01, 0x01, 0x08, 0x01, 0x1e, 0x01, 0x02, 0x09, 0x01, 0x1e, 0x01, 0x03,
0x0a, 0x01, 0x1e, 0x01, 0x04, 0x0b, 0x01, 0x1e, 0x01, 0x05, 0x0c, 0x01,
0x1e, 0x01, 0x06, 0x0d, 0x01, 0x1e, 0x01, 0x07, 0x03, 0x01, 0x08, 0x1e,
0x01, 0x08, 0x03, 0x01, 0x09, 0x1e, 0x01, 0x09, 0x03, 0x01, 0x0a, 0x1e,
0x01, 0x0a, 0x03, 0x01, 0x0b, 0x1e, 0x01, 0x0b, 0x03, 0x01, 0x0c, 0x1e,
0x01, 0x0c, 0x03, 0x01, 0x0d, 0x1e, 0x01, 0x0d, 0x03, 0x01, 0x0e, 0x1e,
0x01, 0x0e, 0x03, 0x01, 0x0f, 0x1e, 0x01, 0x0f, 0x03, 0x01, 0x10, 0x1e,
0x01, 0x10, 0x03, 0x01, 0x11, 0x1e, 0x01, 0x11, 0x03, 0x01, 0x12, 0x1e,
0x01, 0x12, 0x03, 0x01, 0x13, 0x1e, 0x01, 0x13, 0x03, 0x01, 0x14, 0x1e,
0x01, 0x14, 0x03, 0x01, 0x15, 0x1e, 0x01, 0x15, 0x03, 0x01, 0x16, 0x1e,
0x01, 0x16, 0x03, 0x01, 0x17, 0x1e, 0x01, 0x17, 0x03, 0x01, 0x18, 0x1e,
0x01, 0x18, 0x03, 0x01, 0x19, 0x1e, 0x01, 0x19, 0x03, 0x01, 0x1a, 0x1e,
0x01, 0x1a, 0x03, 0x01, 0x1b, 0x1e, 0x01, 0x1b, 0x03, 0x01, 0x1c, 0x1e,
0x01, 0x1c, 0x03, 0x01, 0x1d, 0x1e, 0x01, 0x1d, 0x03, 0x01, 0x1e, 0x1e,
0x01, 0x1e, 0x03, 0x01, 0x1f, 0x1e, 0x01, 0x1f, 0x03, 0x01, 0x20, 0x1e,
0x01, 0x20, 0x03, 0x01, 0x21, 0x1e, 0x01, 0x21, 0x03, 0x01, 0x22, 0x1e,
0x01, 0x22, 0x03, 0x01, 0x23, 0x1e, 0x01, 0x23, 0x03, 0x01, 0x24, 0x1e,
0x01, 0x24, 0x03, 0x01, 0x25, 0x1e, 0x01, 0x25, 0x03, 0x01, 0x26, 0x1e,
0x01, 0x26, 0x03, 0x01, 0x27, 0x1e, 0x01, 0x27, 0x03, 0x01, 0x28, 0x1e,
0x01, 0x28, 0x03, 0x01, 0x29, 0x1e, 0x01, 0x29, 0x03, 0x01, 0x2a, 0x1e,
0x01, 0x2a, 0x03, 0x01, 0x2b, 0x1e, 0x01, 0x2b, 0x03, 0x01, 0x2c, 0x1e,
0x01, 0x2c, 0x03, 0x01, 0x2d, 0x1e, 0x01, 0x2d, 0x03, 0x01, 0x2e, 0x1e,
0x01, 0x2e, 0x03, 0x01, 0x2f, 0x1e, 0x01, 0x2f, 0x03, 0x01, 0x30, 0x1e,
0x01, 0x30, 0x03, 0x01, 0x31, 0x1e, 0x01, 0x31, 0x03, 0x01, 0x32, 0x1e,
0x01, 0x32, 0x03, 0x01, 0x33, 0x1e, 0x01, 0x33, 0x03, 0x01, 0x34, 0x1e,
0x01, 0x34, 0x2d, 0x01, 0x35, 0x00, 0x38, 0x01, 0x00, 0x00, 0x00, 0x36,
0x00, 0x06, 0x4b, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x00, 0x00, 0x09, 0x4b,
0x5f, 0x53, 0x48, 0x45, 0x42, 0x41, 0x4e, 0x47, 0x00, 0x00, 0x09, 0x4b,
0x5f, 0x43, 0x4f, 0x4d, 0x4d, 0x45, 0x4e, 0x54, 0x00, 0x00, 0x07, 0x4b,
0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x53,
0x54, 0x52, 0x49, 0x4e, 0x47, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x45, 0x53,
0x43, 0x41, 0x50, 0x45, 0x00, 0x00, 0x0f, 0x4b, 0x5f, 0x49, 0x4e, 0x54,
0x45, 0x52, 0x50, 0x4f, 0x4c, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00,
0x08, 0x4b, 0x5f, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x00, 0x00, 0x08,
0x4b, 0x5f, 0x4e, 0x55, 0x4d, 0x42, 0x45, 0x52, 0x00, 0x00, 0x06, 0x4b,
0x5f, 0x54, 0x52, 0x55, 0x45, 0x00, 0x00, 0x07, 0x4b, 0x5f, 0x46, 0x41,
0x4c, 0x53, 0x45, 0x00, 0x00, 0x06, 0x4b, 0x5f, 0x43, 0x48, 0x41, 0x52,
0x00, 0x00, 0x09, 0x4b, 0x5f, 0x4b, 0x45, 0x59, 0x57, 0x4f, 0x52, 0x44,
0x00, 0x00, 0x11, 0x4b, 0x5f, 0x4b, 0x45, 0x59, 0x57, 0x4f, 0x52, 0x44,
0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x4f, 0x52, 0x00, 0x00, 0x0a, 0x4b,
0x5f, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x4f, 0x52, 0x00, 0x00, 0x0a,
0x4b, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00,
0x06, 0x4b, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x00, 0x00, 0x0a, 0x4b, 0x5f,
0x43, 0x4f, 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x00, 0x00, 0x12, 0x4b,
0x5f, 0x56, 0x41, 0x52, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x49, 0x4e, 0x53,
0x54, 0x41, 0x4e, 0x43, 0x45, 0x00, 0x00, 0x10, 0x4b, 0x5f, 0x56, 0x41,
0x52, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c,
0x00, 0x00, 0x0c, 0x4b, 0x5f, 0x41, 0x4e, 0x4e, 0x4f, 0x54, 0x41, 0x54,
0x49, 0x4f, 0x4e, 0x00, 0x00, 0x0b, 0x4b, 0x5f, 0x44, 0x49, 0x52, 0x45,
0x43, 0x54, 0x49, 0x56, 0x45, 0x00, 0x00, 0x07, 0x4b, 0x5f, 0x4c, 0x41,
0x42, 0x45, 0x4c, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43,
0x45, 0x31, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45,
0x32, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x33,
0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x34, 0x00,
0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x35, 0x00, 0x00,
0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47, 0x31, 0x00,
0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47, 0x32,
0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47,
0x33, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e,
0x47, 0x34, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49,
0x4e, 0x47, 0x35, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44,
0x49, 0x4e, 0x47, 0x36, 0x00, 0x00, 0x0c, 0x4b, 0x5f, 0x42, 0x4c, 0x4f,
0x43, 0x4b, 0x51, 0x55, 0x4f, 0x54, 0x45, 0x00, 0x00, 0x06, 0x4b, 0x5f,
0x4c, 0x49, 0x53, 0x54, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x4c, 0x49, 0x53,
0x54, 0x49, 0x54, 0x45, 0x4d, 0x00, 0x00, 0x06, 0x4b, 0x5f, 0x43, 0x4f,
0x44, 0x45, 0x00, 0x00, 0x0e, 0x4b, 0x5f, 0x4c, 0x41, 0x4e, 0x47, 0x55,
0x41, 0x47, 0x45, 0x4e, 0x41, 0x4d, 0x45, 0x00, 0x00, 0x0b, 0x4b, 0x5f,
0x4c, 0x49, 0x4e, 0x4b, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x00, 0x00, 0x0c,
0x4b, 0x5f, 0x49, 0x4d, 0x41, 0x47, 0x45, 0x4c, 0x41, 0x42, 0x45, 0x4c,
0x00, 0x00, 0x06, 0x4b, 0x5f, 0x4c, 0x49, 0x4e, 0x4b, 0x00, 0x00, 0x07,
0x4b, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x00, 0x00, 0x0d, 0x4b, 0x5f,
0x54, 0x41, 0x42, 0x4c, 0x45, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x00,
0x00, 0x08, 0x4b, 0x5f, 0x49, 0x54, 0x41, 0x4c, 0x49, 0x43, 0x00, 0x00,
0x06, 0x4b, 0x5f, 0x42, 0x4f, 0x4c, 0x44, 0x00, 0x00, 0x0b, 0x4b, 0x5f,
0x55, 0x4e, 0x44, 0x45, 0x52, 0x4c, 0x49, 0x4e, 0x45, 0x00, 0x00, 0x0f,
0x4b, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x4b, 0x45, 0x54, 0x48, 0x52, 0x4f,
0x55, 0x47, 0x48, 0x00, 0x00, 0x10, 0x4b, 0x5f, 0x48, 0x4f, 0x52, 0x49,
0x58, 0x4f, 0x4e, 0x54, 0x41, 0x4c, 0x52, 0x55, 0x4c, 0x45, 0x00, 0x00,
0x05, 0x4b, 0x5f, 0x54, 0x41, 0x47, 0x00, 0x00, 0x0b, 0x4b, 0x5f, 0x41,
0x54, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x45, 0x00, 0x00, 0x0b, 0x4b,
0x5f, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x44, 0x4f, 0x4e, 0x45, 0x00, 0x00,
0x0e, 0x4b, 0x5f, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x4e, 0x4f, 0x54, 0x44,
0x4f, 0x4e, 0x45, 0x00, 0x00, 0x06, 0x66, 0x72, 0x65, 0x65, 0x7a, 0x65,
0x00, 0x00, 0x00, 0x0f, 0x61, 0x00, 0x01, 0x00, 0x4c, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x07, 0x6f, 0x51, 0x01, 0x00, 0x51, 0x02, 0x01, 0x51,
0x03, 0x02, 0x51, 0x04, 0x03, 0x51, 0x05, 0x04, 0x51, 0x06, 0x05, 0x51,
0x07, 0x06, 0x51, 0x08, 0x07, 0x47, 0x02, 0x07, 0x51, 0x03, 0x08, 0x47,
0x04, 0x00, 0x51, 0x05, 0x09, 0x51, 0x06, 0x0a, 0x47, 0x06, 0x01, 0x51,
0x07, 0x0b, 0x51, 0x08, 0x0c, 0x47, 0x08, 0x01, 0x51, 0x09, 0x0d, 0x51,
0x0a, 0x0e, 0x47, 0x0a, 0x01, 0x51, 0x0b, 0x0f, 0x51, 0x0c, 0x0e, 0x47,
0x0c, 0x01, 0x51, 0x0d, 0x10, 0x51, 0x0e, 0x0c, 0x47, 0x0e, 0x01, 0x51,
0x0f, 0x11, 0x51, 0x10, 0x12, 0x47, 0x10, 0x01, 0x51, 0x11, 0x13, 0x51,
0x12, 0x14, 0x47, 0x12, 0x01, 0x51, 0x13, 0x15, 0x51, 0x14, 0x0e, 0x47,
0x14, 0x01, 0x51, 0x15, 0x16, 0x51, 0x16, 0x0e, 0x47, 0x16, 0x01, 0x51,
0x17, 0x17, 0x47, 0x18, 0x00, 0x51, 0x19, 0x18, 0x51, 0x1a, 0x0e, 0x47,
0x1a, 0x01, 0x51, 0x1b, 0x19, 0x47, 0x1c, 0x00, 0x51, 0x1d, 0x1a, 0x51,
0x1e, 0x0e, 0x47, 0x1e, 0x01, 0x51, 0x1f, 0x1b, 0x51, 0x20, 0x1c, 0x47,
0x20, 0x01, 0x51, 0x21, 0x1d, 0x47, 0x22, 0x00, 0x51, 0x23, 0x1e, 0x51,
0x24, 0x14, 0x51, 0x25, 0x0a, 0x47, 0x24, 0x02, 0x51, 0x25, 0x1f, 0x51,
0x26, 0x0e, 0x47, 0x26, 0x01, 0x51, 0x27, 0x20, 0x51, 0x28, 0x12, 0x47,
0x28, 0x01, 0x51, 0x29, 0x21, 0x47, 0x2a, 0x00, 0x51, 0x2b, 0x22, 0x51,
0x2c, 0x23, 0x51, 0x2d, 0x24, 0x51, 0x2e, 0x0a, 0x47, 0x2c, 0x03, 0x53,
0x01, 0x16, 0x1a, 0x01, 0x00, 0x10, 0x01, 0x01, 0x10, 0x02, 0x02, 0x0f,
0x03, 0x00, 0x55, 0x55, 0x55, 0x10, 0x04, 0x03, 0x51, 0x05, 0x25, 0x10,
0x06, 0x04, 0x51, 0x07, 0x26, 0x47, 0x07, 0x01, 0x10, 0x08, 0x05, 0x51,
0x09, 0x00, 0x53, 0x02, 0x04, 0x10, 0x03, 0x06, 0x10, 0x04, 0x02, 0x0e,
0x05, 0x59, 0x9c, 0x10, 0x06, 0x03, 0x51, 0x07, 0x27, 0x10, 0x08, 0x04,
0x51, 0x09, 0x28, 0x51, 0x0a, 0x29, 0x51, 0x0b, 0x2a, 0x47, 0x09, 0x03,
0x10, 0x0a, 0x05, 0x51, 0x0b, 0x00, 0x53, 0x04, 0x04, 0x10, 0x05, 0x07,
0x10, 0x06, 0x02, 0x0f, 0x07, 0x00, 0xa8, 0xb9, 0xcc, 0x10, 0x08, 0x03,
0x51, 0x09, 0x2b, 0x10, 0x0a, 0x04, 0x51, 0x0b, 0x2c, 0x51, 0x0c, 0x2d,
0x47, 0x0b, 0x02, 0x10, 0x0c, 0x05, 0x51, 0x0d, 0x00, 0x53, 0x06, 0x04,
0x10, 0x07, 0x08, 0x10, 0x08, 0x02, 0x0f, 0x09, 0x00, 0x36, 0xa3, 0xd9,
0x10, 0x0a, 0x03, 0x51, 0x0b, 0x2e, 0x10, 0x0c, 0x04, 0x51, 0x0d, 0x2f,
0x47, 0x0d, 0x01, 0x10, 0x0e, 0x05, 0x51, 0x0f, 0x0d, 0x53, 0x08, 0x04,
0x10, 0x09, 0x09, 0x10, 0x0a, 0x02, 0x0f, 0x0b, 0x00, 0x4d, 0x5a, 0x5e,
0x10, 0x0c, 0x03, 0x51, 0x0d, 0x30, 0x10, 0x0e, 0x04, 0x51, 0x0f, 0x31,
0x47, 0x0f, 0x01, 0x10, 0x10, 0x05, 0x51, 0x11, 0x10, 0x53, 0x0a, 0x04,
0x10, 0x0b, 0x0a, 0x10, 0x0c, 0x02, 0x0f, 0x0d, 0x00, 0x00, 0xad, 0xd8,
0x10, 0x0e, 0x03, 0x51, 0x0f, 0x32, 0x10, 0x10, 0x04, 0x51, 0x11, 0x33,
0x47, 0x11, 0x01, 0x10, 0x12, 0x05, 0x51, 0x13, 0x11, 0x53, 0x0c, 0x04,
0x10, 0x0d, 0x0b, 0x10, 0x0e, 0x02, 0x0f, 0x0f, 0x00, 0x00, 0xad, 0xd8,
0x10, 0x10, 0x03, 0x51, 0x11, 0x32, 0x10, 0x12, 0x04, 0x51, 0x13, 0x34,
0x47, 0x13, 0x01, 0x10, 0x14, 0x05, 0x51, 0x15, 0x11, 0x53, 0x0e, 0x04,
0x10, 0x0f, 0x0c, 0x10, 0x10, 0x02, 0x0f, 0x11, 0x00, 0xa0, 0x74, 0xc4,
0x10, 0x12, 0x03, 0x51, 0x13, 0x35, 0x10, 0x14, 0x04, 0x51, 0x15, 0x36,
0x51, 0x16, 0x37, 0x47, 0x15, 0x02, 0x10, 0x16, 0x05, 0x51, 0x17, 0x13,
0x53, 0x10, 0x04, 0x10, 0x11, 0x0d, 0x10, 0x12, 0x02, 0x0f, 0x13, 0x00,
0xef, 0x8a, 0x91, 0x10, 0x14, 0x03, 0x51, 0x15, 0x38, 0x10, 0x16, 0x04,
0x51, 0x17, 0x39, 0x51, 0x18, 0x3a, 0x47, 0x17, 0x02, 0x10, 0x18, 0x05,
0x51, 0x19, 0x15, 0x53, 0x12, 0x04, 0x10, 0x13, 0x0e, 0x10, 0x14, 0x02,
0x0f, 0x15, 0x00, 0xf0, 0xdf, 0x8a, 0x10, 0x16, 0x03, 0x51, 0x17, 0x3b,
0x10, 0x18, 0x04, 0x51, 0x19, 0x3c, 0x47, 0x19, 0x01, 0x10, 0x1a, 0x05,
0x51, 0x1b, 0x16, 0x53, 0x14, 0x04, 0x10, 0x15, 0x0f, 0x10, 0x16, 0x02,
0x0f, 0x17, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x18, 0x03, 0x51, 0x19, 0x3d,
0x10, 0x1a, 0x04, 0x51, 0x1b, 0x3e, 0x47, 0x1b, 0x01, 0x10, 0x1c, 0x05,
0x51, 0x1d, 0x16, 0x53, 0x16, 0x04, 0x10, 0x17, 0x10, 0x10, 0x18, 0x02,
0x0f, 0x19, 0x00, 0xcb, 0xcb, 0x41, 0x10, 0x1a, 0x03, 0x51, 0x1b, 0x3f,
0x10, 0x1c, 0x04, 0x51, 0x1d, 0x40, 0x47, 0x1d, 0x01, 0x10, 0x1e, 0x05,
0x51, 0x1f, 0x0f, 0x53, 0x18, 0x04, 0x10, 0x19, 0x11, 0x10, 0x1a, 0x02,
0x0f, 0x1b, 0x00, 0xcb, 0xcb, 0x41, 0x10, 0x1c, 0x03, 0x51, 0x1d, 0x3f,
0x10, 0x1e, 0x04, 0x51, 0x1f, 0x41, 0x47, 0x1f, 0x01, 0x10, 0x20, 0x05,
0x51, 0x21, 0x0f, 0x53, 0x1a, 0x04, 0x10, 0x1b, 0x12, 0x10, 0x1c, 0x02,
0x0f, 0x1d, 0x00, 0x6e, 0x15, 0x16, 0x10, 0x1e, 0x03, 0x51, 0x1f, 0x38,
0x10, 0x20, 0x04, 0x51, 0x21, 0x42, 0x47, 0x21, 0x01, 0x10, 0x22, 0x05,
0x51, 0x23, 0x08, 0x53, 0x1c, 0x04, 0x10, 0x1d, 0x13, 0x10, 0x1e, 0x02,
0x0f, 0x1f, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x20, 0x03, 0x51, 0x21, 0x43,
0x10, 0x22, 0x04, 0x51, 0x23, 0x44, 0x47, 0x23, 0x01, 0x10, 0x24, 0x05,
0x51, 0x25, 0x17, 0x53, 0x1e, 0x04, 0x10, 0x1f, 0x14, 0x10, 0x20, 0x02,
0x0f, 0x21, 0x00, 0x95, 0xe6, 0xcb, 0x10, 0x22, 0x03, 0x51, 0x23, 0x45,
0x10, 0x24, 0x04, 0x51, 0x25, 0x46, 0x47, 0x25, 0x01, 0x10, 0x26, 0x05,
0x51, 0x27, 0x47, 0x53, 0x20, 0x04, 0x10, 0x21, 0x15, 0x10, 0x22, 0x02,
0x0f, 0x23, 0x00, 0xde, 0xa5, 0x84, 0x10, 0x24, 0x03, 0x51, 0x25, 0x48,
0x10, 0x26, 0x04, 0x51, 0x27, 0x49, 0x47, 0x27, 0x01, 0x10, 0x28, 0x05,
0x51, 0x29, 0x19, 0x53, 0x22, 0x04, 0x10, 0x23, 0x16, 0x10, 0x24, 0x02,
0x0f, 0x25, 0x00, 0xa0, 0x74, 0xc4, 0x10, 0x26, 0x03, 0x51, 0x27, 0x4a,
0x10, 0x28, 0x04, 0x51, 0x29, 0x4b, 0x47, 0x29, 0x01, 0x10, 0x2a, 0x05,
0x51, 0x2b, 0x1a, 0x53, 0x24, 0x04, 0x10, 0x25, 0x17, 0x10, 0x26, 0x02,
0x0f, 0x27, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x28, 0x03, 0x51, 0x29, 0x4c,
0x10, 0x2a, 0x04, 0x51, 0x2b, 0x4d, 0x51, 0x2c, 0x4e, 0x47, 0x2b, 0x02,
0x10, 0x2c, 0x05, 0x51, 0x2d, 0x1b, 0x53, 0x26, 0x04, 0x10, 0x27, 0x18,
0x10, 0x28, 0x02, 0x0f, 0x29, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x2a, 0x03,
0x51, 0x2b, 0x4f, 0x10, 0x2c, 0x04, 0x51, 0x2d, 0x50, 0x47, 0x2d, 0x01,
0x10, 0x2e, 0x05, 0x51, 0x2f, 0x1d, 0x53, 0x28, 0x04, 0x10, 0x29, 0x19,
0x10, 0x2a, 0x02, 0x0f, 0x2b, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x2c, 0x03,
0x51, 0x2d, 0x51, 0x10, 0x2e, 0x04, 0x51, 0x2f, 0x52, 0x47, 0x2f, 0x01,
0x10, 0x30, 0x05, 0x51, 0x31, 0x1e, 0x53, 0x2a, 0x04, 0x10, 0x2b, 0x1a,
0x10, 0x2c, 0x02, 0x0f, 0x2d, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x2e, 0x03,
0x51, 0x2f, 0x4f, 0x10, 0x30, 0x04, 0x51, 0x31, 0x53, 0x51, 0x32, 0x54,
0x47, 0x31, 0x02, 0x10, 0x32, 0x05, 0x51, 0x33, 0x1f, 0x53, 0x2c, 0x04,
0x10, 0x2d, 0x1b, 0x10, 0x2e, 0x02, 0x0f, 0x2f, 0x00, 0xda, 0xd8, 0xd8,
0x10, 0x30, 0x03, 0x51, 0x31, 0x55, 0x10, 0x32, 0x04, 0x51, 0x33, 0x56,
0x47, 0x33, 0x01, 0x10, 0x34, 0x05, 0x51, 0x35, 0x20, 0x53, 0x2e, 0x04,
0x10, 0x2f, 0x1c, 0x10, 0x30, 0x02, 0x0f, 0x31, 0x00, 0x4e, 0x5c, 0x61,
0x10, 0x32, 0x03, 0x51, 0x33, 0x57, 0x10, 0x34, 0x04, 0x51, 0x35, 0x58,
0x51, 0x36, 0x59, 0x47, 0x35, 0x02, 0x10, 0x36, 0x05, 0x51, 0x37, 0x21,
0x53, 0x30, 0x04, 0x10, 0x31, 0x1d, 0x10, 0x32, 0x02, 0x0f, 0x33, 0x00,
0x6d, 0x80, 0x86, 0x10, 0x34, 0x03, 0x51, 0x35, 0x5a, 0x10, 0x36, 0x04,
0x51, 0x37, 0x5b, 0x47, 0x37, 0x01, 0x53, 0x32, 0x03, 0x10, 0x33, 0x1e,
0x10, 0x34, 0x02, 0x0f, 0x35, 0x00, 0xda, 0xd8, 0xd8, 0x10, 0x36, 0x03,
0x51, 0x37, 0x5c, 0x10, 0x38, 0x04, 0x51, 0x39, 0x5d, 0x47, 0x39, 0x01,
0x53, 0x34, 0x03, 0x10, 0x35, 0x1f, 0x10, 0x36, 0x02, 0x0f, 0x37, 0x00,
0xdd, 0x4c, 0x35, 0x10, 0x38, 0x03, 0x51, 0x39, 0x5e, 0x10, 0x3a, 0x04,
0x51, 0x3b, 0x5f, 0x51, 0x3c, 0x60, 0x47, 0x3b, 0x02, 0x53, 0x36, 0x03,
0x10, 0x37, 0x20, 0x10, 0x38, 0x02, 0x0f, 0x39, 0x00, 0xf0, 0x50, 0x32,
0x10, 0x3a, 0x03, 0x51, 0x3b, 0x61, 0x10, 0x3c, 0x04, 0x51, 0x3d, 0x62,
0x47, 0x3d, 0x01, 0x53, 0x38, 0x03, 0x10, 0x39, 0x21, 0x10, 0x3a, 0x02,
0x0f, 0x3b, 0x00, 0xf0, 0x50, 0x32, 0x10, 0x3c, 0x03, 0x51, 0x3d, 0x61,
0x10, 0x3e, 0x04, 0x51, 0x3f, 0x63, 0x47, 0x3f, 0x01, 0x53, 0x3a, 0x03,
0x10, 0x3b, 0x22, 0x10, 0x3c, 0x02, 0x0f, 0x3d, 0x00, 0x9e, 0x9e, 0x9e,
0x10, 0x3e, 0x03, 0x51, 0x3f, 0x64, 0x10, 0x40, 0x04, 0x51, 0x41, 0x65,
0x47, 0x41, 0x01, 0x53, 0x3c, 0x03, 0x10, 0x3d, 0x23, 0x10, 0x3e, 0x02,
0x0f, 0x3f, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x40, 0x03, 0x51, 0x41, 0x4f,
0x10, 0x42, 0x04, 0x51, 0x43, 0x66, 0x47, 0x43, 0x01, 0x53, 0x3e, 0x03,
0x10, 0x3f, 0x24, 0x10, 0x40, 0x02, 0x0f, 0x41, 0x00, 0xff, 0x80, 0x87,
0x10, 0x42, 0x03, 0x51, 0x43, 0x67, 0x10, 0x44, 0x04, 0x51, 0x45, 0x68,
0x47, 0x45, 0x01, 0x10, 0x46, 0x25, 0x51, 0x47, 0x69, 0x47, 0x47, 0x01,
0x10, 0x48, 0x05, 0x51, 0x49, 0x09, 0x53, 0x40, 0x05, 0x10, 0x41, 0x26,
0x10, 0x42, 0x02, 0x0f, 0x43, 0x00, 0x4d, 0x5a, 0x5e, 0x10, 0x44, 0x03,
0x51, 0x45, 0x6a, 0x10, 0x46, 0x04, 0x51, 0x47, 0x6b, 0x47, 0x47, 0x01,
0x10, 0x48, 0x25, 0x51, 0x49, 0x6c, 0x51, 0x4a, 0x6d, 0x47, 0x49, 0x02,
0x10, 0x4a, 0x05, 0x51, 0x4b, 0x0b, 0x53, 0x42, 0x05, 0x53, 0x01, 0x21,
0x1a, 0x01, 0x27, 0x10, 0x01, 0x28, 0x10, 0x02, 0x29, 0x0f, 0x03, 0x00,
0xee, 0xee, 0xee, 0x53, 0x02, 0x01, 0x10, 0x03, 0x2a, 0x10, 0x04, 0x29,
0x0f, 0x05, 0x00, 0x7d, 0xcf, 0xff, 0x53, 0x04, 0x01, 0x10, 0x05, 0x2b,
0x10, 0x06, 0x29, 0x0f, 0x07, 0x00, 0xef, 0x51, 0x68, 0x53, 0x06, 0x01,
0x10, 0x07, 0x2c, 0x10, 0x08, 0x29, 0x0f, 0x09, 0x00, 0xaa, 0xaa, 0xaa,
0x10, 0x0a, 0x2d, 0x13, 0x0b, 0x53, 0x08, 0x02, 0x10, 0x09, 0x2e, 0x10,
0x0a, 0x29, 0x0f, 0x0b, 0x00, 0xaa, 0xd9, 0x4c, 0x53, 0x0a, 0x01, 0x10,
0x0b, 0x2f, 0x10, 0x0c, 0x29, 0x0f, 0x0d, 0x00, 0x7d, 0xcf, 0xff, 0x53,
0x0c, 0x01, 0x10, 0x0d, 0x30, 0x10, 0x0e, 0x29, 0x0f, 0x0f, 0x00, 0x7d,
0xcf, 0xff, 0x53, 0x0e, 0x01, 0x10, 0x0f, 0x31, 0x10, 0x10, 0x29, 0x0f,
0x11, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x10, 0x01, 0x10, 0x11, 0x32, 0x10,
0x12, 0x29, 0x0f, 0x13, 0x00, 0xe6, 0xc0, 0x8a, 0x53, 0x12, 0x01, 0x10,
0x13, 0x33, 0x10, 0x14, 0x29, 0x0f, 0x15, 0x00, 0x7a, 0xe9, 0x3c, 0x53,
0x14, 0x01, 0x10, 0x15, 0x34, 0x10, 0x16, 0x29, 0x0f, 0x17, 0x00, 0xef,
0x51, 0x68, 0x53, 0x16, 0x01, 0x10, 0x17, 0x35, 0x10, 0x18, 0x29, 0x0f,
0x19, 0x00, 0xff, 0xaf, 0x70, 0x53, 0x18, 0x01, 0x10, 0x19, 0x36, 0x10,
0x1a, 0x29, 0x0f, 0x1b, 0x00, 0xff, 0x8f, 0x40, 0x53, 0x1a, 0x01, 0x10,
0x1b, 0x37, 0x10, 0x1c, 0x29, 0x0f, 0x1d, 0x00, 0xf0, 0x71, 0x78, 0x53,
0x1c, 0x01, 0x10, 0x1d, 0x38, 0x10, 0x1e, 0x29, 0x0f, 0x1f, 0x00, 0xff,
0xff, 0xff, 0x10, 0x20, 0x2d, 0x13, 0x21, 0x53, 0x1e, 0x02, 0x10, 0x1f,
0x39, 0x10, 0x20, 0x29, 0x0f, 0x21, 0x00, 0xff, 0xaf, 0x70, 0x53, 0x20,
0x01, 0x10, 0x21, 0x3a, 0x10, 0x22, 0x29, 0x0f, 0x23, 0x00, 0xf0, 0x71,
0x78, 0x53, 0x22, 0x01, 0x10, 0x23, 0x3b, 0x10, 0x24, 0x29, 0x0f, 0x25,
0x00, 0x7d, 0xcf, 0xff, 0x53, 0x24, 0x01, 0x10, 0x25, 0x3c, 0x10, 0x26,
0x29, 0x0f, 0x27, 0x00, 0x95, 0xe6, 0xcb, 0x53, 0x26, 0x01, 0x10, 0x27,
0x3d, 0x10, 0x28, 0x29, 0x0f, 0x29, 0x00, 0xf0, 0x71, 0x78, 0x53, 0x28,
0x01, 0x10, 0x29, 0x3e, 0x10, 0x2a, 0x29, 0x0f, 0x2b, 0x00, 0x7d, 0xcf,
0xff, 0x53, 0x2a, 0x01, 0x10, 0x2b, 0x3f, 0x10, 0x2c, 0x29, 0x0f, 0x2d,
0x00, 0xff, 0x8f, 0x40, 0x53, 0x2c, 0x01, 0x10, 0x2d, 0x40, 0x10, 0x2e,
0x29, 0x0f, 0x2f, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x2e, 0x01, 0x10, 0x2f,
0x41, 0x10, 0x30, 0x29, 0x0f, 0x31, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x30,
0x01, 0x10, 0x31, 0x42, 0x10, 0x32, 0x29, 0x0f, 0x33, 0x00, 0xff, 0xaf,
0xaf, 0x53, 0x32, 0x01, 0x10, 0x33, 0x43, 0x10, 0x34, 0x29, 0x0f, 0x35,
0x00, 0xff, 0xff, 0x00, 0x53, 0x34, 0x01, 0x10, 0x35, 0x44, 0x10, 0x36,
0x29, 0x0f, 0x37, 0x00, 0x0f, 0xff, 0x0f, 0x53, 0x36, 0x01, 0x10, 0x37,
0x45, 0x10, 0x38, 0x29, 0x0f, 0x39, 0x00, 0xff, 0x0f, 0x0f, 0x53, 0x38,
0x01, 0x53, 0x01, 0x1c, 0x1a, 0x01, 0x46, 0x10, 0x01, 0x47, 0x1a, 0x01,
0x48, 0x53, 0x01, 0x00, 0x1a, 0x01, 0x49, 0x53, 0x01, 0x00, 0x1a, 0x01,
0x4a, 0x53, 0x01, 0x00, 0x1a, 0x01, 0x4b, 0x11, 0x01, 0x1a, 0x01, 0x4c,
0x11, 0x01, 0x1a, 0x01, 0x4d, 0x57, 0x02, 0x00, 0x2e, 0x01, 0x4e, 0x00,
0x1a, 0x01, 0x4f, 0x12, 0x01, 0x62, 0x01, 0x5e, 0x01, 0x01, 0x38, 0x01,
0x00, 0x6e, 0x00, 0x00, 0x06, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x64, 0x00,
0x00, 0x00, 0x12, 0x2d, 0x2d, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f,
0x75, 0x6e, 0x64, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x00, 0x00, 0x00,
0x0c, 0x2d, 0x2d, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64,
0x79, 0x00, 0x00, 0x00, 0x1b, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x6c,
0x65, 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d,
0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x00, 0x00, 0x00, 0x18,
0x2d, 0x2d, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x2d, 0x69, 0x6e, 0x73,
0x65, 0x72, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x6e, 0x65, 0x76, 0x65, 0x72,
0x00, 0x00, 0x00, 0x14, 0x2d, 0x2d, 0x70, 0x63, 0x68, 0x2d, 0x73, 0x74,
0x6f, 0x72, 0x61, 0x67, 0x65, 0x3d, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79,
0x00, 0x00, 0x00, 0x12, 0x2d, 0x2d, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x2d,
0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x3d, 0x35, 0x30, 0x00, 0x00,
0x00, 0x0b, 0x2d, 0x2d, 0x6c, 0x6f, 0x67, 0x3d, 0x65, 0x72, 0x72, 0x6f,
0x72, 0x00, 0x00, 0x00, 0x08, 0x72, 0x75, 0x62, 0x79, 0x2d, 0x6c, 0x73,
0x70, 0x00, 0x00, 0x00, 0x0a, 0x73, 0x6f, 0x6c, 0x61, 0x72, 0x67, 0x72,
0x61, 0x70, 0x68, 0x00, 0x00, 0x00, 0x05, 0x73, 0x74, 0x64, 0x69, 0x6f,
0x00, 0x00, 0x00, 0x14, 0x62, 0x61, 0x73, 0x68, 0x2d, 0x6c, 0x61, 0x6e,
0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
0x00, 0x00, 0x00, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00, 0x00,
0x1a, 0x76, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x63, 0x73, 0x73, 0x2d,
0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72,
0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x07, 0x2d, 0x2d, 0x73, 0x74, 0x64,
0x69, 0x6f, 0x00, 0x00, 0x00, 0x1b, 0x76, 0x73, 0x63, 0x6f, 0x64, 0x65,
0x2d, 0x6a, 0x73, 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61,
0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00,
0x08, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x6c, 0x73, 0x70, 0x00, 0x00, 0x00,
0x05, 0x67, 0x6f, 0x70, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x05, 0x73, 0x65,
0x72, 0x76, 0x65, 0x00, 0x00, 0x00, 0x17, 0x68, 0x61, 0x73, 0x6b, 0x65,
0x6c, 0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d,
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x03, 0x6c, 0x73,
0x70, 0x00, 0x00, 0x00, 0x15, 0x65, 0x6d, 0x6d, 0x65, 0x74, 0x2d, 0x6c,
0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76,
0x65, 0x72, 0x00, 0x00, 0x00, 0x1a, 0x74, 0x79, 0x70, 0x65, 0x73, 0x63,
0x72, 0x69, 0x70, 0x74, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67,
0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x13,
0x6c, 0x75, 0x61, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65,
0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x12, 0x70,
0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x73,
0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x0d, 0x72, 0x75, 0x73,
0x74, 0x2d, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x72, 0x00, 0x00,
0x00, 0x0c, 0x69, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x65, 0x6e,
0x73, 0x65, 0x00, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x6d,
0x61, 0x6e, 0x00, 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
0x00, 0x00, 0x00, 0x15, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2d, 0x6c, 0x61,
0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65,
0x72, 0x00, 0x00, 0x00, 0x05, 0x74, 0x61, 0x70, 0x6c, 0x6f, 0x00, 0x00,
0x00, 0x14, 0x79, 0x61, 0x6d, 0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75,
0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00,
0x00, 0x04, 0x73, 0x71, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x14, 0x6d, 0x61,
0x6b, 0x65, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d,
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x13, 0x73, 0x71,
0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73,
0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x02, 0x75, 0x70, 0x00,
0x00, 0x00, 0x08, 0x2d, 0x2d, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x00,
0x00, 0x00, 0x04, 0xee, 0x98, 0x9e, 0x20, 0x00, 0x00, 0x00, 0x01, 0x63,
0x00, 0x00, 0x00, 0x04, 0xee, 0x98, 0x9d, 0x20, 0x00, 0x00, 0x00, 0x03,
0x63, 0x70, 0x70, 0x00, 0x00, 0x00, 0x02, 0x63, 0x63, 0x00, 0x00, 0x00,
0x03, 0x63, 0x78, 0x78, 0x00, 0x00, 0x00, 0x04, 0xef, 0x83, 0xbd, 0x20,
0x00, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x00, 0x03, 0x68, 0x70, 0x70,
0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0xb8, 0x20, 0x00, 0x00, 0x00, 0x03,
0x63, 0x73, 0x73, 0x00, 0x00, 0x00, 0x04, 0xee, 0xb9, 0x81, 0x20, 0x00,
0x00, 0x00, 0x04, 0x66, 0x69, 0x73, 0x68, 0x00, 0x00, 0x00, 0x04, 0xee,
0x98, 0xa7, 0x20, 0x00, 0x00, 0x00, 0x02, 0x67, 0x6f, 0x00, 0x00, 0x00,
0x03, 0x6d, 0x6f, 0x64, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9d, 0xb7, 0x20,
0x00, 0x00, 0x00, 0x02, 0x68, 0x73, 0x00, 0x00, 0x00, 0x03, 0x6c, 0x68,
0x73, 0x00, 0x00, 0x00, 0x04, 0xef, 0x84, 0xa1, 0x20, 0x00, 0x00, 0x00,
0x04, 0x68, 0x74, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x68, 0x74, 0x6d,
0x00, 0x00, 0x00, 0x04, 0xef, 0x8b, 0xaf, 0x20, 0x00, 0x00, 0x00, 0x02,
0x6a, 0x73, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0x9d, 0x20, 0x00, 0x00,
0x00, 0x02, 0x74, 0x73, 0x00, 0x00, 0x00, 0x02, 0x7b, 0x7d, 0x00, 0x00,
0x00, 0x04, 0x6a, 0x73, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, 0x6a, 0x73,
0x6f, 0x6e, 0x63, 0x00, 0x00, 0x00, 0x03, 0x65, 0x72, 0x62, 0x00, 0x00,
0x00, 0x05, 0xf3, 0xb0, 0xa2, 0xb1, 0x20, 0x00, 0x00, 0x00, 0x03, 0x6c,
0x75, 0x61, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb0, 0x8c, 0xa0, 0x20, 0x00,
0x00, 0x00, 0x02, 0x70, 0x79, 0x00, 0x00, 0x00, 0x07, 0x70, 0x79, 0x72,
0x69, 0x67, 0x68, 0x74, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0x98, 0x97,
0x20, 0x00, 0x00, 0x00, 0x02, 0x72, 0x73, 0x00, 0x00, 0x00, 0x05, 0xf3,
0xb0, 0x8c, 0x9f, 0x20, 0x00, 0x00, 0x00, 0x03, 0x70, 0x68, 0x70, 0x00,
0x00, 0x00, 0x04, 0xee, 0xba, 0xab, 0x20, 0x00, 0x00, 0x00, 0x02, 0x6d,
0x64, 0x00, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x64, 0x6f, 0x77,
0x6e, 0x00, 0x00, 0x00, 0x04, 0xee, 0x98, 0x95, 0x20, 0x00, 0x00, 0x00,
0x04, 0x63, 0x6f, 0x6e, 0x66, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0xb2,
0x20, 0x00, 0x00, 0x00, 0x04, 0x74, 0x6f, 0x6d, 0x6c, 0x00, 0x00, 0x00,
0x03, 0x79, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x04, 0x79, 0x61, 0x6d, 0x6c,
0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0x8d, 0x20, 0x00, 0x00, 0x00, 0x03,
0x73, 0x71, 0x6c, 0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0xb3, 0x20, 0x00,
0x00, 0x00, 0x08, 0x4d, 0x61, 0x6b, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x00,
0x00, 0x00, 0x08, 0x6d, 0x61, 0x6b, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x00,
0x00, 0x00, 0x04, 0xee, 0x99, 0x9f, 0x20, 0x00, 0x00, 0x00, 0x02, 0x67,
0x64, 0x00, 0x00, 0x00, 0x04, 0xef, 0x80, 0xad, 0x20, 0x00, 0x00, 0x00,
0x03, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9c, 0xa8, 0x20,
0x00, 0x00, 0x00, 0x04, 0x64, 0x69, 0x66, 0x66, 0x00, 0x00, 0x00, 0x05,
0x70, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0x9d,
0x20, 0x00, 0x00, 0x00, 0x0d, 0x67, 0x69, 0x74, 0x61, 0x74, 0x74, 0x72,
0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, 0x09, 0x67, 0x69,
0x74, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x00, 0x00, 0x00, 0x02, 0x2e,
0x2a, 0x00, 0x00, 0x00, 0x05, 0x72, 0x65, 0x67, 0x65, 0x78, 0x00, 0x00,
0x00, 0x03, 0x69, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb0, 0xb4,
0xad, 0x20, 0x00, 0x00, 0x00, 0x02, 0x72, 0x62, 0x00, 0x00, 0x00, 0x07,
0x47, 0x65, 0x6d, 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x04, 0xee,
0xaf, 0x8a, 0x20, 0x00, 0x00, 0x00, 0x02, 0x73, 0x68, 0x00, 0x00, 0x00,
0x0c, 0x62, 0x61, 0x73, 0x68, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c,
0x65, 0x00, 0x00, 0x00, 0x06, 0x62, 0x61, 0x73, 0x68, 0x72, 0x63, 0x00,
0x00, 0x50, 0x00, 0x0b, 0x40, 0x6c, 0x73, 0x70, 0x5f, 0x63, 0x6f, 0x6e,
0x66, 0x69, 0x67, 0x00, 0x00, 0x01, 0x63, 0x00, 0x00, 0x05, 0x63, 0x6f,
0x6c, 0x6f, 0x72, 0x00, 0x00, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c,
0x00, 0x00, 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e,
0x73, 0x00, 0x00, 0x03, 0x6c, 0x73, 0x70, 0x00, 0x00, 0x03, 0x63, 0x70,
0x70, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x03, 0x63, 0x73, 0x73, 0x00,
0x00, 0x04, 0x66, 0x69, 0x73, 0x68, 0x00, 0x00, 0x02, 0x67, 0x6f, 0x00,
0x00, 0x05, 0x67, 0x6f, 0x6d, 0x6f, 0x64, 0x00, 0x00, 0x07, 0x68, 0x61,
0x73, 0x6b, 0x65, 0x6c, 0x6c, 0x00, 0x00, 0x04, 0x68, 0x74, 0x6d, 0x6c,
0x00, 0x00, 0x0a, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70,
0x74, 0x00, 0x00, 0x0a, 0x74, 0x79, 0x70, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x00, 0x00, 0x04, 0x6a, 0x73, 0x6f, 0x6e, 0x00, 0x00, 0x05,
0x6a, 0x73, 0x6f, 0x6e, 0x63, 0x00, 0x00, 0x03, 0x65, 0x72, 0x62, 0x00,
0x00, 0x03, 0x6c, 0x75, 0x61, 0x00, 0x00, 0x06, 0x70, 0x79, 0x74, 0x68,
0x6f, 0x6e, 0x00, 0x00, 0x04, 0x72, 0x75, 0x73, 0x74, 0x00, 0x00, 0x03,
0x70, 0x68, 0x70, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x64, 0x6f,
0x77, 0x6e, 0x00, 0x00, 0x05, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x00, 0x00,
0x04, 0x74, 0x6f, 0x6d, 0x6c, 0x00, 0x00, 0x04, 0x79, 0x61, 0x6d, 0x6c,
0x00, 0x00, 0x03, 0x73, 0x71, 0x6c, 0x00, 0x00, 0x04, 0x6d, 0x61, 0x6b,
0x65, 0x00, 0x00, 0x08, 0x67, 0x64, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x00, 0x00, 0x03, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x04, 0x64, 0x69, 0x66,
0x66, 0x00, 0x00, 0x0d, 0x67, 0x69, 0x74, 0x61, 0x74, 0x74, 0x72, 0x69,
0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x09, 0x67, 0x69, 0x74, 0x69,
0x67, 0x6e, 0x6f, 0x72, 0x65, 0x00, 0x00, 0x05, 0x72, 0x65, 0x67, 0x65,
0x78, 0x00, 0x00, 0x03, 0x69, 0x6e, 0x69, 0x00, 0x00, 0x04, 0x72, 0x75,
0x62, 0x79, 0x00, 0x00, 0x09, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d,
0x65, 0x73, 0x00, 0x00, 0x04, 0x62, 0x61, 0x73, 0x68, 0x00, 0x00, 0x0a,
0x40, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x73, 0x00, 0x00,
0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x00, 0x02, 0x66,
0x67, 0x00, 0x00, 0x07, 0x73, 0x68, 0x65, 0x62, 0x61, 0x6e, 0x67, 0x00,
0x00, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x00, 0x07, 0x63, 0x6f,
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x06, 0x69, 0x74, 0x61, 0x6c,
0x69, 0x63, 0x00, 0x00, 0x06, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00,
0x00, 0x06, 0x65, 0x73, 0x63, 0x61, 0x70, 0x65, 0x00, 0x00, 0x0d, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x70, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x00, 0x00, 0x06, 0x72, 0x65, 0x67, 0x65, 0x78, 0x70, 0x00, 0x00, 0x06,
0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x00, 0x00, 0x04, 0x74, 0x72, 0x75,
0x65, 0x00, 0x00, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x00, 0x00, 0x04,
0x63, 0x68, 0x61, 0x72, 0x00, 0x00, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f,
0x72, 0x64, 0x00, 0x00, 0x0f, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64,
0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x00, 0x00, 0x08, 0x6f,
0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x00, 0x00, 0x08, 0x66, 0x75,
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70,
0x65, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74,
0x00, 0x00, 0x10, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x69,
0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x0e, 0x76, 0x61,
0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c,
0x00, 0x00, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x00, 0x00, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76,
0x65, 0x00, 0x00, 0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x00, 0x00, 0x06,
0x62, 0x72, 0x61, 0x63, 0x65, 0x31, 0x00, 0x00, 0x06, 0x62, 0x72, 0x61,
0x63, 0x65, 0x32, 0x00, 0x00, 0x06, 0x62, 0x72, 0x61, 0x63, 0x65, 0x33,
0x00, 0x00, 0x06, 0x62, 0x72, 0x61, 0x63, 0x65, 0x34, 0x00, 0x00, 0x06,
0x62, 0x72, 0x61, 0x63, 0x65, 0x35, 0x00, 0x00, 0x06, 0x40, 0x74, 0x68,
0x65, 0x6d, 0x65, 0x00, 0x00, 0x09, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x75,
0x6e, 0x69, 0x78, 0x00, 0x00, 0x0d, 0x40, 0x6c, 0x69, 0x6e, 0x65, 0x5f,
0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x73, 0x00, 0x00, 0x0d, 0x40, 0x6b,
0x65, 0x79, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x00,
0x00, 0x0a, 0x40, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x6e, 0x64, 0x73,
0x00, 0x00, 0x0d, 0x40, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68,
0x74, 0x65, 0x72, 0x73, 0x00, 0x00, 0x0a, 0x40, 0x62, 0x5f, 0x73, 0x74,
0x61, 0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x0b, 0x40, 0x62, 0x5f, 0x73,
0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x00, 0x00, 0x06, 0x6c, 0x61,
0x6d, 0x62, 0x64, 0x61, 0x00, 0x00, 0x06, 0x40, 0x62, 0x5f, 0x62, 0x61,
0x72, 0x00, 0x00, 0x00, 0x03, 0x47, 0x00, 0x09, 0x00, 0x14, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x17, 0x34, 0x04, 0x00, 0x00, 0x0f, 0x03,
0x00, 0x82, 0xaa, 0xff, 0x51, 0x04, 0x00, 0x01, 0x09, 0x01, 0x10, 0x0a,
0x00, 0x23, 0x09, 0x10, 0x0a, 0x01, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02,
0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0x82,
0xaa, 0xff, 0x51, 0x04, 0x01, 0x25, 0x00, 0x74, 0x10, 0x0a, 0x03, 0x01,
0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00,
0x0c, 0x0f, 0x03, 0x00, 0xff, 0x8f, 0x40, 0x51, 0x04, 0x02, 0x25, 0x00,
0x57, 0x10, 0x0a, 0x04, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26,
0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0x9a, 0xde, 0x7a,
0x51, 0x04, 0x03, 0x25, 0x00, 0x3a, 0x10, 0x0a, 0x05, 0x01, 0x0b, 0x09,
0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f,
0x03, 0x00, 0xff, 0xd7, 0x00, 0x51, 0x04, 0x04, 0x25, 0x00, 0x1d, 0x10,
0x0a, 0x06, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00,
0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0xf2, 0x9c, 0xc3, 0x51, 0x04,
0x05, 0x25, 0x00, 0x00, 0x1d, 0x09, 0x07, 0x2f, 0x09, 0x08, 0x00, 0x01,
0x0a, 0x01, 0x10, 0x0b, 0x09, 0x23, 0x0a, 0x23, 0x09, 0x01, 0x05, 0x09,
0x1d, 0x09, 0x0a, 0x01, 0x0a, 0x01, 0x10, 0x0b, 0x0b, 0x23, 0x0a, 0x2f,
0x09, 0x0c, 0x01, 0x01, 0x06, 0x09, 0x51, 0x09, 0x06, 0x01, 0x0a, 0x04,
0x52, 0x09, 0x51, 0x0a, 0x06, 0x52, 0x09, 0x01, 0x0a, 0x01, 0x10, 0x0b,
0x00, 0x23, 0x0a, 0x2f, 0x0a, 0x0d, 0x00, 0x2f, 0x0a, 0x0e, 0x00, 0x52,
0x09, 0x51, 0x0a, 0x07, 0x52, 0x09, 0x01, 0x0a, 0x05, 0x10, 0x0b, 0x0f,
0x23, 0x0a, 0x52, 0x09, 0x51, 0x0a, 0x08, 0x52, 0x09, 0x01, 0x0a, 0x06,
0x52, 0x09, 0x51, 0x0a, 0x09, 0x52, 0x09, 0x01, 0x07, 0x09, 0x47, 0x08,
0x00, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0x0b, 0x0e,
0x14, 0x10, 0x0c, 0x11, 0x01, 0x0d, 0x03, 0x10, 0x0e, 0x12, 0x08, 0x0f,
0x10, 0x10, 0x13, 0x06, 0x11, 0x10, 0x12, 0x14, 0x03, 0x13, 0x0a, 0x53,
0x0a, 0x05, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10,
0x01, 0x0b, 0x03, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x33, 0x36, 0x3c,
0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0a, 0x10, 0x10, 0x14, 0x07, 0x11, 0x53,
0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10,
0x0f, 0x0b, 0x00, 0x33, 0x36, 0x3c, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00,
0x24, 0x27, 0x2d, 0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0b, 0x10, 0x10, 0x14,
0x07, 0x11, 0x53, 0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08,
0x10, 0x0a, 0x10, 0x01, 0x0b, 0x05, 0x10, 0x0c, 0x16, 0x23, 0x0b, 0x10,
0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x24, 0x27, 0x2d, 0x10, 0x0e, 0x13, 0x03,
0x0f, 0x0d, 0x10, 0x10, 0x14, 0x08, 0x11, 0x53, 0x0a, 0x04, 0x2f, 0x09,
0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0xce,
0xd4, 0xdf, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x24, 0x27, 0x2d, 0x10,
0x0e, 0x13, 0x03, 0x0f, 0x0f, 0x10, 0x10, 0x14, 0x01, 0x11, 0x06, 0x2f,
0x11, 0x14, 0x00, 0x53, 0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09,
0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0x24, 0x27, 0x2d, 0x10, 0x0c,
0x11, 0x06, 0x0d, 0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0f, 0x01, 0x10, 0x06,
0x2f, 0x10, 0x14, 0x00, 0x3c, 0x0f, 0x10, 0x10, 0x14, 0x07, 0x11, 0x53,
0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x10, 0x09, 0x17, 0x01, 0x0a, 0x07,
0x10, 0x0b, 0x18, 0x01, 0x0c, 0x08, 0x53, 0x09, 0x02, 0x39, 0x09, 0x38,
0x09, 0x00, 0x0a, 0x00, 0x00, 0x02, 0x20, 0x20, 0x00, 0x00, 0x00, 0x04,
0xee, 0x99, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0x93, 0xa7,
0x20, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0xa9, 0xa7, 0x20, 0x00, 0x00,
0x00, 0x04, 0xef, 0x84, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x04, 0xee, 0xba,
0xa2, 0x20, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x08, 0x20,
0xee, 0x82, 0xb4, 0xee, 0x82, 0xb4, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xee, 0x82, 0xb4, 0x00, 0x00, 0x19, 0x00, 0x04, 0x6d,
0x6f, 0x64, 0x65, 0x00, 0x00, 0x06, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c,
0x00, 0x00, 0x03, 0x3d, 0x3d, 0x3d, 0x00, 0x00, 0x06, 0x69, 0x6e, 0x73,
0x65, 0x72, 0x74, 0x00, 0x00, 0x06, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74,
0x00, 0x00, 0x06, 0x72, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x00, 0x00, 0x06,
0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x00, 0x00, 0x01, 0x43, 0x00, 0x00,
0x09, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x73, 0x00, 0x00,
0x09, 0x6c, 0x61, 0x6e, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00,
0x04, 0x46, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x08, 0x66, 0x69, 0x6c, 0x65,
0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x08, 0x62, 0x61, 0x73, 0x65, 0x6e,
0x61, 0x6d, 0x65, 0x00, 0x00, 0x04, 0x74, 0x6f, 0x5f, 0x73, 0x00, 0x00,
0x06, 0x75, 0x70, 0x63, 0x61, 0x73, 0x65, 0x00, 0x00, 0x06, 0x73, 0x79,
0x6d, 0x62, 0x6f, 0x6c, 0x00, 0x00, 0x02, 0x66, 0x67, 0x00, 0x00, 0x02,
0x62, 0x67, 0x00, 0x00, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x00, 0x00,
0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00, 0x06, 0x6c, 0x65, 0x6e,
0x67, 0x74, 0x68, 0x00, 0x00, 0x02, 0x3c, 0x3c, 0x00, 0x00, 0x05, 0x63,
0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x04, 0x74, 0x65, 0x78, 0x74, 0x00,
0x00, 0x0a, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73,
0x00, 0x00, 0x00, 0x01, 0x1b, 0x00, 0x01, 0x00, 0x08, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x45, 0x10, 0x02, 0x00, 0x10, 0x03, 0x01, 0x10,
0x04, 0x02, 0x10, 0x05, 0x03, 0x10, 0x06, 0x04, 0x2d, 0x01, 0x05, 0x05,
0x10, 0x02, 0x06, 0x10, 0x03, 0x07, 0x10, 0x04, 0x08, 0x10, 0x05, 0x09,
0x2d, 0x01, 0x0a, 0x04, 0x63, 0x01, 0x58, 0x02, 0x00, 0x5f, 0x01, 0x0b,
0x63, 0x01, 0x58, 0x02, 0x01, 0x5f, 0x01, 0x0c, 0x63, 0x01, 0x58, 0x02,
0x02, 0x5f, 0x01, 0x0d, 0x63, 0x01, 0x58, 0x02, 0x03, 0x5f, 0x01, 0x0e,
0x38, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x05, 0x74, 0x68, 0x65, 0x6d,
0x65, 0x00, 0x00, 0x0a, 0x6c, 0x73, 0x70, 0x5f, 0x63, 0x6f, 0x6e, 0x66,
0x69, 0x67, 0x00, 0x00, 0x09, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67,
0x65, 0x73, 0x00, 0x00, 0x0c, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x65, 0x6e,
0x64, 0x69, 0x6e, 0x67, 0x73, 0x00, 0x00, 0x0c, 0x68, 0x69, 0x67, 0x68,
0x6c, 0x69, 0x67, 0x68, 0x74, 0x65, 0x72, 0x73, 0x00, 0x00, 0x0d, 0x61,
0x74, 0x74, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72,
0x00, 0x00, 0x09, 0x62, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70,
0x00, 0x00, 0x0a, 0x62, 0x5f, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77,
0x6e, 0x00, 0x00, 0x12, 0x62, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f,
0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x00,
0x05, 0x62, 0x5f, 0x62, 0x61, 0x72, 0x00, 0x00, 0x0b, 0x61, 0x74, 0x74,
0x72, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x00, 0x00, 0x07, 0x73,
0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x08, 0x73, 0x68, 0x75,
0x74, 0x64, 0x6f, 0x77, 0x6e, 0x00, 0x00, 0x10, 0x65, 0x78, 0x74, 0x72,
0x61, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73,
0x00, 0x00, 0x04, 0x62, 0x69, 0x6e, 0x64, 0x00, 0x00, 0x00, 0x00, 0x2d,
0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x34, 0x00, 0x00, 0x01, 0x01, 0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02,
0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x40, 0x62, 0x5f, 0x73, 0x74, 0x61,
0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x02, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x34, 0x00, 0x00,
0x01, 0x01, 0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x0b, 0x40, 0x62, 0x5f, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f,
0x77, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x02, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x34, 0x00, 0x00, 0x01, 0x01,
0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00,
0x13, 0x40, 0x62, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x68, 0x69,
0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x00, 0x00, 0x01,
0x43, 0x00, 0x07, 0x00, 0x0a, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc1, 0x34, 0x04, 0x40, 0x01, 0x25, 0x00, 0x06, 0x25, 0x00, 0x05, 0x25,
0x00, 0x04, 0x11, 0x02, 0x11, 0x03, 0x01, 0x07, 0x01, 0x1d, 0x08, 0x00,
0x2f, 0x07, 0x01, 0x01, 0x26, 0x07, 0x00, 0x07, 0x01, 0x07, 0x01, 0x48,
0x01, 0x07, 0x01, 0x01, 0x07, 0x02, 0x28, 0x07, 0x00, 0x03, 0x25, 0x00,
0x33, 0x12, 0x05, 0x1d, 0x07, 0x02, 0x2f, 0x07, 0x03, 0x00, 0x01, 0x06,
0x07, 0x01, 0x07, 0x06, 0x10, 0x08, 0x04, 0x57, 0x09, 0x00, 0x30, 0x07,
0x05, 0x01, 0x2d, 0x07, 0x06, 0x00, 0x27, 0x07, 0x00, 0x0d, 0x01, 0x07,
0x06, 0x01, 0x08, 0x04, 0x30, 0x07, 0x07, 0x00, 0x25, 0x00, 0x02, 0x11,
0x07, 0x25, 0x00, 0x5c, 0x2d, 0x07, 0x06, 0x00, 0x27, 0x07, 0x00, 0x22,
0x01, 0x07, 0x02, 0x1d, 0x08, 0x00, 0x2f, 0x07, 0x01, 0x01, 0x26, 0x07,
0x00, 0x07, 0x01, 0x07, 0x02, 0x48, 0x02, 0x07, 0x01, 0x01, 0x07, 0x01,
0x57, 0x08, 0x01, 0x30, 0x07, 0x08, 0x00, 0x25, 0x00, 0x32, 0x01, 0x07,
0x03, 0x1d, 0x08, 0x09, 0x2f, 0x07, 0x01, 0x01, 0x27, 0x07, 0x00, 0x22,
0x01, 0x07, 0x02, 0x1d, 0x08, 0x00, 0x2f, 0x07, 0x01, 0x01, 0x26, 0x07,
0x00, 0x07, 0x01, 0x07, 0x02, 0x48, 0x02, 0x07, 0x01, 0x01, 0x07, 0x01,
0x57, 0x08, 0x02, 0x30, 0x07, 0x08, 0x00, 0x25, 0x00, 0x02, 0x11, 0x07,
0x38, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x05, 0x41, 0x72, 0x72, 0x61,
0x79, 0x00, 0x00, 0x05, 0x69, 0x73, 0x5f, 0x61, 0x3f, 0x00, 0x00, 0x06,
0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00, 0x00, 0x03, 0x6e, 0x65, 0x77,
0x00, 0x00, 0x03, 0x73, 0x65, 0x74, 0x00, 0x00, 0x17, 0x64, 0x65, 0x66,
0x69, 0x6e, 0x65, 0x5f, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x74, 0x6f,
0x6e, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x00, 0x00, 0x0c, 0x62,
0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x3f, 0x00,
0x00, 0x0d, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x65,
0x78, 0x65, 0x63, 0x00, 0x00, 0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00,
0x06, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x3e,
0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
0x34, 0x04, 0x20, 0x01, 0x25, 0x00, 0x03, 0x25, 0x00, 0x02, 0x11, 0x02,
0x21, 0x04, 0x05, 0x00, 0x21, 0x05, 0x01, 0x00, 0x01, 0x06, 0x01, 0x01,
0x07, 0x02, 0x01, 0x08, 0x03, 0x30, 0x04, 0x00, 0x03, 0x38, 0x04, 0x00,
0x00, 0x00, 0x01, 0x00, 0x04, 0x62, 0x69, 0x6e, 0x64, 0x00, 0x00, 0x00,
0x00, 0x2c, 0x00, 0x03, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x11, 0x34, 0x04, 0x00, 0x00, 0x21, 0x03, 0x02, 0x00, 0x57, 0x04,
0x00, 0x30, 0x03, 0x00, 0x00, 0x38, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00,
0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x03,
0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x34, 0x04,
0x00, 0x00, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x01, 0x05, 0x03,
0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00, 0x07, 0x53,
0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01,
0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x01, 0x05, 0x03, 0x01, 0x06, 0x04,
0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00, 0x07, 0x47, 0x05, 0x00, 0x2f,
0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x23, 0x03,
0x01, 0x04, 0x01, 0x23, 0x03, 0x21, 0x04, 0x04, 0x01, 0x2f, 0x03, 0x03,
0x01, 0x38, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0d, 0x40, 0x6b, 0x65,
0x79, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x00, 0x00,
0x02, 0x5b, 0x5d, 0x00, 0x00, 0x03, 0x5b, 0x5d, 0x3d, 0x00, 0x00, 0x02,
0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x03, 0x00, 0x05, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x34, 0x04, 0x00, 0x00, 0x21,
0x03, 0x02, 0x00, 0x57, 0x04, 0x00, 0x30, 0x03, 0x00, 0x00, 0x38, 0x03,
0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00,
0x00, 0x00, 0x8a, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x59, 0x34, 0x04, 0x00, 0x00, 0x19, 0x03, 0x00, 0x21, 0x04,
0x01, 0x00, 0x01, 0x05, 0x03, 0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01,
0x26, 0x05, 0x00, 0x07, 0x53, 0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19,
0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x01,
0x05, 0x03, 0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00,
0x07, 0x47, 0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21,
0x04, 0x01, 0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x23, 0x03, 0x21, 0x04,
0x03, 0x01, 0x2f, 0x03, 0x03, 0x01, 0x38, 0x03, 0x00, 0x00, 0x00, 0x04,
0x00, 0x0a, 0x40, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x6e, 0x64, 0x73,
0x00, 0x00, 0x02, 0x5b, 0x5d, 0x00, 0x00, 0x03, 0x5b, 0x5d, 0x3d, 0x00,
0x00, 0x02, 0x3c, 0x3c, 0x00, 0x4c, 0x56, 0x41, 0x52, 0x00, 0x00, 0x00,
0xcc, 0x00, 0x00, 0x00, 0x12, 0x00, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x00,
0x0a, 0x6d, 0x6f, 0x64, 0x65, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00,
0x0b, 0x6d, 0x6f, 0x64, 0x65, 0x5f, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c,
0x00, 0x09, 0x6c, 0x61, 0x6e, 0x67, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x00,
0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x08, 0x73,
0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x0a, 0x68, 0x69, 0x67,
0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x05, 0x62, 0x6c, 0x6f,
0x63, 0x6b, 0x00, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x73, 0x00, 0x04, 0x6b,
0x65, 0x79, 0x73, 0x00, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00,
0x03, 0x61, 0x70, 0x70, 0x00, 0x03, 0x64, 0x73, 0x6c, 0x00, 0x01, 0x6b,
0x00, 0x03, 0x61, 0x63, 0x74, 0x00, 0x03, 0x62, 0x6c, 0x6b, 0x00, 0x04,
0x6d, 0x6f, 0x64, 0x65, 0x00, 0x03, 0x6b, 0x65, 0x79, 0x00, 0x00, 0xff,
0xff, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
0x06, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00,
0x0a, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00,
0x0f, 0x00, 0x10, 0xff, 0xff, 0x00, 0x11, 0xff, 0xff, 0x00, 0x10, 0xff,
0xff, 0x00, 0x11, 0xff, 0xff, 0x45, 0x4e, 0x44, 0x00, 0x00, 0x00, 0x00,
0x08
};
constexpr unsigned int _tmp___crib_precompiled_mrb_len = 7273;

View File

@@ -3,74 +3,12 @@
#include "io/knot.h" #include "io/knot.h"
#include "io/sysio.h" #include "io/sysio.h"
#include "syntax/trie.h"
struct Trie {
struct TrieNode {
bool is_word = false;
std::array<TrieNode *, 128> children{};
TrieNode() { children.fill(nullptr); }
};
Trie() : root(new TrieNode()) {}
~Trie() { clear_trie(root); }
void build(const std::vector<std::string> &words) {
for (const auto &word : words) {
TrieNode *node = root;
for (char c : word) {
unsigned char uc = static_cast<unsigned char>(c);
if (!node->children[uc])
node->children[uc] = new TrieNode();
node = node->children[uc];
}
node->is_word = true;
}
}
uint32_t match(const char *text, uint32_t pos, uint32_t len,
bool (*is_word_char)(char c)) const {
const TrieNode *node = root;
uint32_t max_len = 0;
for (uint32_t i = pos; i < len; ++i) {
unsigned char uc = static_cast<unsigned char>(text[i]);
if (uc >= 128)
return 0;
if (!node->children[uc]) {
if (node->is_word && !is_word_char(text[i]))
return i - pos;
break;
}
node = node->children[uc];
if (node->is_word)
max_len = i - pos + 1;
}
if (max_len > 0)
if (pos + max_len < len && is_word_char(text[pos + max_len]))
return 0;
return max_len;
}
void clear() {
clear_trie(root);
root = new TrieNode();
}
private:
TrieNode *root;
void clear_trie(TrieNode *node) {
if (!node)
return;
for (auto *child : node->children)
clear_trie(child);
delete node;
}
};
struct Highlight { struct Highlight {
uint32_t fg; uint32_t fg{0xFFFFFF};
uint32_t bg; uint32_t bg{0x000000};
uint8_t flags; uint8_t flags{0};
}; };
enum struct TokenKind : uint8_t { enum struct TokenKind : uint8_t {
@@ -90,55 +28,6 @@ const std::unordered_map<std::string, TokenKind> kind_map = {
extern std::array<Highlight, TOKEN_KIND_COUNT> highlights; extern std::array<Highlight, TOKEN_KIND_COUNT> highlights;
inline void load_theme(std::string filename) {
uint32_t len = 0;
char *raw = load_file(filename.c_str(), &len);
if (!raw)
return;
std::string data(raw, len);
free(raw);
json j = json::parse(data);
Highlight default_hl = {0xFFFFFF, 0, 0};
if (j.contains("Default")) {
auto def = j["Default"];
if (def.contains("fg") && def["fg"].is_string())
default_hl.fg = HEX(def["fg"]);
if (def.contains("bg") && def["bg"].is_string())
default_hl.bg = HEX(def["bg"]);
if (def.contains("italic") && def["italic"].get<bool>())
default_hl.flags |= CF_ITALIC;
if (def.contains("bold") && def["bold"].get<bool>())
default_hl.flags |= CF_BOLD;
if (def.contains("underline") && def["underline"].get<bool>())
default_hl.flags |= CF_UNDERLINE;
if (def.contains("strikethrough") && def["strikethrough"].get<bool>())
default_hl.flags |= CF_STRIKETHROUGH;
}
for (auto &hl : highlights)
hl = default_hl;
for (auto &[key, value] : j.items()) {
if (key == "Default")
continue;
auto it = kind_map.find(key);
if (it == kind_map.end())
continue;
Highlight hl = {0xFFFFFF, 0, 0};
if (value.contains("fg") && value["fg"].is_string())
hl.fg = HEX(value["fg"]);
if (value.contains("bg") && value["bg"].is_string())
hl.bg = HEX(value["bg"]);
if (value.contains("italic") && value["italic"].get<bool>())
hl.flags |= CF_ITALIC;
if (value.contains("bold") && value["bold"].get<bool>())
hl.flags |= CF_BOLD;
if (value.contains("underline") && value["underline"].get<bool>())
hl.flags |= CF_UNDERLINE;
if (value.contains("strikethrough") && value["strikethrough"].get<bool>())
hl.flags |= CF_STRIKETHROUGH;
highlights[static_cast<uint8_t>(it->second)] = hl;
}
}
struct Token { struct Token {
uint32_t start; uint32_t start;
uint32_t end; uint32_t end;
@@ -151,4 +40,9 @@ struct LineData {
std::shared_ptr<void> out_state{nullptr}; std::shared_ptr<void> out_state{nullptr};
}; };
struct CustomState {
mrb_value state;
CustomState(mrb_value s) : state(s) {}
};
#endif #endif

490
include/syntax/extras.h Normal file
View File

@@ -0,0 +1,490 @@
#ifndef SYNTAX_EXTRAS_H
#define SYNTAX_EXTRAS_H
#include "io/knot.h"
#include "syntax/decl.h"
#include "utils/utils.h"
inline static const std::vector<std::pair<std::string, uint32_t>> color_map = {
{"AliceBlue", 0xF0F8FF},
{"AntiqueWhite", 0xFAEBD7},
{"Aqua", 0x00FFFF},
{"Aquamarine", 0x7FFFD4},
{"Azure", 0xF0FFFF},
{"Beige", 0xF5F5DC},
{"Bisque", 0xFFE4C4},
{"Black", 0x000000},
{"BlanchedAlmond", 0xFFEBCD},
{"Blue", 0x0000FF},
{"BlueViolet", 0x8A2BE2},
{"Brown", 0xA52A2A},
{"BurlyWood", 0xDEB887},
{"CadetBlue", 0x5F9EA0},
{"Chartreuse", 0x7FFF00},
{"Chocolate", 0xD2691E},
{"Coral", 0xFF7F50},
{"CornflowerBlue", 0x6495ED},
{"Cornsilk", 0xFFF8DC},
{"Crimson", 0xDC143C},
{"Cyan", 0x00FFFF},
{"DarkBlue", 0x00008B},
{"DarkCyan", 0x008B8B},
{"DarkGoldenRod", 0xB8860B},
{"DarkGray", 0xA9A9A9},
{"DarkGrey", 0xA9A9A9},
{"DarkGreen", 0x006400},
{"DarkKhaki", 0xBDB76B},
{"DarkMagenta", 0x8B008B},
{"DarkOliveGreen", 0x556B2F},
{"DarkOrange", 0xFF8C00},
{"DarkOrchid", 0x9932CC},
{"DarkRed", 0x8B0000},
{"DarkSalmon", 0xE9967A},
{"DarkSeaGreen", 0x8FBC8F},
{"DarkSlateBlue", 0x483D8B},
{"DarkSlateGray", 0x2F4F4F},
{"DarkSlateGrey", 0x2F4F4F},
{"DarkTurquoise", 0x00CED1},
{"DarkViolet", 0x9400D3},
{"DeepPink", 0xFF1493},
{"DeepSkyBlue", 0x00BFFF},
{"DimGray", 0x696969},
{"DimGrey", 0x696969},
{"DodgerBlue", 0x1E90FF},
{"FireBrick", 0xB22222},
{"FloralWhite", 0xFFFAF0},
{"ForestGreen", 0x228B22},
{"Fuchsia", 0xFF00FF},
{"Gainsboro", 0xDCDCDC},
{"GhostWhite", 0xF8F8FF},
{"Gold", 0xFFD700},
{"GoldenRod", 0xDAA520},
{"Gray", 0x808080},
{"Grey", 0x808080},
{"Green", 0x008000},
{"GreenYellow", 0xADFF2F},
{"HoneyDew", 0xF0FFF0},
{"HotPink", 0xFF69B4},
{"IndianRed", 0xCD5C5C},
{"Indigo", 0x4B0082},
{"Ivory", 0xFFFFF0},
{"Khaki", 0xF0E68C},
{"Lavender", 0xE6E6FA},
{"LavenderBlush", 0xFFF0F5},
{"LawnGreen", 0x7CFC00},
{"LemonChiffon", 0xFFFACD},
{"LightBlue", 0xADD8E6},
{"LightCoral", 0xF08080},
{"LightCyan", 0xE0FFFF},
{"LightGoldenRodYellow", 0xFAFAD2},
{"LightGray", 0xD3D3D3},
{"LightGrey", 0xD3D3D3},
{"LightGreen", 0x90EE90},
{"LightPink", 0xFFB6C1},
{"LightSalmon", 0xFFA07A},
{"LightSeaGreen", 0x20B2AA},
{"LightSkyBlue", 0x87CEFA},
{"LightSlateGray", 0x778899},
{"LightSlateGrey", 0x778899},
{"LightSteelBlue", 0xB0C4DE},
{"LightYellow", 0xFFFFE0},
{"Lime", 0x00FF00},
{"LimeGreen", 0x32CD32},
{"Linen", 0xFAF0E6},
{"Magenta", 0xFF00FF},
{"Maroon", 0x800000},
{"MediumAquaMarine", 0x66CDAA},
{"MediumBlue", 0x0000CD},
{"MediumOrchid", 0xBA55D3},
{"MediumPurple", 0x9370DB},
{"MediumSeaGreen", 0x3CB371},
{"MediumSlateBlue", 0x7B68EE},
{"MediumSpringGreen", 0x00FA9A},
{"MediumTurquoise", 0x48D1CC},
{"MediumVioletRed", 0xC71585},
{"MidnightBlue", 0x191970},
{"MintCream", 0xF5FFFA},
{"MistyRose", 0xFFE4E1},
{"Moccasin", 0xFFE4B5},
{"NavajoWhite", 0xFFDEAD},
{"Navy", 0x000080},
{"OldLace", 0xFDF5E6},
{"Olive", 0x808000},
{"OliveDrab", 0x6B8E23},
{"Orange", 0xFFA500},
{"OrangeRed", 0xFF4500},
{"Orchid", 0xDA70D6},
{"PaleGoldenRod", 0xEEE8AA},
{"PaleGreen", 0x98FB98},
{"PaleTurquoise", 0xAFEEEE},
{"PaleVioletRed", 0xDB7093},
{"PapayaWhip", 0xFFEFD5},
{"PeachPuff", 0xFFDAB9},
{"Peru", 0xCD853F},
{"Pink", 0xFFC0CB},
{"Plum", 0xDDA0DD},
{"PowderBlue", 0xB0E0E6},
{"Purple", 0x800080},
{"RebeccaPurple", 0x663399},
{"Red", 0xFF0000},
{"RosyBrown", 0xBC8F8F},
{"RoyalBlue", 0x4169E1},
{"SaddleBrown", 0x8B4513},
{"Salmon", 0xFA8072},
{"SandyBrown", 0xF4A460},
{"SeaGreen", 0x2E8B57},
{"SeaShell", 0xFFF5EE},
{"Sienna", 0xA0522D},
{"Silver", 0xC0C0C0},
{"SkyBlue", 0x87CEEB},
{"SlateBlue", 0x6A5ACD},
{"SlateGray", 0x708090},
{"SlateGrey", 0x708090},
{"Snow", 0xFFFAFA},
{"SpringGreen", 0x00FF7F},
{"SteelBlue", 0x4682B4},
{"Tan", 0xD2B48C},
{"Teal", 0x008080},
{"Thistle", 0xD8BFD8},
{"Tomato", 0xFF6347},
{"Turquoise", 0x40E0D0},
{"Violet", 0xEE82EE},
{"Wheat", 0xF5DEB3},
{"White", 0xFFFFFF},
{"WhiteSmoke", 0xF5F5F5},
{"Yellow", 0xFFFF00},
{"YellowGreen", 0x9ACD32},
};
// Add word under cursor to this
struct ExtraHighlighter {
std::vector<uint32_t> colors;
std::array<std::vector<uint32_t>, 50> lines;
Trie<uint32_t> css_colors = Trie<uint32_t>();
uint32_t start = 0;
ExtraHighlighter() { css_colors.build(color_map, false); }
void render(Knot *root, uint32_t n_start, std::string word, bool is_css) {
start = n_start;
for (auto &line : lines)
line.clear();
LineIterator *it = begin_l_iter(root, start);
if (!it)
return;
uint32_t idx = 0;
uint32_t len;
char *line;
while (idx < 50 && (line = next_line(it, &len))) {
lines[idx].assign(len, UINT32_MAX - 1);
uint32_t i = 0;
while (i < len) {
if (is_css) {
std::optional<uint32_t> color;
uint32_t color_len = css_colors.match(
line, i, len, [](char c) { return isalnum(c) || c == '_'; },
&color);
if (color) {
for (uint32_t j = 0; j < color_len; j++)
lines[idx][i + j] = *color;
i += color_len;
continue;
} else if (i + 5 < len && (line[i] == 'r' || line[i] == 'R') &&
(line[i + 1] == 'g' || line[i + 1] == 'G') &&
(line[i + 2] == 'b' || line[i + 2] == 'B')) {
uint32_t start = i;
i += 3;
if (line[i] == 'a' || line[i] == 'A')
i++;
if (line[i] == '(') {
i++;
bool is_percent = false;
std::string r = "";
while (i < len && line[i] >= '0' && line[i] <= '9')
r += line[i++];
if (r.empty())
continue;
while (i < len &&
(line[i] == '.' || (line[i] >= '0' && line[i] <= '9')))
i++;
if (line[i] == '%') {
is_percent = true;
i++;
}
while (i < len && (line[i] == ',' || line[i] == ' '))
i++;
std::string g = "";
while (i < len && line[i] >= '0' && line[i] <= '9')
g += line[i++];
if (g.empty())
continue;
while (i < len &&
(line[i] == '.' || (line[i] >= '0' && line[i] <= '9')))
i++;
while (i < len &&
(line[i] == ',' || line[i] == ' ' || line[i] == '%'))
i++;
std::string b = "";
while (i < len && line[i] >= '0' && line[i] <= '9')
b += line[i++];
if (b.empty())
continue;
while (i < len &&
(line[i] == ',' || line[i] == ' ' || line[i] == '.' ||
line[i] == '/' || line[i] == '%' ||
(line[i] >= '0' && line[i] <= '9')))
i++;
if (i < len && line[i] == ')')
i++;
else
continue;
uint32_t rr, gg, bb;
if (is_percent) {
rr = std::stoul(r) * 255 / 100;
gg = std::stoul(g) * 255 / 100;
bb = std::stoul(b) * 255 / 100;
} else {
rr = std::stoul(r);
gg = std::stoul(g);
bb = std::stoul(b);
}
rr = rr > 255 ? 255 : rr;
gg = gg > 255 ? 255 : gg;
bb = bb > 255 ? 255 : bb;
uint32_t color = (rr << 16) | (gg << 8) | bb;
for (uint32_t j = start; j < i; j++)
lines[idx][j] = color;
}
continue;
} else if (i + 5 < len && (line[i] == 'h' || line[i] == 'H') &&
(line[i + 1] == 's' || line[i + 1] == 'S') &&
(line[i + 2] == 'l' || line[i + 2] == 'L')) {
uint32_t start = i;
i += 3;
if (line[i] == 'a' || line[i] == 'A')
i++;
if (line[i] == '(') {
i++;
std::string h = "";
std::string h_unit = "";
enum unit : uint8_t { deg, grad, rad, turn };
unit u = deg;
bool negative = false;
if (i < len && (line[i] == '-' || line[i] == '+')) {
negative = line[i] == '-';
i++;
}
while (i < len && line[i] >= '0' && line[i] <= '9')
h += line[i++];
if (i < len && line[i] == '.') {
h += '.';
while (i < len && line[i] >= '0' && line[i] <= '9')
h += line[i++];
}
if (h.empty())
continue;
while (i < len && ((line[i] >= 'a' && line[i] <= 'z') ||
(line[i] >= 'A' && line[i] <= 'Z')))
h_unit += line[i++];
for (size_t x = 0; x < h_unit.size(); x++)
h_unit[x] = tolower(h_unit[x]);
if (h_unit.empty())
u = deg;
else if (h_unit == "deg")
u = deg;
else if (h_unit == "grad")
u = grad;
else if (h_unit == "rad")
u = rad;
else if (h_unit == "turn")
u = turn;
else
continue;
double hue = std::stod(h);
if (negative)
hue = -hue;
switch (u) {
case deg:
break;
case grad:
hue = hue * 360.0 / 400.0;
break;
case rad:
hue = hue * 180.0 / M_PI;
break;
case turn:
hue = hue * 360.0;
break;
}
hue = fmod(hue, 360.0);
if (hue < 0)
hue += 360.0;
double h_final = hue / 360.0;
while (i < len && (line[i] == ',' || line[i] == ' '))
i++;
std::string s = "";
while (i < len && line[i] >= '0' && line[i] <= '9')
s += line[i++];
if (s.empty())
continue;
if (i < len && line[i] == '%')
i++;
else
continue;
while (i < len && (line[i] == ',' || line[i] == ' '))
i++;
std::string l = "";
while (i < len && line[i] >= '0' && line[i] <= '9')
l += line[i++];
if (l.empty())
continue;
if (i < len && line[i] == '%')
i++;
else
continue;
while (i < len &&
(line[i] == ',' || line[i] == ' ' || line[i] == '.' ||
line[i] == '/' || line[i] == '%' ||
(line[i] >= '0' && line[i] <= '9')))
i++;
if (i < len && line[i] == ')')
i++;
double s_val = std::stod(s) / 100.0;
double l_val = std::stod(l) / 100.0;
uint32_t color = hslToRgb(h_final, s_val, l_val);
for (uint32_t j = start; j < i; j++)
lines[idx][j] = color;
}
continue;
}
}
if (i + 4 < len && line[i] == '#') {
i++;
uint32_t start = i;
while (i < len && isxdigit(line[i]))
i++;
uint32_t color = 0;
if (is_css && (i - start == 3 || i - start == 4)) {
uint32_t r =
std::stoul(std::string(line + start, 1), nullptr, 16) * 0x11;
uint32_t g =
std::stoul(std::string(line + start + 1, 1), nullptr, 16) *
0x11;
uint32_t b =
std::stoul(std::string(line + start + 2, 1), nullptr, 16) *
0x11;
color = (r << 16) | (g << 8) | b;
} else if ((is_css && (i - start == 8)) || i - start == 6) {
uint32_t r = std::stoul(std::string(line + start, 2), nullptr, 16);
uint32_t g =
std::stoul(std::string(line + start + 2, 2), nullptr, 16);
uint32_t b =
std::stoul(std::string(line + start + 4, 2), nullptr, 16);
color = (r << 16) | (g << 8) | b;
} else {
continue;
}
for (uint32_t j = start - 1; j < i; j++)
lines[idx][j] = color;
continue;
} else if (i + 5 < len && line[i] == '0' && line[i + 1] == 'x') {
i += 2;
uint32_t start = i;
while (i < len && isxdigit(line[i]))
i++;
uint32_t color = 0;
if (i - start == 6) {
uint32_t r = std::stoul(std::string(line + start, 2), nullptr, 16);
uint32_t g =
std::stoul(std::string(line + start + 2, 2), nullptr, 16);
uint32_t b =
std::stoul(std::string(line + start + 4, 2), nullptr, 16);
color = (r << 16) | (g << 8) | b;
} else {
continue;
}
if (color)
color--;
else
color++;
for (uint32_t j = start - 2; j < i; j++)
lines[idx][j] = color;
continue;
}
if (i < len && (isalnum(line[i]) || line[i] == '_')) {
uint32_t start = i;
uint32_t x = 0;
bool found = true;
while (i < len && (isalnum(line[i]) || line[i] == '_')) {
if (x < word.size() && line[i] == word[x]) {
i++;
x++;
} else {
found = false;
i++;
}
}
if (found && x == word.size())
for (uint32_t j = start; j < i; j++)
lines[idx][j] = UINT32_MAX;
} else {
i += utf8_codepoint_width(line[i]);
}
}
idx++;
}
free(it->buffer);
free(it);
}
std::optional<std::pair<uint32_t, uint32_t>> get(Coord pos) {
uint32_t val;
if (pos.row < start || pos.row >= start + 50 ||
pos.col >= lines[pos.row - start].size() ||
(val = lines[pos.row - start][pos.col]) == UINT32_MAX - 1)
return std::nullopt;
return (std::pair<uint32_t, uint32_t>){fg_for_bg(val), val};
}
private:
uint32_t fg_for_bg(uint32_t color) {
uint8_t r = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t b = color & 0xFF;
double luminance = 0.299 * r + 0.587 * g + 0.114 * b;
return (luminance > 128) ? 0x010101 : 0xFFFFFF;
}
uint32_t hslToRgb(double h, double s, double l) {
double r, g, b;
if (s == 0.0) {
r = g = b = l;
} else {
auto hue2rgb = [](double p, double q, double t) -> double {
if (t < 0)
t += 1;
if (t > 1)
t -= 1;
if (t < 1.0 / 6)
return p + (q - p) * 6 * t;
if (t < 1.0 / 2)
return q;
if (t < 2.0 / 3)
return p + (q - p) * (2.0 / 3 - t) * 6;
return p;
};
double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
double p = 2 * l - q;
r = hue2rgb(p, q, h + 1.0 / 3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1.0 / 3);
}
uint32_t R = static_cast<uint32_t>(std::clamp(r, 0.0, 1.0) * 255);
uint32_t G = static_cast<uint32_t>(std::clamp(g, 0.0, 1.0) * 255);
uint32_t B = static_cast<uint32_t>(std::clamp(b, 0.0, 1.0) * 255);
return (R << 16) | (G << 8) | B;
}
};
#endif

View File

@@ -4,9 +4,9 @@
#include "syntax/decl.h" #include "syntax/decl.h"
#define DEF_LANG(name) \ #define DEF_LANG(name) \
std::shared_ptr<void> name##_parse(std::vector<Token> *tokens, \ std::shared_ptr<void> name##_parse( \
std::shared_ptr<void> in_state, \ std::vector<Token> *tokens, std::shared_ptr<void> in_state, \
const char *text, uint32_t len); \ const char *text, uint32_t len, uint32_t line_num); \
bool name##_state_match(std::shared_ptr<void> state_1, \ bool name##_state_match(std::shared_ptr<void> state_1, \
std::shared_ptr<void> state_2); std::shared_ptr<void> state_2);
@@ -34,9 +34,9 @@ DEF_LANG(bash);
inline static const std::unordered_map< inline static const std::unordered_map<
std::string, std::string,
std::tuple<std::shared_ptr<void> (*)(std::vector<Token> *tokens, std::tuple<std::shared_ptr<void> (*)(
std::shared_ptr<void> in_state, std::vector<Token> *tokens, std::shared_ptr<void> in_state,
const char *text, uint32_t len), const char *text, uint32_t len, uint32_t line_num),
bool (*)(std::shared_ptr<void> state_1, bool (*)(std::shared_ptr<void> state_1,
std::shared_ptr<void> state_2)>> std::shared_ptr<void> state_2)>>
parsers = { parsers = {

View File

@@ -74,10 +74,14 @@ struct LineTree {
} }
void insert(uint32_t x, uint32_t y) { void insert(uint32_t x, uint32_t y) {
std::unique_lock lock(mtx); std::unique_lock lock(mtx);
if (x > subtree_size(root))
x = subtree_size(root);
root = insert_node(root, x, y); root = insert_node(root, x, y);
} }
void erase(uint32_t x, uint32_t y) { void erase(uint32_t x, uint32_t y) {
std::unique_lock lock(mtx); std::unique_lock lock(mtx);
if (x + y > subtree_size(root))
x = subtree_size(root) - y;
root = erase_node(root, x, y); root = erase_node(root, x, y);
} }
uint32_t count() { uint32_t count() {
@@ -116,18 +120,26 @@ private:
std::shared_mutex mtx; std::shared_mutex mtx;
static constexpr uint32_t LEAF_TARGET = 256; static constexpr uint32_t LEAF_TARGET = 256;
LineTree::LineNode *erase_node(LineNode *n, uint32_t x, uint32_t y) { LineTree::LineNode *erase_node(LineNode *n, uint32_t x, uint32_t y) {
if (!n) if (!n || y == 0)
return nullptr;
if (!n->left && !n->right) {
n->data.erase(n->data.begin() + x, n->data.begin() + x + y);
fix(n);
return n; return n;
uint32_t left_sz = subtree_size(n->left);
uint32_t mid_sz = n->data.size();
if (x < left_sz) {
uint32_t len = std::min(y, left_sz - x);
n->left = erase_node(n->left, x, len);
y -= len;
x = left_sz;
}
if (y > 0 && x < left_sz + mid_sz) {
uint32_t mid_x = x - left_sz;
uint32_t len = std::min(y, mid_sz - mid_x);
n->data.erase(n->data.begin() + mid_x, n->data.begin() + mid_x + len);
y -= len;
x += len;
}
if (y > 0) {
n->right = erase_node(n->right, x - left_sz - n->data.size(), y);
} }
uint32_t left_size = subtree_size(n->left);
if (x < left_size)
n->left = erase_node(n->left, x, y);
else
n->right = erase_node(n->right, x - left_size - n->data.size(), y);
if (n->left && n->right && if (n->left && n->right &&
subtree_size(n->left) + subtree_size(n->right) < 256) { subtree_size(n->left) + subtree_size(n->right) < 256) {
return merge(n->left, n->right); return merge(n->left, n->right);
@@ -142,7 +154,7 @@ private:
return leaf; return leaf;
} }
if (!n->left && !n->right) { if (!n->left && !n->right) {
n->data.insert(n->data.begin() + x, y, LineData{}); n->data.insert(n->data.begin() + x, y, LineData());
fix(n); fix(n);
if (n->data.size() > 512) if (n->data.size() > 512)
return split_leaf(n); return split_leaf(n);

View File

@@ -1,28 +1,31 @@
#ifndef SYNTAX_PARSER_H #ifndef SYNTAX_PARSER_H
#define SYNTAX_PARSER_H #define SYNTAX_PARSER_H
#include "scripting/decl.h"
#include "syntax/decl.h" #include "syntax/decl.h"
#include "syntax/line_tree.h" #include "syntax/line_tree.h"
struct Parser { struct Parser {
Knot *root; struct Editor *editor = nullptr;
std::shared_mutex *knot_mutex;
std::string lang; std::string lang;
std::shared_ptr<void> (*parse_func)(std::vector<Token> *tokens, std::shared_ptr<void> (*parse_func)(std::vector<Token> *tokens,
std::shared_ptr<void> in_state, std::shared_ptr<void> in_state,
const char *text, uint32_t len); const char *text, uint32_t len,
uint32_t line_num);
bool (*state_match_func)(std::shared_ptr<void> state_1, bool (*state_match_func)(std::shared_ptr<void> state_1,
std::shared_ptr<void> state_2); std::shared_ptr<void> state_2);
mrb_value parser_block = mrb_nil_value();
mrb_value match_block = mrb_nil_value();
bool is_custom{false};
std::atomic<uint32_t> scroll_max{UINT32_MAX - 2048}; std::atomic<uint32_t> scroll_max{UINT32_MAX - 2048};
std::atomic<bool> scroll_dirty{false};
std::mutex mutex; std::mutex mutex;
std::mutex data_mutex; std::mutex data_mutex;
LineTree line_tree; LineTree line_tree;
std::set<uint32_t> dirty_lines; UniqueQueue<uint32_t> dirty_lines;
Parser(Knot *n_root, std::shared_mutex *n_knot_mutex, std::string n_lang, Parser(Editor *editor, std::string n_lang, uint32_t n_scroll_max);
uint32_t n_scroll_max); void edit(uint32_t start_line, uint32_t old_end_line, uint32_t inserted_rows);
void edit(Knot *n_root, uint32_t start_line, uint32_t old_end_line,
uint32_t new_end_line);
void work(); void work();
void scroll(uint32_t line); void scroll(uint32_t line);
}; };

View File

@@ -1,53 +1,53 @@
ADD(Data) ADD(K_DATA)
ADD(Shebang) ADD(K_SHEBANG)
ADD(Comment) ADD(K_COMMENT)
ADD(Error) ADD(K_ERROR)
ADD(String) ADD(K_STRING)
ADD(Escape) ADD(K_ESCAPE)
ADD(Interpolation) ADD(K_INTERPOLATION)
ADD(Regexp) ADD(K_REGEXP)
ADD(Number) ADD(K_NUMBER)
ADD(True) ADD(K_TRUE)
ADD(False) ADD(K_FALSE)
ADD(Char) ADD(K_CHAR)
ADD(Keyword) ADD(K_KEYWORD)
ADD(KeywordOperator) ADD(K_KEYWORDOPERATOR)
ADD(Operator) ADD(K_OPERATOR)
ADD(Function) ADD(K_FUNCTION)
ADD(Type) ADD(K_TYPE)
ADD(Constant) ADD(K_CONSTANT)
ADD(VariableInstance) ADD(K_VARIABLEINSTANCE)
ADD(VariableGlobal) ADD(K_VARIABLEGLOBAL)
ADD(Annotation) ADD(K_ANNOTATION)
ADD(Directive) ADD(K_DIRECTIVE)
ADD(Label) ADD(K_LABEL)
ADD(Brace1) ADD(K_BRACE1)
ADD(Brace2) ADD(K_BRACE2)
ADD(Brace3) ADD(K_BRACE3)
ADD(Brace4) ADD(K_BRACE4)
ADD(Brace5) ADD(K_BRACE5)
ADD(Heading1) ADD(K_HEADING1)
ADD(Heading2) ADD(K_HEADING2)
ADD(Heading3) ADD(K_HEADING3)
ADD(Heading4) ADD(K_HEADING4)
ADD(Heading5) ADD(K_HEADING5)
ADD(Heading6) ADD(K_HEADING6)
ADD(Blockquote) ADD(K_BLOCKQUOTE)
ADD(List) ADD(K_LIST)
ADD(ListItem) ADD(K_LISTITEM)
ADD(Code) ADD(K_CODE)
ADD(LanguageName) ADD(K_LANGUAGENAME)
ADD(LinkLabel) ADD(K_LINKLABEL)
ADD(ImageLabel) ADD(K_IMAGELABEL)
ADD(Link) ADD(K_LINK)
ADD(Table) ADD(K_TABLE)
ADD(TableHeader) ADD(K_TABLEHEADER)
ADD(Italic) ADD(K_ITALIC)
ADD(Bold) ADD(K_BOLD)
ADD(Underline) ADD(K_UNDERLINE)
ADD(Strikethrough) ADD(K_STRIKETHROUGH)
ADD(HorixontalRule) ADD(K_HORIXONTALRULE)
ADD(Tag) ADD(K_TAG)
ADD(Attribute) ADD(K_ATTRIBUTE)
ADD(CheckDone) ADD(K_CHECKDONE)
ADD(CheckNotDone) ADD(K_CHECKNOTDONE)

140
include/syntax/trie.h Normal file
View File

@@ -0,0 +1,140 @@
#ifndef SYNTAX_TRIE_H
#define SYNTAX_TRIE_H
#include "utils/utils.h"
template <typename T> struct Trie {
struct TrieNode {
bool is_word = false;
std::array<TrieNode *, 128> children{};
std::conditional_t<std::is_void_v<T>, char, std::optional<T>> value;
TrieNode() { children.fill(nullptr); }
};
Trie() {}
~Trie() { clear_trie(root); }
void build(const std::vector<std::string> &words, bool cs = true) {
static_assert(std::is_void_v<T>, "This build() is for Trie<void> only");
case_sensitive = cs;
for (auto &w : words)
insert(w);
}
template <typename U = T>
std::enable_if_t<!std::is_void_v<U>>
build(const std::vector<std::pair<std::string, U>> &words, bool cs = true) {
static_assert(!std::is_void_v<T>, "This build() is for typed Trie only");
case_sensitive = cs;
for (auto &[w, v] : words)
insert(w, v);
}
uint32_t match(const char *text, uint32_t pos, uint32_t len,
bool (*is_word_char)(char c)) const {
const TrieNode *node = root;
uint32_t max_len = 0;
for (uint32_t i = pos; i < len; ++i) {
unsigned char uc = static_cast<unsigned char>(text[i]);
if (uc >= 128)
return 0;
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
uc = uc - 'A' + 'a';
if (!node->children[uc]) {
if (node->is_word && !is_word_char(text[i]))
return i - pos;
break;
}
node = node->children[uc];
if (node->is_word)
max_len = i - pos + 1;
}
if (max_len > 0)
if (pos + max_len < len && is_word_char(text[pos + max_len]))
return 0;
return max_len;
}
template <typename U = T>
uint32_t
match(const char *text, uint32_t pos, uint32_t len,
bool (*is_word_char)(char c),
std::conditional_t<std::is_void_v<T>, void *, std::optional<T> *>
out_val = nullptr) const {
const TrieNode *node = root;
const TrieNode *last_word_node = nullptr;
uint32_t max_len = 0;
for (uint32_t i = pos; i < len; ++i) {
unsigned char uc = static_cast<unsigned char>(text[i]);
if (uc >= 128)
break;
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
uc = uc - 'A' + 'a';
if (!node->children[uc])
break;
node = node->children[uc];
if (node->is_word) {
last_word_node = node;
max_len = i - pos + 1;
}
}
if (!last_word_node) {
if (out_val)
*out_val = std::nullopt;
return 0;
}
if (pos + max_len < len && is_word_char(text[pos + max_len])) {
if (out_val)
*out_val = std::nullopt;
return 0;
}
if (out_val)
*out_val = last_word_node->value;
return max_len;
}
private:
TrieNode *root = new TrieNode();
bool case_sensitive = true;
void insert(const std::string &word) {
TrieNode *node = root;
for (char c : word) {
unsigned char uc = static_cast<unsigned char>(c);
if (uc >= 128)
return;
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
uc = uc - 'A' + 'a';
if (!node->children[uc])
node->children[uc] = new TrieNode();
node = node->children[uc];
}
node->is_word = true;
}
template <typename U = T>
std::enable_if_t<!std::is_void_v<U>> insert(const std::string &word,
const U &val) {
TrieNode *node = root;
for (char c : word) {
unsigned char uc = static_cast<unsigned char>(c);
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
uc = uc - 'A' + 'a';
if (!node->children[uc])
node->children[uc] = new TrieNode();
node = node->children[uc];
}
node->is_word = true;
node->value = val;
}
void clear_trie(TrieNode *node) {
if (!node)
return;
for (auto *child : node->children)
clear_trie(child);
delete node;
}
};
#endif

View File

@@ -8,9 +8,13 @@
struct Bar { struct Bar {
Coord screen; Coord screen;
std::string command = ""; std::string command = "";
std::string log_line = "";
uint32_t cursor = 0; uint32_t cursor = 0;
BarLine bar_line;
std::mutex mtx;
Bar(Coord screen) : screen(screen) {} void init(Coord screen) { this->screen = screen; }
void work();
void render(); void render();
void handle(KeyEvent event); void handle(KeyEvent event);
void log(std::string message); void log(std::string message);

View File

@@ -4,9 +4,6 @@
#include "pch.h" #include "pch.h"
template <typename T> struct Queue { template <typename T> struct Queue {
std::queue<T> q;
std::mutex m;
void push(T val) { void push(T val) {
std::lock_guard<std::mutex> lock(m); std::lock_guard<std::mutex> lock(m);
q.push(val); q.push(val);
@@ -32,6 +29,49 @@ template <typename T> struct Queue {
std::lock_guard<std::mutex> lock(m); std::lock_guard<std::mutex> lock(m);
return q.empty(); return q.empty();
} }
private:
std::queue<T> q;
std::mutex m;
};
template <typename T> struct UniqueQueue {
bool push(const T &value) {
std::lock_guard<std::mutex> lock(m);
if (set.contains(value))
return false;
dq.push_back(value);
set.insert(value);
return true;
}
bool pop(T &out) {
std::lock_guard<std::mutex> lock(m);
if (dq.empty())
return false;
out = dq.front();
dq.pop_front();
set.erase(out);
return true;
}
bool empty() const {
std::lock_guard<std::mutex> lock(m);
return dq.empty();
}
void clear() {
std::lock_guard<std::mutex> lock(m);
dq.clear();
set.clear();
}
size_t size() const {
std::lock_guard<std::mutex> lock(m);
return dq.size();
}
private:
std::deque<T> dq;
std::set<T> set;
mutable std::mutex m;
}; };
struct Coord { struct Coord {
@@ -60,11 +100,19 @@ struct Match {
struct Language { struct Language {
std::string name; std::string name;
uint8_t lsp_id; std::string lsp_name;
uint32_t color; uint32_t color;
const char *symbol;
}; };
struct LSP {
std::string command;
std::vector<std::string> args;
};
extern std::unordered_map<std::string, Language> languages;
extern std::unordered_map<std::string, std::string> language_extensions;
extern std::unordered_map<std::string, LSP> lsps;
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(x) ((x) < 0 ? -(x) : (x)) #define ABS(x) ((x) < 0 ? -(x) : (x))
@@ -92,8 +140,10 @@ uint32_t get_visual_col_from_bytes(const char *line, uint32_t len,
uint32_t byte_limit); uint32_t byte_limit);
uint32_t get_bytes_from_visual_col(const char *line, uint32_t len, uint32_t get_bytes_from_visual_col(const char *line, uint32_t len,
uint32_t target_visual_col); uint32_t target_visual_col);
uint32_t utf8_byte_offset_to_utf16(const char *s, uint32_t byte_pos); size_t utf8_offset_to_utf16(const char *utf8, size_t utf8_len,
uint32_t utf16_offset_to_utf8(const char *s, uint32_t utf16_pos); size_t byte_offset);
size_t utf16_offset_to_utf8(const char *utf8, size_t utf8_len,
size_t utf16_offset);
uint8_t utf8_codepoint_width(unsigned char c); uint8_t utf8_codepoint_width(unsigned char c);
void log(const char *fmt, ...); void log(const char *fmt, ...);
@@ -102,8 +152,7 @@ std::string path_abs(const std::string &path_str);
std::string path_to_file_uri(const std::string &path_str); std::string path_to_file_uri(const std::string &path_str);
std::string filename_from_path(const std::string &path); std::string filename_from_path(const std::string &path);
std::string get_exe_dir(); std::string get_exe_dir();
char *load_file(const char *path, uint32_t *out_len); char *load_file(const char *path, uint32_t *out_len, bool *out_eol);
char *detect_file_type(const char *filename);
Language language_for_file(const char *filename); Language language_for_file(const char *filename);
void copy_to_clipboard(const char *text, size_t len); void copy_to_clipboard(const char *text, size_t len);

51
installer.sh Normal file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env sh
set -eu
install() {
BINARY_NAME="crib"
VERSION="v0.0.1-alpha"
BIN_URL="https://git.syedm.dev/SyedM-dev/crib/releases/download/$VERSION/crib"
ldconfig -p | grep libmagic >/dev/null 2>&1
if ! ldconfig -p | grep libmagic >/dev/null 2>&1; then
echo "Missing dependency: libmagic (part of \`file\` package)"
echo "Install them using your package manager:"
echo "Ubuntu/Debian: sudo apt install ruby libmagic1"
echo "Arch: sudo pacman -S file"
echo "Void: sudo xbps-install -Sy file"
exit 1
fi
echo "Install locally (~/.local/bin) or globally (/usr/bin)? [l/g]"
read -r choice </dev/tty
case "$choice" in
l | L)
INSTALL_DIR="$HOME/.local/bin"
SUDO=""
;;
g | G)
INSTALL_DIR="/usr/bin"
SUDO="sudo"
;;
*)
echo "Invalid choice"
exit 1
;;
esac
$SUDO mkdir -p "$INSTALL_DIR"
echo "Downloading binary..."
curl -L "$BIN_URL" -o /tmp/"$BINARY_NAME"
$SUDO install -m 755 /tmp/"$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
rm -f /tmp/"$BINARY_NAME"
echo
echo "✔ Crib installed to $INSTALL_DIR"
echo "Run with: $BINARY_NAME"
echo "Add $INSTALL_DIR to PATH if needed."
}
install "$@"

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# --------------------------------------------- # ----------------------------------------------
# Bash Syntax Highlighter Test Specification # Bash Syntax Highlighter Test Specification
# --------------------------------------------- # ----------------------------------------------
VERSION="1.0.0" VERSION="1.0.0"
declare -a ITEMS=("alpha" "beta" "gamma" "delta") declare -a ITEMS=("alpha" "beta" "gamma" "delta")
@@ -22,6 +22,7 @@ colorize() {
} }
# Example of error handling # Example of error handling
handle_error() { handle_error() {
log ERROR "An error occurred on line $1" log ERROR "An error occurred on line $1"
} }
@@ -46,7 +47,7 @@ while ((counter < 5)); do
done done
# Subshelled loops and alternating quoting # Subshelled loops and alternating quoting
for item in "${ITEMS[@]}"; do for item in "${ITEMS[@]}}"; do
( (
msg="Processing $item" msg="Processing $item"
echo "$(colorize blue "$msg")" echo "$(colorize blue "$msg")"
@@ -126,7 +127,7 @@ grep "world" <<<"$FOO" >/dev/null && log INFO "FOO contains world"
diff <(echo foo) <(echo foo) >/dev/null && log INFO "diff matched" diff <(echo foo) <(echo foo) >/dev/null && log INFO "diff matched"
# Command substitution with pipeline # Command substitution with pipeline
timestamp=$(date | sed 's/ /_/g') timestamp=$(date | sed 's//_/g')
log INFO "Timestamp: $timestamp" log INFO "Timestamp: $timestamp"
# Testing array slicing # Testing array slicing

View File

@@ -21,6 +21,7 @@ a:focus-visible {
input::placeholder { input::placeholder {
color: #999; color: #999;
background-color: #523;
} }
/* CSS variables */ /* CSS variables */

View File

@@ -117,4 +117,3 @@ local tpl = `Value: ${counter}`
-- Regex-like string (for testing injection highlighting) -- Regex-like string (for testing injection highlighting)
local re = "/^%a+$/" local re = "/^%a+$/"

View File

@@ -12,7 +12,6 @@ NotImplemented
Ellipsis Ellipsis
__name__ # builtin constant __name__ # builtin constant
# ============================== # ==============================
# Imports # Imports
# ============================== # ==============================

View File

@@ -4,52 +4,46 @@
# Purpose: Test syntax highlighting + width calculation in your editor # Purpose: Test syntax highlighting + width calculation in your editor
# --------------------------------------------------------------- # ---------------------------------------------------------------
# Basic output
def greet
puts "Hello, 世界! 👋🌏"
end
# Emoji-heavy strings
emojis = "👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏👋🌏"
# Mixed-width CJKssssssssssssssss LoadErssssssssssssssssssssssss # Mixed-width CJKssssssssssssssss LoadErssssssssssssssssssssssss
cjk_samples = [ cjk_samples = [
"漢字テスト", '漢字テスト',
"測試中文字串", '測試中文字串',
"한국어 테스트", '한국어 테스트',
"ひらがなカタカナ😀混合", 'ひらがなカタカナ混合'
"大量の文字列🚀🚀🚀"
] ]
# Ruby regex with unicode # a hex color: #FFFFFF shouldn't hl here: hsl(147rad, 50%, 47%) as it is not css-style file
$unicode_regex_multiline = /[一-龯ぁ-ん#{0x3000}
\-ヶー
0x603010 # another hex color
# Ruby regex with unicode
$unicode_regex_multiline = /[一-龯ぁ-ん12288ァ
\-ヶー
s wow s wow
々〆〤]/ 々〆〤]/
UNICORE = %r{ UNICORE = /
[s] s
{#{}} {#{ss}}
\C-s\u{10} \C-s\u{10}
} /
UNINITCORE = %{ UNINITCORE = %(
{{#{}}} {{#{}}}
test = "A:\x41 B:\101 C:\u0043 D:\u{44 45} NUL:\0 DEL:\c? CTRL_A:\cA META_X:\M-x CTRL_META_X:\C-\M-x MIX:\C-\M-z N:\N{UNICODE NAME}" test = "A:\x41 B:\101 C:\u0043 D:\u{44 45} NUL:\0 DEL:\c? CTRL_A:\cA META_X:\M-x CTRL_META_X:\C-\M-x MIX:\C-\M-z N:\N{UNICODE NAME}"
} )
# Unicode identifiers (valid in Ruby) # Unicode identifiers (valid in Ruby)
= 0x5_4eddaee = 0x5_4eddaee
π = 3.14_159e+2, ?\u0234, ?\,, ?\x0A, ?s, true, false, 0 π = 0.314_159e+2, ?\u0234, "\,", ?\x0A, 's', true, false, 0
= -> { "こんに \n ちは" } = -> { "こんに \n ちは" }
arr = Array.new() arr = []
not_arr = NotArray.new() not_arr = NotABuiltin.new
raise NameError or SystemExit or CustomError or Errno or ErrorNotAtAll raise NameError or SystemExit or CustomError or Errno or ErrorNotAtAll
@@ -60,7 +54,7 @@ end
# Iterate through CJK samples # Iterate through CJK samples
cjk_samples.each_with_index do |str, idx:| cjk_samples.each_with_index do |str, idx:|
puts %Q! CJK[#{idx}] => #{str} (len=#{str.length})\! ! puts %! CJK[#{idx}] => #{str} (len=#{str.length})\! !
symbol = :" symbol = :"
a a
" "
@@ -71,7 +65,7 @@ end
puts "Emoji count: #{emojis.length}" puts "Emoji count: #{emojis.length}"
# Multi-line string with unicode # Multi-line string with unicode
multi = <<BASH multi = <<~BASH
# Function recursion demo # Function recursion demo
factorial() { factorial() {
local n="$1" local n="$1"
@@ -82,11 +76,11 @@ multi = <<BASH
prev=$(factorial $((n - 1))) prev=$(factorial $((n - 1)))
echo $((n * prev)) echo $((n * prev))
before #{ interpol before #{ interpol
# {' '}
# comment should be fine heres s # comment should be fine heres s
$a / $-s+0xFF $a / $-s + 0xFF
}s }s#{' '}
x x
a after a after
fi fi
} #{s} } #{s}
@@ -95,21 +89,23 @@ BASH
puts multi puts multi
# Arrays mixing everything # Arrays mixing everything
mixed = [ mixed = [
"🐍 Ruby + Python? sacrilege! 🐍", '🐍 Ruby + Python? sacrilege! 🐍',
"日本語とEnglishと🔧mix", '日本語とEnglishと🔧mix',
"Spacing test →→→→→→→", 'Spacing test →→→→→→→',
"Zero-width joiner test: 👨‍👩‍👧‍👦 family emoji", 'Zero-width joiner test: 👨‍👩‍👧‍👦 family emoji'
] ]
two_docs = <<DOC1 , <<DOC2 two_docs = <<~DOC1, <<~DOC2
stuff for doc2 stuff for doc2
rdvajehvbaejbfh
DOC1 DOC1
stuff for doc 2 with \#{not interpolation} and more stuff for doc 2 with #{!interpolation} and more
DOC2 DOC2
p = 0 <<22 # not a heredoc p = 0 << 22 # not a heredoc
mixed.each { |m| puts m } mixed.each { |m| puts m }
@@ -126,10 +122,10 @@ end
escaped = "Line1\nLine2\tTabbed 😀" escaped = "Line1\nLine2\tTabbed 😀"
puts escaped puts escaped
p = 0 <<2 p = 0 << 2
# Frozen string literal test # Frozen string literal test
# frozen_string_literal: true # frozen_string_literal: true
const_str = "定数文字列🔒".freeze const_str = '定数文字列🔒'.freeze
puts const_str puts const_str
# End marker # End marker
@@ -137,30 +133,26 @@ puts '--- END OF UNICODE TEST FILE ---'
# Ruby syntax highlighting test # Ruby syntax highlighting test
=begin # This is a multi-line comment.
This is a multi-line comment. # It spans multiple lines.
It spans multiple lines. # Good for testing highlighting.
Good for testing highlighting. #
# This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped linetest,
This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped linetest, #
=end
# Constants # Constants
__END_
PI = 3.14159 PI = 3.14159
MAX_ITER = 5 MAX_ITER = 5
# Module # Module
module Utilities module Utilities
def self.random_greeting def self.random_greeting
["Hello", "Hi", "Hey", "Hola", "Bonjour", "Merhaba"].sample %w[Hello Hi Hey Hola Bonjour Merhaba].sample
end end
def self.factorial(n) def self.factorial(n)
return 1 if n <= 1 return 1 if n <= 1
n * factorial(n - 1) n * factorial(n - 1)
end end
end end
@@ -221,18 +213,16 @@ end
# Method definition # Method definition
def greet_person(name) def greet_person(name)
puts "#{Utilities.random_greeting}, #{name}!" puts "#{Utilities.random_greeting}, #{name}!"
if (name == "harry") return true if name == 'harry'
return true
else 's'
return "s"
end
end end
h = a / a h = a / a
# Calling methods # Calling methods
greet_person("Alice") greet_person('Alice')
greet_person("Bob") greet_person('Bob')
# Loops # Loops
i = 0 i = 0
@@ -252,7 +242,7 @@ begin
rescue ZeroDivisionError => e rescue ZeroDivisionError => e
puts "Caught an error: #{e}" puts "Caught an error: #{e}"
ensure ensure
puts "This runs no matter what" puts 'This runs no matter what'
end end
# Arrays of objects # Arrays of objects
@@ -288,7 +278,7 @@ end
end end
# Special objects # Special objects
so = SpecialObject.new("Special", 10) so = SpecialObject.new('Special', 10)
puts "Double: #{so.double_value}, Triple: #{so.triple_value}" puts "Double: #{so.double_value}, Triple: #{so.triple_value}"
# String interpolation and formatting # String interpolation and formatting
@@ -299,8 +289,8 @@ multi_line = <<~TEXT
k kmW ; k kmW ;
This is a multi-line string. This is a multi-line string.
It spans multiple lines. It spans multiple lines.
Gossn m Gossn sssmss
dd ddsss
od for testing highlighting. od for testing highlighting.
TEXT TEXT
@@ -308,7 +298,7 @@ puts multi_line
# Symbols and strings # Symbols and strings
sym = :my_symbol == __dir__ sym = :my_symbol == __dir__
str = "my string" str = 'my string'
puts "Symbol: #{sym}, String: #{str}" puts "Symbol: #{sym}, String: #{str}"
# Random numbers # Random numbers
@@ -327,25 +317,25 @@ end
# Block with yield # Block with yield
def wrapper def wrapper
puts "Before block" puts 'Before block'
yield if block_given? yield if block_given?
puts "After block" puts 'After block'
end end
# ss # ss
wrapper { puts "Inside block" } wrapper { puts 'Inside block' }
# Sorting # Sorting
sorted = rand_nums.sort sorted = rand_nums.sort
puts "Sorted: #{sorted.join(', ')}" puts "Sorted: #{sorted.join(', ')}"
# Regex # Regex
sample_text = "The quick brown fox jumps over the lazy dog" sample_text = 'The quick brown fox jumps over the lazy dog'
puts "Match 'fox'?" if sample_text =~ /fox/ puts "Match 'fox'?" if sample_text =~ /fox/
# End of test script # End of test script
puts "Ruby syntax highlighting test complete." puts 'Ruby syntax highlighting test complete.'
__END__ __END__

View File

@@ -1 +0,0 @@
# kitty @ --to="$KITTY_LISTEN_ON" set-spacing padding=8 margin=0 2>/dev/null || true

View File

@@ -1 +0,0 @@
# kitty @ --to="$KITTY_LISTEN_ON" set-spacing padding=0 margin=0 2>/dev/null || true

View File

@@ -12,20 +12,36 @@ inline static std::string completion_prefix(Editor *editor) {
if (hook.row != cur.row || cur.col < hook.col) if (hook.row != cur.row || cur.col < hook.col)
return ""; return "";
LineIterator *it = begin_l_iter(editor->root, hook.row); LineIterator *it = begin_l_iter(editor->root, hook.row);
char *line = next_line(it, nullptr); uint32_t line_len;
char *line = next_line(it, &line_len);
if (!line) { if (!line) {
free(it->buffer); free(it->buffer);
free(it); free(it);
return ""; return "";
} }
uint32_t start = utf16_offset_to_utf8(line, hook.col); std::string prefix(line + hook.col, cur.col - hook.col);
uint32_t end = editor->cursor.col;
std::string prefix(line + start, end - start);
free(it->buffer); free(it->buffer);
free(it); free(it);
return prefix; return prefix;
} }
inline static void completion_adjust_scroll(CompletionSession &s) {
if (s.visible.empty())
return;
int vi = -1;
for (size_t i = 0; i < s.visible.size(); i++)
if (s.visible[i] == s.select) {
vi = (int)i;
break;
}
if (vi < 0)
return;
if ((uint32_t)vi < s.scroll)
s.scroll = vi;
else if ((uint32_t)vi >= s.scroll + 8)
s.scroll = vi - 7;
}
void completion_filter(Editor *editor) { void completion_filter(Editor *editor) {
auto &session = editor->completion; auto &session = editor->completion;
std::string prefix = completion_prefix(editor); std::string prefix = completion_prefix(editor);
@@ -45,6 +61,8 @@ void completion_filter(Editor *editor) {
session.select) == session.visible.end()) session.select) == session.visible.end())
session.select = session.visible[0]; session.select = session.visible[0];
session.box.hidden = false; session.box.hidden = false;
session.scroll = 0;
completion_adjust_scroll(session);
session.box.render_update(); session.box.render_update();
} }
@@ -212,13 +230,14 @@ void completion_request(Editor *editor) {
}; };
std::shared_lock lock(editor->knot_mtx); std::shared_lock lock(editor->knot_mtx);
LineIterator *it = begin_l_iter(editor->root, hook.row); LineIterator *it = begin_l_iter(editor->root, hook.row);
char *line = next_line(it, nullptr); uint32_t length;
char *line = next_line(it, &length);
if (!line) { if (!line) {
free(it->buffer); free(it->buffer);
free(it); free(it);
return; return;
} }
uint32_t col = utf8_byte_offset_to_utf16(line, editor->cursor.col); uint32_t col = utf8_offset_to_utf16(line, length, editor->cursor.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
lock.unlock(); lock.unlock();
@@ -417,6 +436,7 @@ void complete_next(Editor *editor) {
vi = (vi + 1) % s.visible.size(); vi = (vi + 1) % s.visible.size();
s.select = s.visible[vi]; s.select = s.visible[vi];
completion_resolve_doc(editor); completion_resolve_doc(editor);
completion_adjust_scroll(editor->completion);
editor->completion.box.render_update(); editor->completion.box.render_update();
} }
@@ -431,6 +451,7 @@ void complete_prev(Editor *editor) {
vi = (vi + s.visible.size() - 1) % s.visible.size(); vi = (vi + s.visible.size() - 1) % s.visible.size();
s.select = s.visible[vi]; s.select = s.visible[vi];
completion_resolve_doc(editor); completion_resolve_doc(editor);
completion_adjust_scroll(editor->completion);
editor->completion.box.render_update(); editor->completion.box.render_update();
} }

View File

@@ -1,7 +1,6 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "lsp/lsp.h" #include "lsp/lsp.h"
#include "utils/utils.h" #include "utils/utils.h"
#include <cstdint>
void edit_erase(Editor *editor, Coord pos, int64_t len) { void edit_erase(Editor *editor, Coord pos, int64_t len) {
if (len == 0) if (len == 0)
@@ -17,17 +16,18 @@ void edit_erase(Editor *editor, Coord pos, int64_t len) {
bool do_lsp = (editor->lsp != nullptr); bool do_lsp = (editor->lsp != nullptr);
if (do_lsp) { if (do_lsp) {
LineIterator *it = begin_l_iter(editor->root, point.row); LineIterator *it = begin_l_iter(editor->root, point.row);
char *line = next_line(it, nullptr); uint32_t len;
char *line = next_line(it, &len);
int utf16_start = 0; int utf16_start = 0;
if (line) if (line)
utf16_start = utf8_byte_offset_to_utf16(line, point.col); utf16_start = utf8_offset_to_utf16(line, len, point.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
it = begin_l_iter(editor->root, pos.row); it = begin_l_iter(editor->root, pos.row);
line = next_line(it, nullptr); line = next_line(it, &len);
int utf16_end = 0; int utf16_end = 0;
if (line) if (line)
utf16_end = utf8_byte_offset_to_utf16(line, pos.col); utf16_end = utf8_offset_to_utf16(line, len, pos.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
lsp_range = {{"start", {{"line", point.row}, {"character", utf16_start}}}, lsp_range = {{"start", {{"line", point.row}, {"character", utf16_start}}},
@@ -52,7 +52,7 @@ void edit_erase(Editor *editor, Coord pos, int64_t len) {
editor->root = erase(editor->root, start, byte_pos - start); editor->root = erase(editor->root, start, byte_pos - start);
lock_2.unlock(); lock_2.unlock();
if (editor->parser) if (editor->parser)
editor->parser->edit(editor->root, start_row, end_row, start_row); editor->parser->edit(start_row, end_row, 0);
if (do_lsp) { if (do_lsp) {
if (editor->lsp->incremental_sync) { if (editor->lsp->incremental_sync) {
json message = { json message = {
@@ -89,17 +89,18 @@ void edit_erase(Editor *editor, Coord pos, int64_t len) {
bool do_lsp = (editor->lsp != nullptr); bool do_lsp = (editor->lsp != nullptr);
if (do_lsp) { if (do_lsp) {
LineIterator *it = begin_l_iter(editor->root, pos.row); LineIterator *it = begin_l_iter(editor->root, pos.row);
char *line = next_line(it, nullptr); uint32_t line_len;
char *line = next_line(it, &line_len);
int utf16_start = 0; int utf16_start = 0;
if (line) if (line)
utf16_start = utf8_byte_offset_to_utf16(line, pos.col); utf16_start = utf8_offset_to_utf16(line, line_len, pos.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
it = begin_l_iter(editor->root, point.row); it = begin_l_iter(editor->root, point.row);
line = next_line(it, nullptr); line = next_line(it, &line_len);
int utf16_end = 0; int utf16_end = 0;
if (line) if (line)
utf16_end = utf8_byte_offset_to_utf16(line, point.col); utf16_end = utf8_offset_to_utf16(line, line_len, point.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
lsp_range = {{"start", {{"line", pos.row}, {"character", utf16_start}}}, lsp_range = {{"start", {{"line", pos.row}, {"character", utf16_start}}},
@@ -124,7 +125,7 @@ void edit_erase(Editor *editor, Coord pos, int64_t len) {
editor->root = erase(editor->root, byte_pos, end - byte_pos); editor->root = erase(editor->root, byte_pos, end - byte_pos);
lock_2.unlock(); lock_2.unlock();
if (editor->parser) if (editor->parser)
editor->parser->edit(editor->root, start_row, end_row, start_row); editor->parser->edit(start_row, end_row, 0);
if (do_lsp) { if (do_lsp) {
if (editor->lsp->incremental_sync) { if (editor->lsp->incremental_sync) {
json message = { json message = {
@@ -165,6 +166,14 @@ void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len) {
uint32_t new_row = byte_to_line(editor->root, cursor_new, &new_col); uint32_t new_row = byte_to_line(editor->root, cursor_new, &new_col);
editor->cursor = {new_row, new_col}; editor->cursor = {new_row, new_col};
} }
LineIterator *it = begin_l_iter(editor->root, pos.row);
uint32_t line_len;
char *line = next_line(it, &line_len);
int utf16_col = 0;
if (line)
utf16_col = utf8_offset_to_utf16(line, line_len, pos.col);
free(it->buffer);
free(it);
lock_1.unlock(); lock_1.unlock();
std::unique_lock lock_2(editor->knot_mtx); std::unique_lock lock_2(editor->knot_mtx);
editor->root = insert(editor->root, byte_pos, data, len); editor->root = insert(editor->root, byte_pos, data, len);
@@ -175,18 +184,9 @@ void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len) {
apply_hook_insertion(editor, pos.row, rows); apply_hook_insertion(editor, pos.row, rows);
lock_2.unlock(); lock_2.unlock();
if (editor->parser) if (editor->parser)
editor->parser->edit(editor->root, pos.row, pos.row, pos.row + rows); editor->parser->edit(pos.row, pos.row, rows);
if (editor->lsp) { if (editor->lsp) {
if (editor->lsp->incremental_sync) { if (editor->lsp->incremental_sync) {
lock_1.lock();
LineIterator *it = begin_l_iter(editor->root, pos.row);
char *line = next_line(it, nullptr);
int utf16_col = 0;
if (line)
utf16_col = utf8_byte_offset_to_utf16(line, pos.col);
free(it->buffer);
free(it);
lock_1.unlock();
json message = { json message = {
{"jsonrpc", "2.0"}, {"jsonrpc", "2.0"},
{"method", "textDocument/didChange"}, {"method", "textDocument/didChange"},
@@ -218,19 +218,63 @@ void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len) {
void edit_replace(Editor *editor, Coord start, Coord end, const char *text, void edit_replace(Editor *editor, Coord start, Coord end, const char *text,
uint32_t len) { uint32_t len) {
std::shared_lock lock(editor->knot_mtx); std::unique_lock lock(editor->knot_mtx);
uint32_t start_byte = uint32_t start_byte =
line_to_byte(editor->root, start.row, nullptr) + start.col; line_to_byte(editor->root, start.row, nullptr) + start.col;
uint32_t end_byte = line_to_byte(editor->root, end.row, nullptr) + end.col; uint32_t end_byte = line_to_byte(editor->root, end.row, nullptr) + end.col;
char *buf = read(editor->root, start_byte, end_byte - start_byte); LineIterator *it = begin_l_iter(editor->root, start.row);
if (!buf) uint32_t line_len;
return; char *line = next_line(it, &line_len);
lock.unlock(); int utf16_start = 0;
uint32_t erase_len = if (line)
count_clusters(buf, end_byte - start_byte, 0, end_byte - start_byte); utf16_start = utf8_offset_to_utf16(line, line_len, start.col);
free(buf); free(it->buffer);
if (erase_len != 0) free(it);
edit_erase(editor, start, erase_len); it = begin_l_iter(editor->root, end.row);
line = next_line(it, &line_len);
int utf16_end = 0;
if (line)
utf16_end = utf8_offset_to_utf16(line, line_len, end.col);
free(it->buffer);
free(it);
if (start_byte != end_byte)
editor->root = erase(editor->root, start_byte, end_byte - start_byte);
if (len > 0) if (len > 0)
edit_insert(editor, start, const_cast<char *>(text), len); editor->root = insert(editor->root, start_byte, (char *)text, len);
uint32_t rows = 0;
for (uint32_t i = 0; i < len; i++)
if (text[i] == '\n')
rows++;
if (editor->parser)
editor->parser->edit(start.row, end.row - 1, rows);
if (editor->lsp) {
if (editor->lsp->incremental_sync) {
json message = {
{"jsonrpc", "2.0"},
{"method", "textDocument/didChange"},
{"params",
{{"textDocument",
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
{"contentChanges",
json::array(
{{{"range",
{{"start",
{{"line", start.row}, {"character", utf16_start}}},
{"end", {{"line", end.row}, {"character", utf16_end}}}}},
{"text", std::string(text, len)}}})}}}};
lsp_send(editor->lsp, message, nullptr);
} else {
char *buf = read(editor->root, 0, editor->root->char_count);
std::string full_text(buf);
free(buf);
json message = {
{"jsonrpc", "2.0"},
{"method", "textDocument/didChange"},
{"params",
{{"textDocument",
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
{"contentChanges", json::array({{{"text", full_text}}})}}}};
lsp_send(editor->lsp, message, nullptr);
}
}
} }

View File

@@ -1,20 +1,26 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "editor/decl.h" #include "editor/decl.h"
#include "lsp/lsp.h" #include "lsp/lsp.h"
#include "main.h"
#include "syntax/langs.h"
#include "utils/utils.h" #include "utils/utils.h"
#include <shared_mutex>
Editor *new_editor(const char *filename_arg, Coord position, Coord size) { Editor *new_editor(const char *filename_arg, Coord position, Coord size,
uint8_t eol) {
Editor *editor = new Editor(); Editor *editor = new Editor();
if (!editor) if (!editor)
return nullptr; return nullptr;
uint32_t len = 0; uint32_t len = 0;
std::string filename = path_abs(filename_arg); std::string filename = path_abs(filename_arg);
char *str = load_file(filename.c_str(), &len); editor->unix_eol = eol & 1;
char *str = load_file(filename.c_str(), &len, &editor->unix_eol);
if (!str) { if (!str) {
free_editor(editor); str = (char *)malloc(1);
return nullptr; *str = '\n';
len = 1;
} }
if ((eol >> 1) & 1)
editor->unix_eol = eol & 1;
editor->filename = filename; editor->filename = filename;
editor->uri = path_to_file_uri(filename); editor->uri = path_to_file_uri(filename);
editor->position = position; editor->position = position;
@@ -29,9 +35,12 @@ Editor *new_editor(const char *filename_arg, Coord position, Coord size) {
editor->root = load(str, len, optimal_chunk_size(len)); editor->root = load(str, len, optimal_chunk_size(len));
free(str); free(str);
editor->lang = language_for_file(filename.c_str()); editor->lang = language_for_file(filename.c_str());
if (editor->lang.name != "unknown") if (parsers.find(editor->lang.name) != parsers.end())
editor->parser = new Parser(editor->root, &editor->knot_mtx, editor->parser = new Parser(editor, editor->lang.name, size.row + 5);
editor->lang.name, size.row + 5); if (editor->lang.name == "css" || editor->lang.name == "html" ||
editor->lang.name == "javascript" || editor->lang.name == "markdown" ||
editor->lang.name == "typescript")
editor->is_css_color = true;
if (len <= (1024 * 28)) if (len <= (1024 * 28))
request_add_to_lsp(editor->lang, editor); request_add_to_lsp(editor->lang, editor);
editor->indents.compute_indent(editor); editor->indents.compute_indent(editor);
@@ -52,14 +61,25 @@ void save_file(Editor *editor) {
return; return;
std::shared_lock lock(editor->knot_mtx); std::shared_lock lock(editor->knot_mtx);
int version = editor->lsp_version; int version = editor->lsp_version;
char *str = read(editor->root, 0, editor->root->char_count); uint32_t char_count = editor->root->char_count;
char *str = read(editor->root, 0, char_count);
if (!str) if (!str)
return; return;
lock.unlock(); lock.unlock();
std::ofstream out(editor->filename); std::ofstream out(editor->filename);
out.write(str, editor->root->char_count); if (!editor->unix_eol) {
for (uint32_t i = 0; i < char_count; ++i) {
if (str[i] == '\n')
out.put('\r');
out.put(str[i]);
}
} else {
out.write(str, char_count);
}
out.close(); out.close();
free(str); free(str);
bar.log("Written " + std::to_string(char_count) + " bytes to " +
editor->filename);
if (editor->lsp) { if (editor->lsp) {
json save_msg = {{"jsonrpc", "2.0"}, json save_msg = {{"jsonrpc", "2.0"},
{"method", "textDocument/didSave"}, {"method", "textDocument/didSave"},
@@ -99,12 +119,22 @@ void save_file(Editor *editor) {
apply_lsp_edits(editor, t_edits, false); apply_lsp_edits(editor, t_edits, false);
ensure_scroll(editor); ensure_scroll(editor);
std::shared_lock lock(editor->knot_mtx); std::shared_lock lock(editor->knot_mtx);
char *str = read(editor->root, 0, editor->root->char_count); uint32_t char_count = editor->root->char_count;
char *str = read(editor->root, 0, char_count);
if (!str) if (!str)
return; return;
lock.unlock(); lock.unlock();
std::ofstream out(editor->filename); std::ofstream out(editor->filename);
out.write(str, editor->root->char_count); if (!editor->unix_eol) {
for (uint32_t i = 0; i < char_count; ++i) {
if (str[i] == '\n')
out.put('\r');
out.put(str[i]);
}
} else {
out.write(str, char_count);
}
out.close();
free(str); free(str);
lsp_send(editor->lsp, save_msg, nullptr); lsp_send(editor->lsp, save_msg, nullptr);
} }

View File

@@ -1,147 +1,14 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "lsp/lsp.h" #include "editor/helpers.h"
#include "io/sysio.h"
#include "main.h" #include "main.h"
#include "utils/utils.h" #include "utils/utils.h"
void handle_editor_event(Editor *editor, KeyEvent event) { void handle_editor_event(Editor *editor, KeyEvent event) {
static std::chrono::steady_clock::time_point last_click_time =
std::chrono::steady_clock::now();
static uint32_t click_count = 0;
static Coord last_click_pos = {UINT32_MAX, UINT32_MAX};
Coord start = editor->cursor;
uint8_t old_mode = mode; uint8_t old_mode = mode;
if (editor->hover_active) if (editor->hover_active)
editor->hover_active = false; editor->hover_active = false;
if (event.key_type == KEY_MOUSE) { handle_mouse(editor, event);
auto now = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
now - last_click_time)
.count();
switch (event.mouse_state) {
case SCROLL:
switch (event.mouse_direction) {
case SCROLL_UP:
scroll_up(editor, 4);
ensure_cursor(editor);
break;
case SCROLL_DOWN:
scroll_down(editor, 4);
ensure_cursor(editor);
break;
case SCROLL_LEFT:
cursor_left(editor, 10);
break;
case SCROLL_RIGHT:
cursor_right(editor, 10);
break;
}
break;
case PRESS:
if (event.mouse_button == LEFT_BTN) {
Coord cur_pos = {event.mouse_x, event.mouse_y};
if (duration < 250 && last_click_pos == cur_pos)
click_count++;
else
click_count = 1;
last_click_time = now;
last_click_pos = cur_pos;
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
return;
editor->cursor_preffered = UINT32_MAX;
if (click_count == 1) {
editor->cursor = p;
editor->selection = p;
if (mode == SELECT) {
mode = NORMAL;
editor->selection_active = false;
}
} else if (click_count == 2) {
uint32_t prev_col, next_col;
word_boundaries(editor, editor->cursor, &prev_col, &next_col, nullptr,
nullptr);
if (editor->cursor < editor->selection)
editor->cursor = {editor->cursor.row, prev_col};
else
editor->cursor = {editor->cursor.row, next_col};
editor->cursor_preffered = UINT32_MAX;
editor->selection_type = WORD;
mode = SELECT;
editor->selection_active = true;
} else if (click_count >= 3) {
if (editor->cursor < editor->selection) {
editor->cursor = {p.row, 0};
} else {
uint32_t line_len;
LineIterator *it = begin_l_iter(editor->root, p.row);
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
free(it->buffer);
free(it);
editor->cursor = {p.row, line_len};
}
editor->cursor_preffered = UINT32_MAX;
editor->selection_type = LINE;
mode = SELECT;
editor->selection_active = true;
click_count = 3;
}
}
break;
case DRAG:
if (event.mouse_button == LEFT_BTN) {
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
return;
editor->cursor_preffered = UINT32_MAX;
mode = SELECT;
if (!editor->selection_active) {
editor->selection_active = true;
editor->selection_type = CHAR;
}
uint32_t prev_col, next_col, line_len;
switch (editor->selection_type) {
case CHAR:
editor->cursor = p;
break;
case WORD:
word_boundaries(editor, p, &prev_col, &next_col, nullptr, nullptr);
if (editor->cursor < editor->selection)
editor->cursor = {p.row, prev_col};
else
editor->cursor = {p.row, next_col};
break;
case LINE:
if (editor->cursor < editor->selection) {
editor->cursor = {p.row, 0};
} else {
LineIterator *it = begin_l_iter(editor->root, p.row);
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
free(it->buffer);
free(it);
editor->cursor = {p.row, line_len};
}
break;
}
}
break;
case RELEASE:
if (event.mouse_button == LEFT_BTN)
if (editor->cursor.row == editor->selection.row &&
editor->cursor.col == editor->selection.col) {
mode = NORMAL;
editor->selection_active = false;
}
break;
}
}
if (event.key_type == KEY_SPECIAL) { if (event.key_type == KEY_SPECIAL) {
switch (event.special_modifier) { switch (event.special_modifier) {
case 0: case 0:
@@ -161,9 +28,6 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
} }
break; break;
case CNTRL: case CNTRL:
uint32_t prev_col, next_col;
word_boundaries(editor, editor->cursor, &prev_col, &next_col, nullptr,
nullptr);
switch (event.special_key) { switch (event.special_key) {
case KEY_DOWN: case KEY_DOWN:
cursor_down(editor, 5); cursor_down(editor, 5);
@@ -172,18 +36,9 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
cursor_up(editor, 5); cursor_up(editor, 5);
break; break;
case KEY_LEFT: case KEY_LEFT:
editor->cursor_preffered = UINT32_MAX; cursor_prev_word(editor);
if (prev_col == editor->cursor.col)
cursor_left(editor, 1);
else
editor->cursor = {editor->cursor.row, prev_col};
break;
case KEY_RIGHT: case KEY_RIGHT:
editor->cursor_preffered = UINT32_MAX; cursor_next_word(editor);
if (next_col == editor->cursor.col)
cursor_right(editor, 1);
else
editor->cursor = {editor->cursor.row, next_col};
break; break;
} }
break; break;
@@ -210,27 +65,7 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
if (event.key_type == KEY_CHAR && event.len == 1) { if (event.key_type == KEY_CHAR && event.len == 1) {
switch (event.c[0]) { switch (event.c[0]) {
case 'u': case 'u':
if (editor->root->line_count > 0) { select_all(editor);
editor->cursor.row = editor->root->line_count - 1;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
break;
uint32_t line_len;
char *line = next_line(it, &line_len);
if (!line)
break;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
line_len = count_clusters(line, line_len, 0, line_len);
free(it->buffer);
free(it);
editor->cursor.col = line_len;
editor->cursor_preffered = UINT32_MAX;
mode = SELECT;
editor->selection_active = true;
editor->selection = {0, 0};
editor->selection_type = LINE;
}
break; break;
case CTRL('h'): case CTRL('h'):
editor->hover.scroll(-1); editor->hover.scroll(-1);
@@ -241,68 +76,15 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
editor->hover_active = true; editor->hover_active = true;
break; break;
case 'h': case 'h':
if (editor->lsp && editor->lsp->allow_hover) { fetch_lsp_hover(editor);
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
char *line = next_line(it, nullptr);
if (!line) {
free(it->buffer);
free(it);
break; break;
} case 'a': {
uint32_t col = utf8_byte_offset_to_utf16(line, editor->cursor.col);
free(it->buffer);
free(it);
json hover_request = {
{"jsonrpc", "2.0"},
{"method", "textDocument/hover"},
{"params",
{{"textDocument", {{"uri", editor->uri}}},
{"position",
{{"line", editor->cursor.row}, {"character", col}}}}}};
LSPPending *pending = new LSPPending();
pending->editor = editor;
pending->method = "textDocument/hover";
pending->callback = [](Editor *editor, std::string, json hover) {
if (hover.contains("result") && !hover["result"].is_null()) {
auto &contents = hover["result"]["contents"];
std::string hover_text = "";
bool is_markup = false;
if (contents.is_object()) {
hover_text += contents["value"].get<std::string>();
is_markup = (contents["kind"].get<std::string>() == "markdown");
} else if (contents.is_array()) {
for (auto &block : contents) {
if (block.is_string()) {
hover_text += block.get<std::string>() + "\n";
} else if (block.is_object() && block.contains("language") &&
block.contains("value")) {
std::string lang = block["language"].get<std::string>();
std::string val = block["value"].get<std::string>();
is_markup = true;
hover_text += "```" + lang + "\n" + val + "\n```\n";
}
}
} else if (contents.is_string()) {
hover_text += contents.get<std::string>();
}
if (!hover_text.empty()) {
editor->hover.clear();
editor->hover.text = clean_text(hover_text);
editor->hover.is_markup = is_markup;
editor->hover.render_first();
editor->hover_active = true;
}
}
};
lsp_send(editor->lsp, hover_request, pending);
}
break;
case 'a':
mode = INSERT; mode = INSERT;
Coord start = editor->cursor;
cursor_right(editor, 1); cursor_right(editor, 1);
if (start.row != editor->cursor.row) if (start.row != editor->cursor.row)
cursor_left(editor, 1); cursor_left(editor, 1);
break; } break;
case 'i': case 'i':
mode = INSERT; mode = INSERT;
break; break;
@@ -315,11 +97,7 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
editor->jumper_set = false; editor->jumper_set = false;
break; break;
case 'N': case 'N':
for (uint8_t i = 0; i < 94; i++) clear_hooks_at_line(editor, editor->cursor.row);
if (editor->hooks[i] == editor->cursor.row + 1) {
editor->hooks[i] = 0;
break;
}
break; break;
case 's': case 's':
case 'v': case 'v':
@@ -355,29 +133,18 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
ensure_cursor(editor); ensure_cursor(editor);
break; break;
case '>': case '>':
case '.': { case '.':
uint32_t delta = editor->indents.indent_line(editor->cursor.row); indent_current_line(editor);
editor->cursor.col = start.col + delta; break;
editor->cursor.row = start.row;
} break;
case '<': case '<':
case ',': { case ',':
uint32_t delta = editor->indents.dedent_line(editor->cursor.row); dedent_current_line(editor);
editor->cursor.col = MAX((int64_t)start.col - delta, 0); break;
editor->cursor.row = start.row;
} break;
case CTRL('s'): case CTRL('s'):
save_file(editor); save_file(editor);
break; break;
case 'p': case 'p':
uint32_t len; paste(editor);
char *text = get_from_clipboard(&len);
if (text) {
edit_insert(editor, editor->cursor, text, len);
uint32_t grapheme_len = count_clusters(text, len, 0, len);
cursor_right(editor, grapheme_len);
free(text);
}
break; break;
} }
} }
@@ -391,156 +158,13 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
} else if (event.c[0] == '\n' || event.c[0] == '\r') { } else if (event.c[0] == '\n' || event.c[0] == '\r') {
editor->indents.insert_new_line(editor->cursor); editor->indents.insert_new_line(editor->cursor);
} else if (event.c[0] == CTRL('W')) { } else if (event.c[0] == CTRL('W')) {
uint32_t prev_col_byte, prev_col_cluster; delete_prev_word(editor);
word_boundaries(editor, editor->cursor, &prev_col_byte, nullptr,
&prev_col_cluster, nullptr);
if (prev_col_byte == editor->cursor.col)
edit_erase(editor, editor->cursor, -1);
else
edit_erase(editor, editor->cursor, -(int64_t)prev_col_cluster);
} else if (isprint((unsigned char)(event.c[0]))) { } else if (isprint((unsigned char)(event.c[0]))) {
char c = event.c[0]; insert_char(editor, event.c[0]);
uint32_t col = editor->cursor.col;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
uint32_t len;
char *line = next_line(it, &len);
if (!line) {
free(it->buffer);
free(it);
return;
}
bool skip_insert = false;
if (line && col < len) {
char next = line[col];
if ((c == '}' && next == '}') || (c == ')' && next == ')') ||
(c == ']' && next == ']') || (c == '"' && next == '"') ||
(c == '\'' && next == '\'')) {
cursor_right(editor, 1);
skip_insert = true;
}
}
free(it->buffer);
free(it);
if (!skip_insert) {
char closing = 0;
switch (c) {
case '{':
closing = '}';
break;
case '(':
closing = ')';
break;
case '[':
closing = ']';
break;
case '"':
closing = '"';
break;
case '\'':
closing = '\'';
break;
}
if (closing) {
char pair[2] = {c, closing};
edit_insert(editor, editor->cursor, pair, 2);
cursor_right(editor, 1);
} else {
edit_insert(editor, editor->cursor, &c, 1);
cursor_right(editor, 1);
}
if (editor->lsp && editor->lsp->allow_formatting_on_type) {
for (char ch : editor->lsp->format_chars) {
if (ch == c) {
LineIterator *it =
begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
char *line = next_line(it, nullptr);
if (!line) {
free(it->buffer);
free(it);
return;
}
uint32_t col =
utf8_byte_offset_to_utf16(line, editor->cursor.col);
free(it->buffer);
free(it);
int version = editor->lsp_version;
json message = {
{"jsonrpc", "2.0"},
{"method", "textDocument/onTypeFormatting"},
{"params",
{{"textDocument", {{"uri", editor->uri}}},
{"position",
{{"line", editor->cursor.row}, {"character", col}}},
{"ch", std::string(1, c)},
{"options",
{{"tabSize", 2},
{"insertSpaces", true},
{"trimTrailingWhitespace", true},
{"trimFinalNewlines", true}}}}}};
LSPPending *pending = new LSPPending();
pending->editor = editor;
pending->method = "textDocument/onTypeFormatting";
pending->callback = [version](Editor *editor, std::string,
json message) {
if (version != editor->lsp_version)
return;
auto &edits = message["result"];
if (edits.is_array()) {
std::vector<TextEdit> t_edits;
t_edits.reserve(edits.size());
for (auto &edit : edits) {
TextEdit t_edit;
t_edit.text = edit.value("newText", "");
t_edit.start.row = edit["range"]["start"]["line"];
t_edit.start.col = edit["range"]["start"]["character"];
t_edit.end.row = edit["range"]["end"]["line"];
t_edit.end.col = edit["range"]["end"]["character"];
utf8_normalize_edit(editor, &t_edit);
t_edits.push_back(t_edit);
}
apply_lsp_edits(editor, t_edits, false);
ensure_scroll(editor);
}
};
lsp_send(editor->lsp, message, pending);
break;
}
}
}
}
} else if (event.c[0] == 0x7F || event.c[0] == 0x08) { } else if (event.c[0] == 0x7F || event.c[0] == 0x08) {
Coord prev_pos = editor->cursor; backspace_edit(editor);
if (prev_pos.col > 0)
prev_pos.col--;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
char *line = next_line(it, nullptr);
char prev_char = line[prev_pos.col];
char next_char = line[editor->cursor.col];
free(it->buffer);
free(it);
bool is_pair = (prev_char == '{' && next_char == '}') ||
(prev_char == '(' && next_char == ')') ||
(prev_char == '[' && next_char == ']') ||
(prev_char == '"' && next_char == '"') ||
(prev_char == '\'' && next_char == '\'');
if (is_pair) {
edit_erase(editor, editor->cursor, 1);
edit_erase(editor, prev_pos, 1);
} else {
edit_erase(editor, editor->cursor, -1);
}
} else if (event.c[0] == 0x1B) { } else if (event.c[0] == 0x1B) {
Coord prev_pos = editor->cursor; normal_mode(editor);
mode = NORMAL;
cursor_left(editor, 1);
if (prev_pos.row != editor->cursor.row)
cursor_right(editor, 1);
} }
} else if (event.len > 1) { } else if (event.len > 1) {
edit_insert(editor, editor->cursor, event.c, event.len); edit_insert(editor, editor->cursor, event.c, event.len);
@@ -553,29 +177,15 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
edit_erase(editor, editor->cursor, 1); edit_erase(editor, editor->cursor, 1);
break; break;
case CNTRL: case CNTRL:
uint32_t next_col_byte, next_col_cluster; delete_next_word(editor);
word_boundaries(editor, editor->cursor, nullptr, &next_col_byte,
nullptr, &next_col_cluster);
if (next_col_byte == editor->cursor.col)
edit_erase(editor, editor->cursor, 1);
else
edit_erase(editor, editor->cursor, next_col_cluster);
break; break;
} }
} else if (event.key_type == KEY_PASTE) { } else if (event.key_type == KEY_PASTE) {
if (event.c) { insert_str(editor, event.c, event.len);
edit_insert(editor, editor->cursor, event.c, event.len);
uint32_t grapheme_len =
count_clusters(event.c, event.len, 0, event.len);
cursor_right(editor, grapheme_len);
}
} }
break; break;
case SELECT: case SELECT:
if (event.key_type == KEY_CHAR && event.len == 1) { if (event.key_type == KEY_CHAR && event.len == 1) {
uint32_t len;
char *text;
Coord start;
switch (event.c[0]) { switch (event.c[0]) {
case 0x1B: case 0x1B:
case 's': case 's':
@@ -584,41 +194,15 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
mode = NORMAL; mode = NORMAL;
break; break;
case 'y': case 'y':
text = get_selection(editor, &len, nullptr); copy(editor);
copy_to_clipboard(text, len);
free(text);
editor->selection_active = false;
mode = NORMAL; mode = NORMAL;
break; break;
case 'x': case 'x':
text = get_selection(editor, &len, &start); cut(editor);
copy_to_clipboard(text, len);
len = count_clusters(text, len, 0, len);
edit_erase(editor, start, len);
free(text);
editor->selection_active = false;
mode = NORMAL; mode = NORMAL;
break; break;
case 'p': case 'p':
text = get_from_clipboard(&len); paste(editor);
if (text) {
Coord start, end;
if (editor->cursor >= editor->selection) {
start = editor->selection;
end = move_right(editor, editor->cursor, 1);
} else {
start = editor->cursor;
end = move_right(editor, editor->selection, 1);
}
uint32_t start_byte =
line_to_byte(editor->root, start.row, nullptr) + start.col;
uint32_t end_byte =
line_to_byte(editor->root, end.row, nullptr) + end.col;
edit_erase(editor, start, end_byte - start_byte);
edit_insert(editor, editor->cursor, text, len);
free(text);
}
editor->selection_active = false;
mode = NORMAL; mode = NORMAL;
break; break;
} }
@@ -648,6 +232,4 @@ void handle_editor_event(Editor *editor, KeyEvent event) {
if (old_mode == mode || mode != INSERT) if (old_mode == mode || mode != INSERT)
handle_completion(editor, event); handle_completion(editor, event);
ensure_scroll(editor); ensure_scroll(editor);
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) && event.c)
free(event.c);
} }

490
src/editor/helpers.cc Normal file
View File

@@ -0,0 +1,490 @@
#include "editor/helpers.h"
#include "editor/editor.h"
#include "io/sysio.h"
#include "lsp/lsp.h"
#include "main.h"
#include "utils/utils.h"
void cut(Editor *editor) {
if (mode != SELECT)
return;
Coord start;
uint32_t len;
char *text = get_selection(editor, &len, &start);
copy_to_clipboard(text, len);
len = count_clusters(text, len, 0, len);
edit_erase(editor, start, len);
free(text);
editor->selection_active = false;
}
void copy(Editor *editor) {
if (mode != SELECT)
return;
uint32_t len;
char *text = get_selection(editor, &len, nullptr);
copy_to_clipboard(text, len);
free(text);
editor->selection_active = false;
}
void paste(Editor *editor) {
uint32_t len;
if (mode == NORMAL) {
char *text = get_from_clipboard(&len);
if (text) {
insert_str(editor, text, len);
free(text);
}
} else if (mode == SELECT) {
char *text = get_from_clipboard(&len);
if (text) {
Coord start, end;
selection_bounds(editor, &start, &end);
uint32_t start_byte =
line_to_byte(editor->root, start.row, nullptr) + start.col;
uint32_t end_byte =
line_to_byte(editor->root, end.row, nullptr) + end.col;
edit_erase(editor, start, end_byte - start_byte);
edit_insert(editor, editor->cursor, text, len);
free(text);
}
editor->selection_active = false;
}
}
void insert_str(Editor *editor, char *c, uint32_t len) {
if (c) {
edit_insert(editor, editor->cursor, c, len);
uint32_t grapheme_len = count_clusters(c, len, 0, len);
cursor_right(editor, grapheme_len);
}
}
void indent_current_line(Editor *editor) {
Coord start = editor->cursor;
uint32_t delta = editor->indents.indent_line(editor->cursor.row);
editor->cursor.col = start.col + delta;
editor->cursor.row = start.row;
}
void dedent_current_line(Editor *editor) {
Coord start = editor->cursor;
uint32_t delta = editor->indents.dedent_line(editor->cursor.row);
editor->cursor.col = MAX((int64_t)start.col - delta, 0);
editor->cursor.row = start.row;
}
void insert_char(Editor *editor, char c) {
uint32_t col = editor->cursor.col;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
uint32_t len;
char *line = next_line(it, &len);
if (!line) {
free(it->buffer);
free(it);
return;
}
bool skip_insert = false;
if (line && col < len) {
char next = line[col];
if ((c == '}' && next == '}') || (c == ')' && next == ')') ||
(c == ']' && next == ']') || (c == '"' && next == '"') ||
(c == '\'' && next == '\'')) {
cursor_right(editor, 1);
skip_insert = true;
}
}
free(it->buffer);
free(it);
if (!skip_insert) {
char closing = 0;
switch (c) {
case '{':
closing = '}';
break;
case '(':
closing = ')';
break;
case '[':
closing = ']';
break;
case '"':
closing = '"';
break;
case '\'':
closing = '\'';
break;
}
if (closing) {
char pair[2] = {c, closing};
edit_insert(editor, editor->cursor, pair, 2);
cursor_right(editor, 1);
} else {
edit_insert(editor, editor->cursor, &c, 1);
cursor_right(editor, 1);
}
if (editor->lsp && editor->lsp->allow_formatting_on_type) {
for (char ch : editor->lsp->format_chars) {
if (ch == c) {
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
uint32_t len;
char *line = next_line(it, &len);
if (!line) {
free(it->buffer);
free(it);
return;
}
uint32_t col = utf8_offset_to_utf16(line, len, editor->cursor.col);
free(it->buffer);
free(it);
int version = editor->lsp_version;
json message = {
{"jsonrpc", "2.0"},
{"method", "textDocument/onTypeFormatting"},
{"params",
{{"textDocument", {{"uri", editor->uri}}},
{"position",
{{"line", editor->cursor.row}, {"character", col}}},
{"ch", std::string(1, c)},
{"options",
{{"tabSize", 2},
{"insertSpaces", true},
{"trimTrailingWhitespace", true},
{"trimFinalNewlines", true}}}}}};
LSPPending *pending = new LSPPending();
pending->editor = editor;
pending->method = "textDocument/onTypeFormatting";
pending->callback = [version](Editor *editor, std::string,
json message) {
if (version != editor->lsp_version)
return;
auto &edits = message["result"];
if (edits.is_array()) {
std::vector<TextEdit> t_edits;
t_edits.reserve(edits.size());
for (auto &edit : edits) {
TextEdit t_edit;
t_edit.text = edit.value("newText", "");
t_edit.start.row = edit["range"]["start"]["line"];
t_edit.start.col = edit["range"]["start"]["character"];
t_edit.end.row = edit["range"]["end"]["line"];
t_edit.end.col = edit["range"]["end"]["character"];
utf8_normalize_edit(editor, &t_edit);
t_edits.push_back(t_edit);
}
apply_lsp_edits(editor, t_edits, false);
ensure_scroll(editor);
}
};
lsp_send(editor->lsp, message, pending);
break;
}
}
}
}
}
void normal_mode(Editor *editor) {
Coord prev_pos = editor->cursor;
mode = NORMAL;
cursor_left(editor, 1);
if (prev_pos.row != editor->cursor.row)
cursor_right(editor, 1);
}
void backspace_edit(Editor *editor) {
Coord prev_pos = editor->cursor;
if (prev_pos.col > 0)
prev_pos.col--;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
char *line = next_line(it, nullptr);
char prev_char = line[prev_pos.col];
char next_char = line[editor->cursor.col];
free(it->buffer);
free(it);
bool is_pair = (prev_char == '{' && next_char == '}') ||
(prev_char == '(' && next_char == ')') ||
(prev_char == '[' && next_char == ']') ||
(prev_char == '"' && next_char == '"') ||
(prev_char == '\'' && next_char == '\'');
if (is_pair) {
edit_erase(editor, editor->cursor, 1);
edit_erase(editor, prev_pos, 1);
} else {
edit_erase(editor, editor->cursor, -1);
}
}
void delete_prev_word(Editor *editor) {
uint32_t prev_col_byte, prev_col_cluster;
word_boundaries(editor, editor->cursor, &prev_col_byte, nullptr,
&prev_col_cluster, nullptr);
if (prev_col_byte == editor->cursor.col)
edit_erase(editor, editor->cursor, -1);
else
edit_erase(editor, editor->cursor, -(int64_t)prev_col_cluster);
}
void delete_next_word(Editor *editor) {
uint32_t next_col_byte, next_col_cluster;
word_boundaries(editor, editor->cursor, nullptr, &next_col_byte, nullptr,
&next_col_cluster);
if (next_col_byte == editor->cursor.col)
edit_erase(editor, editor->cursor, 1);
else
edit_erase(editor, editor->cursor, next_col_cluster);
}
void clear_hooks_at_line(Editor *editor, uint32_t line) {
for (uint8_t i = 0; i < 94; i++)
if (editor->hooks[i] == line + 1) {
editor->hooks[i] = 0;
break;
}
}
void cursor_prev_word(Editor *editor) {
uint32_t prev_col;
word_boundaries(editor, editor->cursor, &prev_col, nullptr, nullptr, nullptr);
editor->cursor_preffered = UINT32_MAX;
if (prev_col == editor->cursor.col)
cursor_left(editor, 1);
else
editor->cursor = {editor->cursor.row, prev_col};
}
void cursor_next_word(Editor *editor) {
uint32_t next_col;
word_boundaries(editor, editor->cursor, nullptr, &next_col, nullptr, nullptr);
editor->cursor_preffered = UINT32_MAX;
if (next_col == editor->cursor.col)
cursor_right(editor, 1);
else
editor->cursor = {editor->cursor.row, next_col};
}
void select_all(Editor *editor) {
if (editor->root->line_count > 0) {
editor->cursor.row = editor->root->line_count - 1;
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it)
return;
uint32_t line_len;
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
line_len = count_clusters(line, line_len, 0, line_len);
free(it->buffer);
free(it);
editor->cursor.col = line_len;
editor->cursor_preffered = UINT32_MAX;
mode = SELECT;
editor->selection_active = true;
editor->selection = {0, 0};
editor->selection_type = LINE;
}
}
void fetch_lsp_hover(Editor *editor) {
if (editor->lsp && editor->lsp->allow_hover) {
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
uint32_t line_len;
char *line = next_line(it, &line_len);
if (!line) {
free(it->buffer);
free(it);
return;
}
uint32_t col = utf8_offset_to_utf16(line, line_len, editor->cursor.col);
free(it->buffer);
free(it);
json hover_request = {
{"jsonrpc", "2.0"},
{"method", "textDocument/hover"},
{"params",
{{"textDocument", {{"uri", editor->uri}}},
{"position", {{"line", editor->cursor.row}, {"character", col}}}}}};
LSPPending *pending = new LSPPending();
pending->editor = editor;
pending->method = "textDocument/hover";
pending->callback = [](Editor *editor, std::string, json hover) {
if (hover.contains("result") && !hover["result"].is_null()) {
auto &contents = hover["result"]["contents"];
std::string hover_text = "";
bool is_markup = false;
if (contents.is_object()) {
hover_text += contents["value"].get<std::string>();
is_markup = (contents["kind"].get<std::string>() == "markdown");
} else if (contents.is_array()) {
for (auto &block : contents) {
if (block.is_string()) {
hover_text += block.get<std::string>() + "\n";
} else if (block.is_object() && block.contains("language") &&
block.contains("value")) {
std::string lang = block["language"].get<std::string>();
std::string val = block["value"].get<std::string>();
is_markup = true;
hover_text += "```" + lang + "\n" + val + "\n```\n";
}
}
} else if (contents.is_string()) {
hover_text += contents.get<std::string>();
}
if (!hover_text.empty()) {
editor->hover.clear();
editor->hover.text = clean_text(hover_text);
editor->hover.is_markup = is_markup;
editor->hover.render_first();
editor->hover_active = true;
}
}
};
lsp_send(editor->lsp, hover_request, pending);
}
}
void handle_mouse(Editor *editor, KeyEvent event) {
static std::chrono::steady_clock::time_point last_click_time =
std::chrono::steady_clock::now();
static uint32_t click_count = 0;
static Coord last_click_pos = {UINT32_MAX, UINT32_MAX};
if (event.key_type == KEY_MOUSE) {
auto now = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
now - last_click_time)
.count();
switch (event.mouse_state) {
case SCROLL:
switch (event.mouse_direction) {
case SCROLL_UP:
scroll_up(editor, 4);
ensure_cursor(editor);
break;
case SCROLL_DOWN:
scroll_down(editor, 4);
ensure_cursor(editor);
break;
case SCROLL_LEFT:
cursor_left(editor, 10);
break;
case SCROLL_RIGHT:
cursor_right(editor, 10);
break;
}
break;
case PRESS:
if (event.mouse_button == LEFT_BTN) {
Coord cur_pos = {event.mouse_x, event.mouse_y};
if (duration < 250 && last_click_pos == cur_pos)
click_count++;
else
click_count = 1;
last_click_time = now;
last_click_pos = cur_pos;
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
return;
editor->cursor_preffered = UINT32_MAX;
if (click_count == 1) {
editor->cursor = p;
editor->selection = p;
if (mode == SELECT) {
mode = NORMAL;
editor->selection_active = false;
}
} else if (click_count == 2) {
uint32_t prev_col, next_col;
word_boundaries(editor, editor->cursor, &prev_col, &next_col, nullptr,
nullptr);
if (editor->cursor < editor->selection)
editor->cursor = {editor->cursor.row, prev_col};
else
editor->cursor = {editor->cursor.row, next_col};
editor->cursor_preffered = UINT32_MAX;
editor->selection_type = WORD;
mode = SELECT;
editor->selection_active = true;
} else if (click_count >= 3) {
if (editor->cursor < editor->selection) {
editor->cursor = {p.row, 0};
} else {
uint32_t line_len;
LineIterator *it = begin_l_iter(editor->root, p.row);
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
free(it->buffer);
free(it);
editor->cursor = {p.row, line_len};
}
editor->cursor_preffered = UINT32_MAX;
editor->selection_type = LINE;
mode = SELECT;
editor->selection_active = true;
click_count = 3;
}
}
break;
case DRAG:
if (event.mouse_button == LEFT_BTN) {
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
return;
editor->cursor_preffered = UINT32_MAX;
mode = SELECT;
if (!editor->selection_active) {
editor->selection_active = true;
editor->selection_type = CHAR;
}
uint32_t prev_col, next_col, line_len;
switch (editor->selection_type) {
case CHAR:
editor->cursor = p;
break;
case WORD:
word_boundaries(editor, p, &prev_col, &next_col, nullptr, nullptr);
if (editor->cursor < editor->selection)
editor->cursor = {p.row, prev_col};
else
editor->cursor = {p.row, next_col};
break;
case LINE:
if (editor->cursor < editor->selection) {
editor->cursor = {p.row, 0};
} else {
LineIterator *it = begin_l_iter(editor->root, p.row);
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
free(it->buffer);
free(it);
editor->cursor = {p.row, line_len};
}
break;
}
}
break;
case RELEASE:
if (event.mouse_button == LEFT_BTN)
if (editor->cursor.row == editor->selection.row &&
editor->cursor.col == editor->selection.col) {
mode = NORMAL;
editor->selection_active = false;
}
break;
}
}
}

View File

@@ -218,8 +218,8 @@ void IndentationEngine::insert_new_line(Coord cursor) {
if (is_end_full != kLangtoBlockEndsFull.end()) if (is_end_full != kLangtoBlockEndsFull.end())
for (auto end : is_end_full->second) for (auto end : is_end_full->second)
if (end == trim(line)) { if (end == trim(line)) {
cursor.col = cursor.col = set_indent(
set_indent(cursor.row, (int64_t)indent_expected(cursor.row) - 1); cursor.row, (int64_t)indent_expected(cursor.row) - (int64_t)1);
end_matched = true; end_matched = true;
break; break;
} }
@@ -286,7 +286,7 @@ void IndentationEngine::insert_new_line(Coord cursor) {
(indent == 1 ? std::string(c_indent, '\t') (indent == 1 ? std::string(c_indent, '\t')
: std::string(c_indent * indent, ' ')) + : std::string(c_indent * indent, ' ')) +
ending; ending;
else if (ending_valid) else if (ending_valid && c_indent)
c_indent--; c_indent--;
} }
auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name); auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name);
@@ -323,13 +323,14 @@ void IndentationEngine::insert_new_line(Coord cursor) {
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row); LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
if (!it) if (!it)
return; return;
char *line = next_line(it, nullptr); uint32_t line_len;
char *line = next_line(it, &line_len);
if (!line) { if (!line) {
free(it->buffer); free(it->buffer);
free(it); free(it);
return; return;
} }
uint32_t col = utf8_byte_offset_to_utf16(line, editor->cursor.col); uint32_t col = utf8_offset_to_utf16(line, line_len, editor->cursor.col);
free(it->buffer); free(it->buffer);
free(it); free(it);
int version = editor->lsp_version; int version = editor->lsp_version;

View File

@@ -60,10 +60,10 @@ void editor_lsp_handle(Editor *editor, json msg) {
if (len > 0 && line[len - 1] == '\n') if (len > 0 && line[len - 1] == '\n')
--len; --len;
lock.unlock(); lock.unlock();
w.start = utf16_offset_to_utf8(line, w.start); w.start = utf16_offset_to_utf8(line, len, w.start);
uint32_t end = d["range"]["end"]["character"]; uint32_t end = d["range"]["end"]["character"];
if (d["range"]["end"]["line"] == w.line) if (d["range"]["end"]["line"] == w.line)
w.end = utf16_offset_to_utf8(line, end); w.end = utf16_offset_to_utf8(line, len, end);
free(it->buffer); free(it->buffer);
free(it); free(it);
std::string text = trim(d["message"].get<std::string>()); std::string text = trim(d["message"].get<std::string>());

View File

@@ -1,14 +1,17 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "io/sysio.h"
#include "main.h" #include "main.h"
#include "syntax/decl.h" #include "syntax/decl.h"
#include "syntax/parser.h" #include "syntax/parser.h"
#include <cstdint>
void render_editor(Editor *editor) { void render_editor(Editor *editor) {
uint32_t sel_start = 0, sel_end = 0; uint32_t sel_start = 0, sel_end = 0;
std::shared_lock knot_lock(editor->knot_mtx);
uint32_t numlen = uint32_t numlen =
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1)); EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
uint32_t render_width = editor->size.col - numlen; uint32_t render_width = editor->size.col - numlen;
uint32_t render_x = editor->position.col + numlen; uint32_t render_x = editor->position.col + numlen + 1;
std::vector<std::pair<uint32_t, char>> v; std::vector<std::pair<uint32_t, char>> v;
for (size_t i = 0; i < 94; ++i) for (size_t i = 0; i < 94; ++i)
if (editor->hooks[i] != 0) if (editor->hooks[i] != 0)
@@ -34,7 +37,6 @@ void render_editor(Editor *editor) {
return (int)token.type; return (int)token.type;
return 0; return 0;
}; };
std::shared_lock knot_lock(editor->knot_mtx);
if (editor->selection_active) { if (editor->selection_active) {
Coord start, end; Coord start, end;
if (editor->cursor >= editor->selection) { if (editor->cursor >= editor->selection) {
@@ -88,15 +90,29 @@ void render_editor(Editor *editor) {
LineIterator *it = begin_l_iter(editor->root, line_index); LineIterator *it = begin_l_iter(editor->root, line_index);
if (!it) if (!it)
return; return;
uint32_t prev_col, next_col;
std::string word;
word_boundaries_exclusive(editor, editor->cursor, &prev_col, &next_col);
if (next_col - prev_col > 0 && next_col - prev_col < 256 - 4) {
uint32_t offset = line_to_byte(editor->root, editor->cursor.row, nullptr);
char *word_ptr = read(editor->root, offset + prev_col, next_col - prev_col);
if (word_ptr) {
word = std::string(word_ptr, next_col - prev_col);
free(word_ptr);
}
}
editor->extra_hl.render(editor->root, line_index, word, editor->is_css_color);
uint32_t rendered_rows = 0; uint32_t rendered_rows = 0;
uint32_t global_byte_offset = line_to_byte(editor->root, line_index, nullptr); uint32_t global_byte_offset = line_to_byte(editor->root, line_index, nullptr);
while (rendered_rows < editor->size.row) { while (rendered_rows < editor->size.row) {
uint32_t line_len; uint32_t line_len;
char *line = next_line(it, &line_len); char *line = next_line(it, &line_len);
if (editor->parser) {
if (line_data) if (line_data)
line_data = editor->parser->line_tree.next(); line_data = editor->parser->line_tree.next();
else else
line_data = editor->parser->line_tree.start_iter(line_index); line_data = editor->parser->line_tree.start_iter(line_index);
}
if (!line) if (!line)
break; break;
if (line_len > 0 && line[line_len - 1] == '\n') if (line_len > 0 && line[line_len - 1] == '\n')
@@ -130,16 +146,14 @@ void render_editor(Editor *editor) {
update(editor->position.row + rendered_rows, editor->position.col, hook, update(editor->position.row + rendered_rows, editor->position.col, hook,
0xAAAAAA, 0, 0); 0xAAAAAA, 0, 0);
char buf[16]; char buf[16];
int len = int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
snprintf(buf, sizeof(buf), "%*u ", numlen - 3, line_index + 1);
uint32_t num_color = uint32_t num_color =
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555; editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
update(editor->position.row + rendered_rows, update(editor->position.row + rendered_rows, editor->position.col + i,
editor->position.col + i + 2, (char[2]){buf[i], 0}, num_color, (char[2]){buf[i], 0}, num_color, 0, 0);
0, 0);
} else { } else {
for (uint32_t i = 0; i < numlen; i++) for (uint32_t i = 0; i < numlen + 1; i++)
update(editor->position.row + rendered_rows, editor->position.col + i, update(editor->position.row + rendered_rows, editor->position.col + i,
" ", 0, 0, 0); " ", 0, 0, 0);
} }
@@ -157,12 +171,22 @@ void render_editor(Editor *editor) {
const Highlight *hl = nullptr; const Highlight *hl = nullptr;
if (editor->parser) if (editor->parser)
hl = &highlights[get_type(current_byte_offset + local_render_offset)]; hl = &highlights[get_type(current_byte_offset + local_render_offset)];
uint32_t fg = hl ? hl->fg : 0xFFFFFF; std::optional<std::pair<uint32_t, uint32_t>> extra =
uint32_t bg = hl ? hl->bg : 0; editor->extra_hl.get(
uint8_t fl = hl ? hl->flags : 0; {line_index, current_byte_offset + local_render_offset});
uint32_t fg = extra && extra->second != UINT32_MAX
? extra->first
: (hl ? hl->fg : 0xFFFFFF);
uint32_t bg = extra && extra->second != UINT32_MAX
? extra->second
: (hl ? hl->bg : 0x000000);
uint8_t fl =
(hl ? hl->flags : 0) |
(extra ? (extra->second != UINT32_MAX ? CF_BOLD : CF_UNDERLINE)
: 0);
if (editor->selection_active && absolute_byte_pos >= sel_start && if (editor->selection_active && absolute_byte_pos >= sel_start &&
absolute_byte_pos < sel_end) absolute_byte_pos < sel_end)
bg = 0x555555; bg = bg | 0x555555;
uint32_t u_color = 0; uint32_t u_color = 0;
for (const auto &w : line_warnings) { for (const auto &w : line_warnings) {
if (w.start <= current_byte_offset + local_render_offset && if (w.start <= current_byte_offset + local_render_offset &&
@@ -323,13 +347,12 @@ void render_editor(Editor *editor) {
update(editor->position.row + rendered_rows, editor->position.col, hook, update(editor->position.row + rendered_rows, editor->position.col, hook,
0xAAAAAA, 0, 0); 0xAAAAAA, 0, 0);
char buf[16]; char buf[16];
int len = snprintf(buf, sizeof(buf), "%*u ", numlen - 3, line_index + 1); int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
uint32_t num_color = uint32_t num_color =
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555; editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
update(editor->position.row + rendered_rows, update(editor->position.row + rendered_rows, editor->position.col + i,
editor->position.col + i + 2, (char[2]){buf[i], 0}, num_color, 0, (char[2]){buf[i], 0}, num_color, 0, 0);
0);
if (editor->cursor.row == line_index) { if (editor->cursor.row == line_index) {
cursor.row = editor->position.row + rendered_rows; cursor.row = editor->position.row + rendered_rows;
cursor.col = render_x; cursor.col = render_x;

View File

@@ -1,17 +1,18 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "utils/utils.h"
char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start) { void selection_bounds(Editor *editor, Coord *out_start, Coord *out_end) {
std::shared_lock lock(editor->knot_mtx); std::shared_lock lock(editor->knot_mtx);
Coord start, end; Coord start, end;
if (editor->cursor >= editor->selection) { if (editor->cursor >= editor->selection) {
uint32_t prev_col, next_col; uint32_t prev_col;
switch (editor->selection_type) { switch (editor->selection_type) {
case CHAR: case CHAR:
start = editor->selection; start = editor->selection;
end = move_right(editor, editor->cursor, 1); end = move_right(editor, editor->cursor, 1);
break; break;
case WORD: case WORD:
word_boundaries(editor, editor->selection, &prev_col, &next_col, nullptr, word_boundaries(editor, editor->selection, &prev_col, nullptr, nullptr,
nullptr); nullptr);
start = {editor->selection.row, prev_col}; start = {editor->selection.row, prev_col};
end = editor->cursor; end = editor->cursor;
@@ -23,13 +24,65 @@ char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start) {
} }
} else { } else {
start = editor->cursor; start = editor->cursor;
uint32_t prev_col, next_col, line_len; uint32_t next_col, line_len;
switch (editor->selection_type) { switch (editor->selection_type) {
case CHAR: case CHAR:
end = move_right(editor, editor->selection, 1); end = move_right(editor, editor->selection, 1);
break; break;
case WORD: case WORD:
word_boundaries(editor, editor->selection, &prev_col, &next_col, nullptr, word_boundaries(editor, editor->selection, nullptr, &next_col, nullptr,
nullptr);
end = {editor->selection.row, next_col};
break;
case LINE:
LineIterator *it = begin_l_iter(editor->root, editor->selection.row);
char *line = next_line(it, &line_len);
if (!line)
return;
if (line_len > 0 && line[line_len - 1] == '\n')
line_len--;
end = {editor->selection.row, line_len};
free(it->buffer);
free(it);
break;
}
}
if (out_start)
*out_start = start;
if (out_end)
*out_end = end;
}
char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start) {
std::shared_lock lock(editor->knot_mtx);
Coord start, end;
if (editor->cursor >= editor->selection) {
uint32_t prev_col;
switch (editor->selection_type) {
case CHAR:
start = editor->selection;
end = move_right(editor, editor->cursor, 1);
break;
case WORD:
word_boundaries(editor, editor->selection, &prev_col, nullptr, nullptr,
nullptr);
start = {editor->selection.row, prev_col};
end = editor->cursor;
break;
case LINE:
start = {editor->selection.row, 0};
end = editor->cursor;
break;
}
} else {
start = editor->cursor;
uint32_t next_col, line_len;
switch (editor->selection_type) {
case CHAR:
end = move_right(editor, editor->selection, 1);
break;
case WORD:
word_boundaries(editor, editor->selection, nullptr, &next_col, nullptr,
nullptr); nullptr);
end = {editor->selection.row, next_col}; end = {editor->selection.row, next_col};
break; break;

View File

@@ -154,7 +154,7 @@ void render() {
} }
} }
} }
last_change_col = MIN(cols + 1, col + 4); last_change_col = MIN(cols - 1, col + 4);
} }
} }
if (first_change_col == -1) if (first_change_col == -1)

View File

@@ -1,4 +1,5 @@
#include "lsp/lsp.h" #include "lsp/lsp.h"
#include "main.h"
Queue<LSPOpenRequest> lsp_open_queue; Queue<LSPOpenRequest> lsp_open_queue;
@@ -7,7 +8,7 @@ void request_add_to_lsp(Language language, Editor *editor) {
} }
void add_to_lsp(Language language, Editor *editor) { void add_to_lsp(Language language, Editor *editor) {
std::shared_ptr<LSPInstance> lsp = get_or_init_lsp(language.lsp_id); std::shared_ptr<LSPInstance> lsp = get_or_init_lsp(language.lsp_name);
if (!lsp) if (!lsp)
return; return;
std::unique_lock lock(lsp->mtx); std::unique_lock lock(lsp->mtx);
@@ -41,11 +42,11 @@ void open_editor(std::shared_ptr<LSPInstance> lsp,
lsp_send(lsp, message, nullptr); lsp_send(lsp, message, nullptr);
} }
static uint8_t find_lsp_id(std::shared_ptr<LSPInstance> needle) { static std::string find_lsp_id(std::shared_ptr<LSPInstance> needle) {
for (const auto &[id, lsp] : active_lsps) for (const auto &[id, lsp] : active_lsps)
if (lsp == needle) if (lsp == needle)
return id; return id;
return 0; return "";
} }
void remove_from_lsp(Editor *editor) { void remove_from_lsp(Editor *editor) {
@@ -64,8 +65,8 @@ void remove_from_lsp(Editor *editor) {
{"method", "textDocument/didClose"}, {"method", "textDocument/didClose"},
{"params", {{"textDocument", {{"uri", editor->uri}}}}}}; {"params", {{"textDocument", {{"uri", editor->uri}}}}}};
lsp_send(lsp, message, nullptr); lsp_send(lsp, message, nullptr);
uint8_t lsp_id = find_lsp_id(lsp); std::string lsp_id = find_lsp_id(lsp);
if (lsp_id && lsp->editors.empty()) if (!lsp_id.empty() && lsp->editors.empty())
close_lsp(lsp_id); close_lsp(lsp_id);
} }

View File

@@ -1,4 +1,3 @@
#include "config.h"
#include "lsp/lsp.h" #include "lsp/lsp.h"
static bool init_lsp(std::shared_ptr<LSPInstance> lsp) { static bool init_lsp(std::shared_ptr<LSPInstance> lsp) {
@@ -25,7 +24,12 @@ static bool init_lsp(std::shared_ptr<LSPInstance> lsp) {
close(in_pipe[1]); close(in_pipe[1]);
close(out_pipe[0]); close(out_pipe[0]);
close(out_pipe[1]); close(out_pipe[1]);
execvp(lsp->lsp->command, (char *const *)(lsp->lsp->args.data())); std::vector<char *> argv;
argv.push_back(const_cast<char *>(lsp->lsp->command.c_str()));
for (auto &arg : lsp->lsp->args)
argv.push_back(const_cast<char *>(arg.c_str()));
argv.push_back(nullptr);
execvp(lsp->lsp->command.c_str(), argv.data());
perror("execvp"); perror("execvp");
_exit(127); _exit(127);
} }
@@ -37,12 +41,12 @@ static bool init_lsp(std::shared_ptr<LSPInstance> lsp) {
return true; return true;
} }
std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id) { std::shared_ptr<LSPInstance> get_or_init_lsp(std::string lsp_id) {
std::unique_lock lock(active_lsps_mtx); std::unique_lock lock(active_lsps_mtx);
auto it = active_lsps.find(lsp_id); auto it = active_lsps.find(lsp_id);
if (it == active_lsps.end()) { if (it == active_lsps.end()) {
auto map_it = kLsps.find(lsp_id); auto map_it = lsps.find(lsp_id);
if (map_it == kLsps.end()) if (map_it == lsps.end())
return nullptr; return nullptr;
std::shared_ptr<LSPInstance> lsp = std::make_shared<LSPInstance>(); std::shared_ptr<LSPInstance> lsp = std::make_shared<LSPInstance>();
lsp->lsp = &map_it->second; lsp->lsp = &map_it->second;
@@ -54,6 +58,13 @@ std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id) {
pending->callback = [lsp, lsp_id](Editor *, std::string, json msg) { pending->callback = [lsp, lsp_id](Editor *, std::string, json msg) {
if (msg.contains("result") && msg["result"].contains("capabilities")) { if (msg.contains("result") && msg["result"].contains("capabilities")) {
auto &caps = msg["result"]["capabilities"]; auto &caps = msg["result"]["capabilities"];
// if (caps.contains("positionEncoding")) {
// std::string s = caps["positionEncoding"].get<std::string>();
// if (s == "utf-8")
// lsp->is_utf8 = true;
// log("Lsp name: %s, supports: %s", lsp->lsp->command.c_str(),
// s.c_str());
// }
if (caps.contains("textDocumentSync")) { if (caps.contains("textDocumentSync")) {
auto &sync = caps["textDocumentSync"]; auto &sync = caps["textDocumentSync"];
if (sync.is_number()) { if (sync.is_number()) {
@@ -65,8 +76,9 @@ std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id) {
} }
} }
lsp->allow_formatting = caps.value("documentFormattingProvider", false); lsp->allow_formatting = caps.value("documentFormattingProvider", false);
if (lsp_id != LUA_LS /* Lua ls gives terrible ontype formatting */ && if (lsp_id != "lua-language-server" /* Lua ls gives terrible ontype
caps.contains("documentOnTypeFormattingProvider")) { formatting so disable */
&& caps.contains("documentOnTypeFormattingProvider")) {
auto &fmt = caps["documentOnTypeFormattingProvider"]; auto &fmt = caps["documentOnTypeFormattingProvider"];
if (fmt.is_object()) { if (fmt.is_object()) {
if (fmt.contains("firstTriggerCharacter")) { if (fmt.contains("firstTriggerCharacter")) {
@@ -142,44 +154,82 @@ std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id) {
return it->second; return it->second;
} }
void close_lsp(uint8_t lsp_id) { void close_lsp(std::string lsp_id) {
std::shared_lock active_lsps_lock(active_lsps_mtx); std::shared_ptr<LSPInstance> lsp;
{
std::shared_lock lock(active_lsps_mtx);
auto it = active_lsps.find(lsp_id); auto it = active_lsps.find(lsp_id);
if (it == active_lsps.end()) if (it == active_lsps.end())
return; return;
std::shared_ptr<LSPInstance> lsp = it->second; lsp = it->second;
active_lsps_lock.unlock(); }
if (!lsp || lsp->pid == -1 || lsp->exited)
return;
lsp->exited = true; lsp->exited = true;
lsp->initialized = false; lsp->initialized = false;
LSPPending *shutdown_pending = new LSPPending(); auto send_raw = [&](const json &msg) {
shutdown_pending->method = "shutdown"; std::string payload = msg.dump();
shutdown_pending->callback = [lsp](Editor *, std::string, json) { std::string header =
json exit = {{"jsonrpc", "2.0"}, {"method", "exit"}}; "Content-Length: " + std::to_string(payload.size()) + "\r\n\r\n";
lsp_send(lsp, exit, nullptr); std::string out = header + payload;
const char *ptr = out.data();
size_t remaining = out.size();
while (remaining > 0) {
ssize_t n = write(lsp->stdin_fd, ptr, remaining);
if (n <= 0) {
if (errno == EINTR)
continue;
break;
}
ptr += n;
remaining -= n;
}
}; };
json shutdown = {{"jsonrpc", "2.0"}, {"method", "shutdown"}}; json shutdown = {{"jsonrpc", "2.0"}, {"id", 1}, {"method", "shutdown"}};
lsp_send(lsp, shutdown, shutdown_pending); send_raw(shutdown);
std::thread t([lsp, lsp_id] { {
std::this_thread::sleep_for(100ms); pollfd pfd{lsp->stdout_fd, POLLIN, 0};
std::unique_lock active_lsps_lock(active_lsps_mtx); int timeout_ms = 300;
std::unique_lock lock(lsp->mtx); if (poll(&pfd, 1, timeout_ms) > 0) {
if (lsp->pid != -1 && kill(lsp->pid, 0) == 0) auto msg = read_lsp_message(lsp->stdout_fd);
(void)msg;
}
}
json exit_msg = {{"jsonrpc", "2.0"}, {"method", "exit"}};
send_raw(exit_msg);
const int max_wait_ms = 500;
int waited = 0;
while (waited < max_wait_ms) {
int status;
pid_t res = waitpid(lsp->pid, &status, WNOHANG);
if (res == lsp->pid)
break;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
waited += 10;
}
if (kill(lsp->pid, 0) == 0) {
kill(lsp->pid, SIGKILL); kill(lsp->pid, SIGKILL);
waitpid(lsp->pid, nullptr, 0); waitpid(lsp->pid, nullptr, 0);
}
close(lsp->stdin_fd); close(lsp->stdin_fd);
close(lsp->stdout_fd); close(lsp->stdout_fd);
{
std::unique_lock lock(lsp->mtx);
for (auto &kv : lsp->pending) for (auto &kv : lsp->pending)
delete kv.second; delete kv.second;
lsp->pending.clear();
}
for (auto &editor : lsp->editors) { for (auto &editor : lsp->editors) {
std::unique_lock editor_lock(editor->lsp_mtx); std::unique_lock editor_lock(editor->lsp_mtx);
editor->lsp = nullptr; editor->lsp = nullptr;
} }
{
std::unique_lock lock(active_lsps_mtx);
active_lsps.erase(lsp_id); active_lsps.erase(lsp_id);
}); }
t.detach();
} }
void clean_lsp(std::shared_ptr<LSPInstance> lsp, uint8_t lsp_id) { void clean_lsp(std::shared_ptr<LSPInstance> lsp, std::string lsp_id) {
for (auto &kv : lsp->pending) for (auto &kv : lsp->pending)
delete kv.second; delete kv.second;
lsp->pid = -1; lsp->pid = -1;

View File

@@ -1,7 +1,7 @@
#include "lsp/lsp.h" #include "lsp/lsp.h"
std::shared_mutex active_lsps_mtx; std::shared_mutex active_lsps_mtx;
std::unordered_map<uint8_t, std::shared_ptr<LSPInstance>> active_lsps; std::unordered_map<std::string, std::shared_ptr<LSPInstance>> active_lsps;
void lsp_send(std::shared_ptr<LSPInstance> lsp, json message, void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
LSPPending *pending) { LSPPending *pending) {
@@ -16,7 +16,7 @@ void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
lsp->outbox.push(message); lsp->outbox.push(message);
} }
static std::optional<json> read_lsp_message(int fd) { std::optional<json> read_lsp_message(int fd) {
std::string header; std::string header;
char c; char c;
while (true) { while (true) {

View File

@@ -2,43 +2,24 @@
#include "editor/editor.h" #include "editor/editor.h"
#include "io/sysio.h" #include "io/sysio.h"
#include "lsp/lsp.h" #include "lsp/lsp.h"
#include "syntax/decl.h" #include "scripting/decl.h"
#include "ui/bar.h" #include "ui/bar.h"
#include "utils/utils.h" #include "utils/utils.h"
std::atomic<bool> running{true}; std::atomic<bool> running{true};
Queue<KeyEvent> event_queue; Queue<KeyEvent> event_queue;
std::vector<Editor *> editors; std::vector<Editor *> editors;
Bar bar;
uint8_t current_editor = 0; uint8_t current_editor = 0;
std::atomic<uint8_t> mode = NORMAL; std::atomic<uint8_t> mode = NORMAL;
void background_worker() {
while (running)
throttle(16ms, editor_worker, editors[current_editor]);
}
void background_lsp() { void background_lsp() {
while (running) while (running)
throttle(8ms, lsp_worker); throttle(8ms, lsp_worker);
} }
void input_listener() { inline Editor *editor_at(uint8_t x, uint8_t y) {
while (running) {
KeyEvent event = throttle(1ms, read_key);
if (event.key_type == KEY_NONE)
continue;
if (event.key_type == KEY_CHAR && event.len == 1 &&
event.c[0] == CTRL('q')) {
free(event.c);
running = false;
return;
}
event_queue.push(event);
}
}
Editor *editor_at(uint8_t x, uint8_t y) {
for (Editor *ed : editors) { for (Editor *ed : editors) {
Coord pos = ed->position; Coord pos = ed->position;
Coord size = ed->size; Coord size = ed->size;
@@ -49,23 +30,61 @@ Editor *editor_at(uint8_t x, uint8_t y) {
return nullptr; return nullptr;
} }
uint8_t index_of(Editor *ed) { inline uint8_t index_of(Editor *ed) {
for (uint8_t i = 0; i < editors.size(); i++) for (uint8_t i = 0; i < editors.size(); i++)
if (editors[i] == ed) if (editors[i] == ed)
return i; return i;
return 0; return 0;
} }
void input_listener() {
while (running) {
KeyEvent event = throttle(1ms, read_key);
if (event.key_type == KEY_NONE)
goto render;
if (event.key_type == KEY_CHAR && event.len == 1 &&
event.c[0] == CTRL('q')) {
free(event.c);
running = false;
break;
}
if (mode != RUNNER) {
if (event.key_type == KEY_MOUSE) {
Editor *target = editor_at(event.mouse_x, event.mouse_y);
if (target) {
if (event.mouse_state == PRESS)
current_editor = index_of(target);
event.mouse_x -= target->position.col;
event.mouse_y -= target->position.row;
handle_editor_event(target, event);
}
} else {
handle_editor_event(editors[current_editor], event);
}
} else {
bar.handle(event);
}
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) && event.c)
free(event.c);
render:
bar.render();
render_editor(editors[current_editor]);
throttle(4ms, render);
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
ruby_start();
load_theme();
load_languages_info();
load_custom_highlighters();
Coord screen = start_screen(); Coord screen = start_screen();
const char *filename = (argc > 1) ? argv[1] : ""; const char *filename = (argc > 1) ? argv[1] : "";
uint8_t eol = read_line_endings();
system(("bash " + get_exe_dir() + "/../scripts/init.sh").c_str()); Editor *editor =
new_editor(filename, {0, 0}, {screen.row - 2, screen.col}, eol);
load_theme(get_exe_dir() + "/../themes/default.json"); bar.init(screen);
Editor *editor = new_editor(filename, {0, 0}, {screen.row - 2, screen.col});
Bar bar(screen);
if (!editor) { if (!editor) {
end_screen(); end_screen();
@@ -77,59 +96,25 @@ int main(int argc, char *argv[]) {
current_editor = editors.size() - 1; current_editor = editors.size() - 1;
std::thread input_thread(input_listener); std::thread input_thread(input_listener);
std::thread work_thread(background_worker);
std::thread lsp_thread(background_lsp); std::thread lsp_thread(background_lsp);
while (running) { while (running) {
KeyEvent event; throttle(16ms, editor_worker, editors[current_editor]);
while (event_queue.pop(event)) { bar.work();
if (mode != RUNNER) {
if (event.key_type == KEY_MOUSE) {
Editor *target = editor_at(event.mouse_x, event.mouse_y);
if (!target)
continue;
if (event.mouse_state == PRESS)
current_editor = index_of(target);
event.mouse_x -= target->position.col;
event.mouse_y -= target->position.row;
handle_editor_event(target, event);
} else {
handle_editor_event(editors[current_editor], event);
}
} else {
bar.handle(event);
}
}
render_editor(editors[current_editor]);
bar.render();
throttle(4ms, render);
} }
if (input_thread.joinable()) if (input_thread.joinable())
input_thread.join(); input_thread.join();
if (work_thread.joinable())
work_thread.join();
if (lsp_thread.joinable()) if (lsp_thread.joinable())
lsp_thread.join(); lsp_thread.join();
system(("bash " + get_exe_dir() + "/../scripts/exit.sh").c_str());
end_screen(); end_screen();
for (auto editor : editors) for (auto editor : editors)
free_editor(editor); free_editor(editor);
std::unique_lock lk(active_lsps_mtx); ruby_shutdown();
lk.unlock();
while (true) {
lk.lock();
if (active_lsps.empty())
break;
lk.unlock();
throttle(16ms, lsp_worker);
}
return 0; return 0;
} }

38
src/ruby_compile.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
INPUT="$SCRIPT_DIR/../include/syntax/tokens.def"
TMP="/tmp/__crib_precompiled.rb"
OUTPUT="/tmp/__crib_precompiled.mrb"
echo "module Tokens" >"$TMP"
counter=0
while read -r line; do
if [[ $line =~ ADD\(([^\)]+)\) ]]; then
name="${BASH_REMATCH[1]}"
echo " $name = $counter" >>"$TMP"
counter=$((counter + 1))
fi
done <"$INPUT"
{
echo " freeze"
echo "end"
echo
cat "$SCRIPT_DIR/../include/scripting/libcrib.rb"
} >>"$TMP"
mrbc -o$OUTPUT $TMP
{
echo "#pragma once"
xxd -i $OUTPUT | sed 's/^unsigned char /constexpr unsigned char /' |
sed 's/^unsigned int /constexpr unsigned int /'
} >"$SCRIPT_DIR/../include/scripting/ruby_compiled.h"
rm $TMP
rm $OUTPUT

10
src/scripting/bindings.cc Normal file
View File

@@ -0,0 +1,10 @@
#include "main.h"
#include "scripting/decl.h"
mrb_value get_mode(mrb_state *mrb, mrb_value self) {
return mrb_fixnum_value(mode);
}
void setup_ruby_bindings(mrb_state *mrb, RClass *C_module) {
mrb_define_module_function(mrb, C_module, "mode", get_mode, MRB_ARGS_NONE());
}

448
src/scripting/process.cc Normal file
View File

@@ -0,0 +1,448 @@
#include "main.h"
#include "scripting/decl.h"
#include "scripting/ruby_compiled.h"
#include "utils/utils.h"
#include <mruby/boxing_word.h>
std::unordered_map<std::string, std::pair<mrb_value, mrb_value>>
custom_highlighters;
struct R_ThemeEntry {
std::string key;
uint32_t fg = 0xFFFFFF;
uint32_t bg = 0x000000;
bool italic = false;
bool bold = false;
bool underline = false;
bool strikethrough = false;
};
struct R_Language {
std::string name;
uint32_t color = 0xFFFFFF;
std::vector<std::string> extensions;
std::vector<std::string> filenames;
std::string lsp_command; // link to LSP by name
};
mrb_state *mrb = nullptr;
RClass *C_module;
namespace fs = std::filesystem;
void ruby_start() {
mrb = mrb_open();
if (!mrb) {
fprintf(stderr, "Failed to init mruby\n");
return;
}
fs::path exe_dir = get_exe_dir();
std::vector<fs::path> candidates;
candidates.emplace_back("./crib.rb");
const char *xdg = std::getenv("XDG_CONFIG_HOME");
const char *home = std::getenv("HOME");
if (xdg) {
candidates.emplace_back(fs::path(xdg) / "crib/crib.rb");
candidates.emplace_back(fs::path(xdg) / "crib/main.rb");
candidates.emplace_back(fs::path(xdg) / "crib.rb");
} else if (home) {
fs::path base = fs::path(home) / ".config";
candidates.emplace_back(base / "crib/crib.rb");
candidates.emplace_back(base / "crib/main.rb");
candidates.emplace_back(base / "crib.rb");
}
candidates.emplace_back(exe_dir / "../config/main.rb");
candidates.emplace_back(exe_dir / "../config/crib.rb");
mrb_load_irep(mrb, _tmp___crib_precompiled_mrb);
C_module = mrb_module_get(mrb, "C");
setup_ruby_bindings(mrb, C_module);
for (const auto &p : candidates) {
if (fs::exists(p)) {
FILE *f = fopen(p.string().c_str(), "r");
if (f) {
mrb_load_file(mrb, f);
if (mrb->exc)
exit(1);
fclose(f);
}
break;
}
}
mrb_value mod_val = mrb_obj_value(C_module);
mrb_value block = mrb_funcall(mrb, mod_val, "b_startup", 0);
mrb_funcall(mrb, block, "call", 0);
}
inline static std::vector<BarLight>
convert_highlights(mrb_state *mrb, mrb_value highlights_val) {
std::vector<BarLight> result;
if (!mrb_array_p(highlights_val))
return result;
mrb_int len = RARRAY_LEN(highlights_val);
for (mrb_int i = 0; i < len; i++) {
mrb_value item = mrb_ary_ref(mrb, highlights_val, i);
if (!mrb_hash_p(item))
continue;
auto get_sym = [&](const char *name) {
return mrb_symbol_value(mrb_intern_cstr(mrb, name));
};
mrb_value fg_v = mrb_hash_get(mrb, item, get_sym("fg"));
mrb_value bg_v = mrb_hash_get(mrb, item, get_sym("bg"));
mrb_value flags_v = mrb_hash_get(mrb, item, get_sym("flags"));
mrb_value start_v = mrb_hash_get(mrb, item, get_sym("start"));
mrb_value length_v = mrb_hash_get(mrb, item, get_sym("length"));
BarLight bl{};
if (!mrb_nil_p(fg_v))
bl.highlight.fg = (uint32_t)mrb_fixnum(fg_v);
if (!mrb_nil_p(bg_v))
bl.highlight.bg = (uint32_t)mrb_fixnum(bg_v);
if (!mrb_nil_p(flags_v))
bl.highlight.flags = (uint32_t)mrb_fixnum(flags_v);
uint32_t start = !mrb_nil_p(start_v) ? (uint32_t)mrb_fixnum(start_v) : 0;
uint32_t length = !mrb_nil_p(length_v) ? (uint32_t)mrb_fixnum(length_v) : 0;
bl.start = start;
bl.end = start + length;
result.push_back(bl);
}
return result;
}
BarLine bar_contents(uint8_t mode, std::string lang_name, uint32_t warnings,
std::string lsp_name, std::string filename,
std::string foldername, uint32_t line, uint32_t max_line,
uint32_t width) {
BarLine bar_line;
mrb_value info = mrb_hash_new(mrb);
mrb_value key_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "mode"));
mrb_value val_mode;
switch (mode) {
case NORMAL:
val_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "normal"));
break;
case INSERT:
val_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "insert"));
break;
case SELECT:
val_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "select"));
break;
case RUNNER:
val_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "runner"));
break;
case JUMPER:
val_mode = mrb_symbol_value(mrb_intern_cstr(mrb, "jumper"));
break;
}
mrb_hash_set(mrb, info, key_mode, val_mode);
mrb_value key_lang_name = mrb_symbol_value(mrb_intern_cstr(mrb, "lang_name"));
mrb_value val_lang_name =
mrb_symbol_value(mrb_intern_cstr(mrb, lang_name.c_str()));
mrb_hash_set(mrb, info, key_lang_name, val_lang_name);
mrb_value key_filename = mrb_symbol_value(mrb_intern_cstr(mrb, "filename"));
mrb_value val_filename =
mrb_str_new(mrb, filename.c_str(), filename.length());
mrb_hash_set(mrb, info, key_filename, val_filename);
mrb_value key_width = mrb_symbol_value(mrb_intern_cstr(mrb, "width"));
mrb_value val_width = mrb_fixnum_value(width);
mrb_hash_set(mrb, info, key_width, val_width);
mrb_value mod_val = mrb_obj_value(C_module);
mrb_value block = mrb_funcall(mrb, mod_val, "b_bar", 0);
mrb_value val_line = mrb_funcall(mrb, block, "call", 1, info);
if (mrb->exc)
exit(1);
mrb_value text_val = mrb_hash_get(
mrb, val_line, mrb_symbol_value(mrb_intern_cstr(mrb, "text")));
const char *ptr = RSTRING_PTR(text_val);
mrb_int len = RSTRING_LEN(text_val);
bar_line.line = std::string(ptr, len);
mrb_value highlights_val = mrb_hash_get(
mrb, val_line, mrb_symbol_value(mrb_intern_cstr(mrb, "highlights")));
bar_line.highlights = convert_highlights(mrb, highlights_val);
return bar_line;
}
void ruby_shutdown() {
if (C_module == nullptr)
return;
mrb_value mod_val = mrb_obj_value(C_module);
mrb_value block = mrb_funcall(mrb, mod_val, "b_shutdown", 0);
mrb_funcall(mrb, block, "call", 0);
mrb_close(mrb);
mrb = nullptr;
C_module = nullptr;
}
std::vector<std::string> array_to_vector(mrb_value ary) {
std::vector<std::string> result;
if (mrb_nil_p(ary) || mrb_type(ary) != MRB_TT_ARRAY)
return result;
mrb_int len = RARRAY_LEN(ary);
for (mrb_int i = 0; i < len; i++) {
mrb_value item = mrb_ary_ref(mrb, ary, i);
if (mrb_string_p(item))
result.push_back(std::string(RSTRING_PTR(item), RSTRING_LEN(item)));
}
return result;
}
void load_custom_highlighters() {
if (!C_module)
return;
mrb_value mod_val = mrb_obj_value((struct RObject *)C_module);
mrb_value hashmap = mrb_funcall(mrb, mod_val, "highlighters", 0);
if (mrb_nil_p(hashmap) || mrb_type(hashmap) != MRB_TT_HASH)
return;
mrb_value keys = mrb_funcall(mrb, hashmap, "keys", 0);
mrb_int len = RARRAY_LEN(keys);
for (mrb_int i = 0; i < len; i++) {
mrb_value key_sym = mrb_ary_ref(mrb, keys, i);
mrb_sym sym_id = mrb_symbol(key_sym);
const char *key_cstr = mrb_sym_dump(mrb, sym_id);
std::string key(key_cstr);
mrb_value val_hash = mrb_hash_get(mrb, hashmap, key_sym);
if (mrb_nil_p(val_hash) || mrb_type(val_hash) != MRB_TT_HASH)
continue;
mrb_sym parser_sym = mrb_intern_lit(mrb, "parser");
mrb_sym matcher_sym = mrb_intern_lit(mrb, "matcher");
mrb_value parse_block =
mrb_hash_get(mrb, val_hash, mrb_symbol_value(parser_sym));
mrb_value match_block =
mrb_hash_get(mrb, val_hash, mrb_symbol_value(matcher_sym));
custom_highlighters[key] = {parse_block, match_block};
}
}
bool custom_compare(mrb_value match_block, mrb_value state1, mrb_value state2) {
if (mrb_type(match_block) != MRB_TT_PROC)
return false;
mrb_value ret = mrb_funcall(mrb, match_block, "call", 2, state1, state2);
return mrb_test(ret);
}
mrb_value parse_custom(std::vector<Token> *tokens, mrb_value parser_block,
const char *line, uint32_t len, mrb_value state,
uint32_t c_line) {
tokens->clear();
if (mrb_nil_p(parser_block))
return mrb_nil_value();
mrb_value ruby_line = mrb_str_new(mrb, line, len);
mrb_value line_idx = mrb_fixnum_value(c_line);
mrb_value tokens_and_state_hash =
mrb_funcall(mrb, parser_block, "call", 3, ruby_line, state, line_idx);
mrb_sym tokens_sym = mrb_intern_lit(mrb, "tokens");
mrb_value tokens_rb =
mrb_hash_get(mrb, tokens_and_state_hash, mrb_symbol_value(tokens_sym));
if (mrb_type(tokens_rb) == MRB_TT_ARRAY) {
mrb_int len_tokens = RARRAY_LEN(tokens_rb);
for (mrb_int i = 0; i < len_tokens; i++) {
mrb_value token = mrb_ary_ref(mrb, tokens_rb, i);
Token tok;
tok.type = (TokenKind)mrb_fixnum(mrb_hash_get(
mrb, token, mrb_symbol_value(mrb_intern_lit(mrb, "type"))));
tok.start = (uint32_t)mrb_fixnum(mrb_hash_get(
mrb, token, mrb_symbol_value(mrb_intern_lit(mrb, "start"))));
tok.end = (uint32_t)mrb_fixnum(mrb_hash_get(
mrb, token, mrb_symbol_value(mrb_intern_lit(mrb, "end"))));
if (tok.type < TokenKind::Count && tok.end > tok.start && tok.end <= len)
tokens->push_back(tok);
}
}
mrb_sym state_sym = mrb_intern_lit(mrb, "state");
return mrb_hash_get(mrb, tokens_and_state_hash, mrb_symbol_value(state_sym));
}
static std::vector<R_ThemeEntry> read_theme() {
std::vector<R_ThemeEntry> result;
if (!C_module)
return result;
mrb_value mod_val = mrb_obj_value((struct RObject *)C_module);
mrb_value theme_hash = mrb_funcall(mrb, mod_val, "theme", 0);
if (mrb_nil_p(theme_hash) || mrb_type(theme_hash) != MRB_TT_HASH)
return result;
mrb_value keys = mrb_funcall(mrb, theme_hash, "keys", 0);
mrb_int len_keys = RARRAY_LEN(keys);
for (mrb_int i = 0; i < len_keys; i++) {
mrb_value key_sym = mrb_ary_ref(mrb, keys, i);
mrb_sym sym_id = mrb_symbol(key_sym);
const char *key_cstr = mrb_sym_dump(mrb, sym_id);
std::string key(key_cstr);
mrb_value val_hash = mrb_hash_get(mrb, theme_hash, key_sym);
if (mrb_nil_p(val_hash) || mrb_type(val_hash) != MRB_TT_HASH)
continue;
R_ThemeEntry entry;
entry.key = key;
mrb_value fg = mrb_hash_get(mrb, val_hash,
mrb_symbol_value(mrb_intern_lit(mrb, "fg")));
mrb_value bg = mrb_hash_get(mrb, val_hash,
mrb_symbol_value(mrb_intern_lit(mrb, "bg")));
mrb_value italic = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "italic")));
mrb_value bold = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "bold")));
mrb_value underline = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "underline")));
mrb_value strikethrough = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "strikethrough")));
if (!mrb_nil_p(fg))
entry.fg = (uint32_t)mrb_fixnum(fg);
if (!mrb_nil_p(bg))
entry.bg = (uint32_t)mrb_fixnum(bg);
if (!mrb_nil_p(italic))
entry.italic = mrb_test(italic);
if (!mrb_nil_p(bold))
entry.bold = mrb_test(bold);
if (!mrb_nil_p(underline))
entry.underline = mrb_test(underline);
if (!mrb_nil_p(strikethrough))
entry.strikethrough = mrb_test(strikethrough);
result.push_back(entry);
}
return result;
}
void load_theme() {
std::vector<R_ThemeEntry> entries = read_theme();
Highlight default_hl = {0xFFFFFF, 0, 0};
for (auto &entry : entries) {
if (entry.key == "default") {
default_hl.fg = entry.fg;
default_hl.bg = entry.bg;
if (entry.italic)
default_hl.flags |= CF_ITALIC;
if (entry.bold)
default_hl.flags |= CF_BOLD;
if (entry.underline)
default_hl.flags |= CF_UNDERLINE;
if (entry.strikethrough)
default_hl.flags |= CF_STRIKETHROUGH;
break;
}
}
for (auto &hl : highlights)
hl = default_hl;
for (auto &entry : entries) {
if (entry.key == "default")
continue;
std::string key = "k_" + entry.key;
for (char &c : key)
c = std::toupper(static_cast<unsigned char>(c));
auto it = kind_map.find(key);
if (it == kind_map.end())
continue;
Highlight hl = {0xFFFFFF, 0, 0};
hl.fg = entry.fg;
hl.bg = entry.bg;
if (entry.italic)
hl.flags |= CF_ITALIC;
if (entry.bold)
hl.flags |= CF_BOLD;
if (entry.underline)
hl.flags |= CF_UNDERLINE;
if (entry.strikethrough)
hl.flags |= CF_STRIKETHROUGH;
highlights[static_cast<uint8_t>(it->second)] = hl;
}
}
std::vector<LSP> read_lsps() {
std::vector<LSP> result;
if (!C_module)
return result;
mrb_value mod_val = mrb_obj_value((struct RObject *)C_module);
mrb_value lsp_hash = mrb_funcall(mrb, mod_val, "lsp_config", 0);
if (mrb_nil_p(lsp_hash) || mrb_type(lsp_hash) != MRB_TT_HASH)
return result;
mrb_value keys = mrb_funcall(mrb, lsp_hash, "keys", 0);
mrb_int len_keys = RARRAY_LEN(keys);
for (mrb_int i = 0; i < len_keys; i++) {
mrb_value key = mrb_ary_ref(mrb, keys, i);
std::string cmd;
if (mrb_string_p(key))
cmd = std::string(RSTRING_PTR(key), RSTRING_LEN(key));
else if (mrb_symbol_p(key))
cmd = std::string(mrb_sym_dump(mrb, mrb_symbol(key)));
mrb_value args_array = mrb_hash_get(mrb, lsp_hash, key);
std::vector<std::string> args = array_to_vector(args_array);
result.push_back({cmd, args});
}
return result;
}
std::vector<R_Language> read_languages() {
std::vector<R_Language> result;
if (!C_module)
return result;
mrb_value mod_val = mrb_obj_value((struct RObject *)C_module);
mrb_value lang_hash = mrb_funcall(mrb, mod_val, "languages", 0);
if (mrb_nil_p(lang_hash) || mrb_type(lang_hash) != MRB_TT_HASH)
return result;
mrb_value keys = mrb_funcall(mrb, lang_hash, "keys", 0);
mrb_int len_keys = RARRAY_LEN(keys);
for (mrb_int i = 0; i < len_keys; i++) {
mrb_value key = mrb_ary_ref(mrb, keys, i);
mrb_value val_hash = mrb_hash_get(mrb, lang_hash, key);
if (mrb_nil_p(val_hash) || mrb_type(val_hash) != MRB_TT_HASH)
continue;
R_Language lang;
if (mrb_symbol_p(key))
lang.name = std::string(mrb_sym_dump(mrb, mrb_symbol(key)));
else if (mrb_string_p(key))
lang.name = std::string(RSTRING_PTR(key), RSTRING_LEN(key));
mrb_value fg = mrb_hash_get(mrb, val_hash,
mrb_symbol_value(mrb_intern_lit(mrb, "color")));
mrb_value extensions = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "extensions")));
mrb_value filenames = mrb_hash_get(
mrb, val_hash, mrb_symbol_value(mrb_intern_lit(mrb, "filenames")));
mrb_value lsp = mrb_hash_get(mrb, val_hash,
mrb_symbol_value(mrb_intern_lit(mrb, "lsp")));
if (!mrb_nil_p(fg))
lang.color = (uint32_t)mrb_fixnum(fg);
lang.extensions = array_to_vector(extensions);
if (!mrb_nil_p(filenames))
lang.filenames = array_to_vector(filenames);
if (!mrb_nil_p(lsp))
lang.lsp_command = std::string(RSTRING_PTR(lsp), RSTRING_LEN(lsp));
result.push_back(lang);
}
return result;
}
void load_languages_info() {
auto langs = read_languages();
auto lsps_t = read_lsps();
languages.clear();
for (auto &lang : langs) {
Language l;
l.name = lang.name;
l.color = lang.color;
l.lsp_name = lang.lsp_command;
languages[lang.name] = l;
for (auto &ext : lang.extensions)
language_extensions[ext] = lang.name;
// TODO: seperate extensions and filenames
for (auto &filename : lang.filenames)
language_extensions[filename] = lang.name;
}
for (auto &lsp : lsps_t)
lsps[lsp.command] = lsp;
}
uint8_t read_line_endings() {
if (!C_module)
return 1;
mrb_value mod_val = mrb_obj_value((struct RObject *)C_module);
mrb_value le = mrb_funcall(mrb, mod_val, "line_endings", 0);
if (!mrb_symbol_p(le))
return 1;
uint8_t flags = 1;
const char *name = mrb_sym_dump(mrb, mrb_symbol(le));
if (std::strcmp(name, "unix") == 0)
flags = 0b01;
else if (std::strcmp(name, "windows") == 0)
flags = 0b00;
else if (std::strcmp(name, "auto_unix") == 0)
flags = 0b11;
else if (std::strcmp(name, "auto_windows") == 0)
flags = 0b10;
return flags;
}

View File

@@ -1,23 +1,20 @@
#include "syntax/decl.h" #include "syntax/decl.h"
#include "syntax/langs.h" #include "syntax/langs.h"
#include "utils/utils.h"
struct BashFullState { struct BashFullState {
int brace_level = 0; int brace_level = 0;
enum : uint8_t { NONE, STRING, HEREDOC }; enum : uint8_t { NONE, STRING, HEREDOC, PARAMETER };
uint8_t in_state = BashFullState::NONE; uint8_t in_state = BashFullState::NONE;
bool line_cont = false; bool line_cont = false;
struct Lit { struct Lit {
std::string delim = ""; std::string delim = ""; // Only 1 wide for strings
int brace_level = 1;
bool allow_interp = false; bool allow_interp = false;
bool operator==(const BashFullState::Lit &other) const { bool operator==(const BashFullState::Lit &other) const {
return delim == other.delim && brace_level == other.brace_level && return delim == other.delim && allow_interp == other.allow_interp;
allow_interp == other.allow_interp;
} }
} lit; } lit;
@@ -52,7 +49,8 @@ bool bash_state_match(std::shared_ptr<void> state_1,
std::shared_ptr<void> bash_parse(std::vector<Token> *tokens, std::shared_ptr<void> bash_parse(std::vector<Token> *tokens,
std::shared_ptr<void> in_state, std::shared_ptr<void> in_state,
const char *text, uint32_t len) { const char *text, uint32_t len,
uint32_t line_num) {
static bool keywords_trie_init = false; static bool keywords_trie_init = false;
if (!keywords_trie_init) { if (!keywords_trie_init) {
keywords_trie_init = true; keywords_trie_init = true;
@@ -66,7 +64,75 @@ std::shared_ptr<void> bash_parse(std::vector<Token> *tokens,
if (len == 0) if (len == 0)
return state; return state;
while (i < len) { while (i < len) {
i += utf8_codepoint_width(text[i]); if (state->full_state->in_state == BashFullState::PARAMETER) {
uint32_t start = i;
while (i < len) {
if (text[i] == '{') {
i++;
state->full_state->brace_level++;
continue;
}
if (text[i] == '}') {
if (--state->full_state->brace_level == 0 &&
!state->interp_stack.empty()) {
tokens->push_back({i - 1, i, TokenKind::K_INTERPOLATION});
state->full_state = state->interp_stack.top();
state->interp_stack.pop();
i++;
break;
}
}
i++;
}
continue;
}
if (state->full_state->in_state == BashFullState::STRING) {
uint32_t start = i;
while (i < len) {
if (state->full_state->lit.allow_interp && text[i] == '$') {
if (++i < len && text[i] == '{') {
tokens->push_back({start, i - 1, TokenKind::K_STRING});
tokens->push_back({i - 1, i, TokenKind::K_INTERPOLATION});
state->interp_stack.push(state->full_state);
state->full_state = std::make_shared<BashFullState>();
state->full_state->in_state = BashFullState::PARAMETER;
state->full_state->brace_level = 1;
break;
}
}
if (text[i] == state->full_state->lit.delim[0]) {
i++;
tokens->push_back({start, i, TokenKind::K_STRING});
state->full_state->in_state = BashFullState::NONE;
break;
}
i++;
}
if (i == len)
tokens->push_back({start, i, TokenKind::K_STRING});
continue;
}
if (text[i] == '#') {
if (line_num == 0 && i == 0 && len > 4 && text[i + 1] == '!') {
tokens->push_back({0, len, TokenKind::K_SHEBANG});
return state;
}
tokens->push_back({i, len, TokenKind::K_COMMENT});
return state;
} else if (text[i] == '\'') {
state->full_state->in_state = BashFullState::STRING;
state->full_state->lit.delim = "'";
state->full_state->lit.allow_interp = false;
tokens->push_back({i, ++i, TokenKind::K_STRING});
continue;
} else if (text[i] == '"') {
state->full_state->in_state = BashFullState::STRING;
state->full_state->lit.delim = "\"";
state->full_state->lit.allow_interp = true;
tokens->push_back({i, ++i, TokenKind::K_STRING});
continue;
}
i++;
} }
return state; return state;
} }
@@ -76,3 +142,6 @@ std::shared_ptr<void> bash_parse(std::vector<Token> *tokens,
// ${var} and $((math)) $(command) and `command` expansions ANSI-C quoted // ${var} and $((math)) $(command) and `command` expansions ANSI-C quoted
// stirngs - $'' backslash escapes but with \xHH and \uHHHH and \uHHHHHHHH \cX // stirngs - $'' backslash escapes but with \xHH and \uHHHH and \uHHHHHHHH \cX
// too // too
//
// Lock edit_replace across both delete and insert instead of within to keep the
// parser from glitching

0
src/syntax/extras.cc Normal file
View File

View File

@@ -1,4 +1,5 @@
#include "syntax/parser.h" #include "syntax/parser.h"
#include "editor/editor.h"
#include "io/knot.h" #include "io/knot.h"
#include "main.h" #include "main.h"
#include "syntax/decl.h" #include "syntax/decl.h"
@@ -6,68 +7,95 @@
std::array<Highlight, TOKEN_KIND_COUNT> highlights = {}; std::array<Highlight, TOKEN_KIND_COUNT> highlights = {};
Parser::Parser(Knot *n_root, std::shared_mutex *n_knot_mutex, Parser::Parser(Editor *n_editor, std::string n_lang, uint32_t n_scroll_max) {
std::string n_lang, uint32_t n_scroll_max) { editor = n_editor;
scroll_max = n_scroll_max; scroll_max = n_scroll_max;
knot_mutex = n_knot_mutex;
lang = n_lang; lang = n_lang;
auto custom_parser = custom_highlighters.find(n_lang);
if (custom_parser != custom_highlighters.end()) {
parser_block = custom_parser->second.first;
match_block = custom_parser->second.second;
is_custom = true;
} else {
auto pair = parsers.find(n_lang); auto pair = parsers.find(n_lang);
if (pair != parsers.end()) { if (pair != parsers.end()) {
parse_func = std::get<0>(pair->second); parse_func = std::get<0>(pair->second);
state_match_func = std::get<1>(pair->second); state_match_func = std::get<1>(pair->second);
is_custom = false;
} else { } else {
assert("unknown lang should be checked by caller" && 0); assert("unknown lang should be checked by caller" && 0);
} }
edit(n_root, 0, 0, n_root->line_count); }
edit(0, 0, editor->root->line_count);
} }
void Parser::edit(Knot *n_root, uint32_t start_line, uint32_t old_end_line, void Parser::edit(uint32_t start_line, uint32_t old_end_line,
uint32_t new_end_line) { uint32_t inserted_rows) {
std::lock_guard lock(data_mutex); std::lock_guard lock(data_mutex);
root = n_root;
if (((int64_t)old_end_line - (int64_t)start_line) > 0) if (((int64_t)old_end_line - (int64_t)start_line) > 0)
line_tree.erase(start_line + 1, old_end_line - start_line); line_tree.erase(start_line, old_end_line - start_line);
if (((int64_t)new_end_line - (int64_t)old_end_line) > 0) if (inserted_rows > 0)
line_tree.insert(start_line + 1, new_end_line - start_line); line_tree.insert(start_line, inserted_rows);
dirty_lines.insert(start_line); if (start_line > 0)
dirty_lines.push(start_line - 1);
dirty_lines.push(start_line);
dirty_lines.push(start_line + 1);
} }
void Parser::work() { void Parser::work() {
std::shared_lock k_lock(*knot_mutex); if (!editor || !editor->root)
return;
std::shared_lock k_lock(editor->knot_mtx);
k_lock.unlock(); k_lock.unlock();
uint32_t capacity = 256; uint32_t capacity = 256;
char *text = (char *)calloc((capacity + 1), sizeof(char)); char *text = (char *)calloc((capacity + 1), sizeof(char));
std::set<uint32_t> tmp_dirty;
std::unique_lock lock_data(data_mutex); std::unique_lock lock_data(data_mutex);
tmp_dirty.swap(dirty_lines);
lock_data.unlock(); lock_data.unlock();
std::set<uint32_t> remaining_dirty;
std::unique_lock lock(mutex); std::unique_lock lock(mutex);
lock.unlock(); lock.unlock();
for (uint32_t c_line : tmp_dirty) { uint32_t c_line;
if (c_line > scroll_max) { while (dirty_lines.pop(c_line)) {
remaining_dirty.insert(c_line); if (!running.load(std::memory_order_relaxed)) {
free(text);
return;
}
if (c_line > scroll_max + 40) {
dirty_lines.push(c_line);
continue;
}
if (scroll_max > 50 && c_line < scroll_max - 50) {
dirty_lines.push(c_line);
continue; continue;
} }
uint32_t line_count = line_tree.count(); uint32_t line_count = line_tree.count();
lock_data.lock(); lock_data.lock();
std::shared_ptr<void> prev_state = std::shared_ptr<void> prev_state =
(c_line > 0) ? line_tree.at(c_line - 1)->out_state : nullptr; (c_line > 0) && c_line < line_tree.count()
? line_tree.at(c_line - 1)->out_state
: nullptr;
lock_data.unlock(); lock_data.unlock();
while (c_line < line_count) { while (c_line < line_count) {
if (!running.load(std::memory_order_relaxed)) { if (!running.load(std::memory_order_relaxed)) {
free(text); free(text);
return; return;
} }
if (scroll_dirty.exchange(false, std::memory_order_acq_rel)) {
dirty_lines.push(c_line);
c_line = scroll_max < 50 ? 0 : scroll_max - 50;
}
k_lock.lock(); k_lock.lock();
if (c_line > editor->root->line_count) {
k_lock.unlock();
continue;
}
uint32_t r_offset, r_len; uint32_t r_offset, r_len;
r_offset = line_to_byte(root, c_line, &r_len); r_offset = line_to_byte(editor->root, c_line, &r_len);
if (r_len > capacity) { if (r_len > capacity) {
capacity = r_len; capacity = r_len;
text = (char *)realloc(text, capacity + 1); text = (char *)realloc(text, capacity + 1);
memset(text, 0, capacity + 1); memset(text, 0, capacity + 1);
} }
read_into(root, r_offset, r_len, text); read_into(editor->root, r_offset, r_len, text);
k_lock.unlock(); k_lock.unlock();
if (c_line < scroll_max && if (c_line < scroll_max &&
((scroll_max > 100 && c_line > scroll_max - 100) || c_line < 100)) ((scroll_max > 100 && c_line > scroll_max - 100) || c_line < 100))
@@ -79,8 +107,29 @@ void Parser::work() {
} }
lock_data.lock(); lock_data.lock();
LineData *line_data = line_tree.at(c_line); LineData *line_data = line_tree.at(c_line);
std::shared_ptr<void> new_state = if (!line_data) {
parse_func(&line_data->tokens, prev_state, text, r_len); lock_data.unlock();
if (lock.owns_lock())
lock.unlock();
continue;
}
std::shared_ptr<void> new_state{nullptr};
if (is_custom) {
mrb_value state = mrb_nil_value();
if (prev_state) {
std::shared_ptr<CustomState> state_ptr =
std::static_pointer_cast<CustomState>(prev_state);
state = state_ptr->state;
}
mrb_value out_state = parse_custom(&line_data->tokens, parser_block,
text, r_len, state, c_line);
std::shared_ptr<CustomState> out_state_ptr =
std::make_shared<CustomState>(out_state);
new_state = out_state_ptr;
} else {
new_state =
parse_func(&line_data->tokens, prev_state, text, r_len, c_line);
}
line_data->in_state = prev_state; line_data->in_state = prev_state;
line_data->out_state = new_state; line_data->out_state = new_state;
if (!running.load(std::memory_order_relaxed)) { if (!running.load(std::memory_order_relaxed)) {
@@ -89,22 +138,39 @@ void Parser::work() {
} }
prev_state = new_state; prev_state = new_state;
c_line++; c_line++;
if (c_line < line_count && c_line > scroll_max + 50) { if (c_line < line_count && c_line > scroll_max + 50 && scroll_max < 50 &&
c_line < scroll_max + 50) {
lock_data.unlock(); lock_data.unlock();
if (lock.owns_lock()) if (lock.owns_lock())
lock.unlock(); lock.unlock();
if (c_line > 0) if (c_line > 0)
remaining_dirty.insert(c_line - 1); dirty_lines.push(c_line - 1);
remaining_dirty.insert(c_line); dirty_lines.push(c_line);
break; break;
} }
if (c_line < line_count && if (c_line < line_count && (line_data = line_tree.at(c_line))) {
state_match_func(prev_state, line_tree.at(c_line)->in_state)) { bool done = false;
if (is_custom) {
mrb_value in_state_v = mrb_nil_value();
if (prev_state)
in_state_v =
std::static_pointer_cast<CustomState>(prev_state)->state;
mrb_value out_state_v = mrb_nil_value();
if (line_data->in_state)
out_state_v =
std::static_pointer_cast<CustomState>(line_data->in_state)
->state;
done = custom_compare(match_block, in_state_v, out_state_v);
} else {
done = state_match_func(prev_state, line_data->in_state);
}
if (done) {
lock_data.unlock(); lock_data.unlock();
if (lock.owns_lock()) if (lock.owns_lock())
lock.unlock(); lock.unlock();
break; break;
} }
}
lock_data.unlock(); lock_data.unlock();
if (lock.owns_lock()) if (lock.owns_lock())
lock.unlock(); lock.unlock();
@@ -116,70 +182,19 @@ void Parser::work() {
} }
free(text); free(text);
lock_data.lock(); lock_data.lock();
dirty_lines = std::move(remaining_dirty);
} }
void Parser::scroll(uint32_t line) { void Parser::scroll(uint32_t line) {
if (line != scroll_max) { if (line != scroll_max) {
scroll_max = line; scroll_max = line;
uint32_t c_line = line > 100 ? line - 100 : 0; uint32_t c_line = line > 50 ? line - 50 : 0;
if (line_tree.count() < c_line) if (c_line >= line_tree.count())
return; return;
std::unique_lock lock_data(data_mutex); std::unique_lock lock_data(data_mutex);
if (line_tree.at(c_line)->in_state || line_tree.at(c_line)->out_state) if (line_tree.at(c_line)->in_state || line_tree.at(c_line)->out_state)
return; return;
lock_data.unlock(); scroll_dirty = true;
std::shared_lock k_lock(*knot_mutex); dirty_lines.push(c_line);
k_lock.unlock();
uint32_t capacity = 256;
char *text = (char *)calloc((capacity + 1), sizeof(char));
uint32_t line_count = line_tree.count();
std::unique_lock lock(mutex);
std::shared_ptr<void> prev_state =
(c_line > 0) ? line_tree.at(c_line - 1)->out_state : nullptr;
lock.unlock();
while (c_line < line_count) {
if (!running.load(std::memory_order_relaxed)) {
free(text);
return;
}
k_lock.lock();
uint32_t r_offset, r_len;
r_offset = line_to_byte(root, c_line, &r_len);
if (r_len > capacity) {
capacity = r_len;
text = (char *)realloc(text, capacity + 1);
memset(text, 0, capacity + 1);
}
read_into(root, r_offset, r_len, text);
k_lock.unlock();
if (c_line < scroll_max &&
((scroll_max > 100 && c_line > scroll_max - 100) || c_line < 100))
lock.lock();
if (line_tree.count() < c_line) {
if (lock.owns_lock())
lock.unlock();
continue;
}
lock_data.lock();
LineData *line_data = line_tree.at(c_line);
std::shared_ptr<void> new_state =
parse_func(&line_data->tokens, prev_state, text, r_len);
line_data->in_state = nullptr;
line_data->out_state = new_state;
lock_data.unlock();
if (lock.owns_lock())
lock.unlock();
if (!running.load(std::memory_order_relaxed)) {
free(text);
return;
}
prev_state = new_state;
c_line++;
if (c_line < line_count && c_line > scroll_max + 50)
break;
}
free(text);
} else { } else {
scroll_max = line; scroll_max = line;
} }

View File

@@ -288,17 +288,18 @@ bool ruby_state_match(std::shared_ptr<void> state_1,
std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens, std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
std::shared_ptr<void> in_state, std::shared_ptr<void> in_state,
const char *text, uint32_t len) { const char *text, uint32_t len,
uint32_t line_num) {
static bool keywords_trie_init = false; static bool keywords_trie_init = false;
static Trie base_keywords_trie; static Trie<void> base_keywords_trie;
static Trie expecting_keywords_trie; static Trie<void> expecting_keywords_trie;
static Trie operator_keywords_trie; static Trie<void> operator_keywords_trie;
static Trie expecting_operators_trie; static Trie<void> expecting_operators_trie;
static Trie operator_trie; static Trie<void> operator_trie;
static Trie types_trie; static Trie<void> types_trie;
static Trie builtins_trie; static Trie<void> builtins_trie;
static Trie methods_trie; static Trie<void> methods_trie;
static Trie errors_trie; static Trie<void> errors_trie;
if (!keywords_trie_init) { if (!keywords_trie_init) {
base_keywords_trie.build(base_keywords); base_keywords_trie.build(base_keywords);
expecting_keywords_trie.build(expecting_keywords); expecting_keywords_trie.build(expecting_keywords);
@@ -324,7 +325,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (state->full_state->in_state == RubyFullState::END) if (state->full_state->in_state == RubyFullState::END)
return state; return state;
if (state->full_state->in_state == RubyFullState::COMMENT) { if (state->full_state->in_state == RubyFullState::COMMENT) {
tokens->push_back({i, len, TokenKind::Comment}); tokens->push_back({i, len, TokenKind::K_COMMENT});
if (i == 0 && len == 4 && text[i] == '=' && text[i + 1] == 'e' && if (i == 0 && len == 4 && text[i] == '=' && text[i + 1] == 'e' &&
text[i + 2] == 'n' && text[i + 3] == 'd') { text[i + 2] == 'n' && text[i + 3] == 'd') {
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
@@ -344,18 +345,18 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
state->heredocs.pop_front(); state->heredocs.pop_front();
if (state->heredocs.empty()) if (state->heredocs.empty())
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
tokens->push_back({i, len, TokenKind::Annotation}); tokens->push_back({i, len, TokenKind::K_ANNOTATION});
return state; return state;
} }
} }
uint32_t start = i; uint32_t start = i;
if (!state->heredocs.front().allow_interpolation) { if (!state->heredocs.front().allow_interpolation) {
tokens->push_back({i, len, TokenKind::String}); tokens->push_back({i, len, TokenKind::K_STRING});
return state; return state;
} else { } else {
while (i < len) { while (i < len) {
if (text[i] == '\\') { if (text[i] == '\\') {
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
start = i; start = i;
i++; i++;
if (i < len && text[i] == 'x') { if (i < len && text[i] == 'x') {
@@ -412,12 +413,12 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (i < len) if (i < len)
i++; i++;
} }
tokens->push_back({start, i, TokenKind::Escape}); tokens->push_back({start, i, TokenKind::K_ESCAPE});
continue; continue;
} }
if (text[i] == '#' && i + 1 < len && text[i + 1] == '{') { if (text[i] == '#' && i + 1 < len && text[i + 1] == '{') {
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
tokens->push_back({i, i + 2, TokenKind::Interpolation}); tokens->push_back({i, i + 2, TokenKind::K_INTERPOLATION});
i += 2; i += 2;
state->interp_stack.push(state->full_state); state->interp_stack.push(state->full_state);
state->full_state = std::make_shared<RubyFullState>(); state->full_state = std::make_shared<RubyFullState>();
@@ -427,7 +428,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
} }
if (i == len) if (i == len)
tokens->push_back({start, len, TokenKind::String}); tokens->push_back({start, len, TokenKind::K_STRING});
continue; continue;
} }
} }
@@ -435,7 +436,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
uint32_t start = i; uint32_t start = i;
while (i < len) { while (i < len) {
if (text[i] == '\\') { if (text[i] == '\\') {
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
start = i; start = i;
i++; i++;
if (i < len && text[i] == 'x') { if (i < len && text[i] == 'x') {
@@ -492,13 +493,13 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (i < len) if (i < len)
i++; i++;
} }
tokens->push_back({start, i, TokenKind::Escape}); tokens->push_back({start, i, TokenKind::K_ESCAPE});
continue; continue;
} }
if (state->full_state->lit.allow_interp && text[i] == '#' && if (state->full_state->lit.allow_interp && text[i] == '#' &&
i + 1 < len && text[i + 1] == '{') { i + 1 < len && text[i + 1] == '{') {
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
tokens->push_back({i, i + 2, TokenKind::Interpolation}); tokens->push_back({i, i + 2, TokenKind::K_INTERPOLATION});
i += 2; i += 2;
state->interp_stack.push(state->full_state); state->interp_stack.push(state->full_state);
state->full_state = std::make_shared<RubyFullState>(); state->full_state = std::make_shared<RubyFullState>();
@@ -514,7 +515,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (state->full_state->lit.delim_start == if (state->full_state->lit.delim_start ==
state->full_state->lit.delim_end) { state->full_state->lit.delim_end) {
i++; i++;
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
break; break;
@@ -522,7 +523,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
state->full_state->lit.brace_level--; state->full_state->lit.brace_level--;
if (state->full_state->lit.brace_level == 0) { if (state->full_state->lit.brace_level == 0) {
i++; i++;
tokens->push_back({start, i, TokenKind::String}); tokens->push_back({start, i, TokenKind::K_STRING});
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
break; break;
@@ -532,14 +533,14 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
} }
if (i == len) if (i == len)
tokens->push_back({start, len, TokenKind::String}); tokens->push_back({start, len, TokenKind::K_STRING});
continue; continue;
} }
if (state->full_state->in_state == RubyFullState::REGEXP) { if (state->full_state->in_state == RubyFullState::REGEXP) {
uint32_t start = i; uint32_t start = i;
while (i < len) { while (i < len) {
if (text[i] == '\\') { if (text[i] == '\\') {
tokens->push_back({start, i, TokenKind::Regexp}); tokens->push_back({start, i, TokenKind::K_REGEXP});
start = i; start = i;
i++; i++;
if (i < len && text[i] == 'x') { if (i < len && text[i] == 'x') {
@@ -596,12 +597,12 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (i < len) if (i < len)
i++; i++;
} }
tokens->push_back({start, i, TokenKind::Escape}); tokens->push_back({start, i, TokenKind::K_ESCAPE});
continue; continue;
} }
if (text[i] == '#' && i + 1 < len && text[i + 1] == '{') { if (text[i] == '#' && i + 1 < len && text[i + 1] == '{') {
tokens->push_back({start, i, TokenKind::Regexp}); tokens->push_back({start, i, TokenKind::K_REGEXP});
tokens->push_back({i, i + 2, TokenKind::Interpolation}); tokens->push_back({i, i + 2, TokenKind::K_INTERPOLATION});
i += 2; i += 2;
state->interp_stack.push(state->full_state); state->interp_stack.push(state->full_state);
state->full_state = std::make_shared<RubyFullState>(); state->full_state = std::make_shared<RubyFullState>();
@@ -617,7 +618,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (state->full_state->lit.delim_start == if (state->full_state->lit.delim_start ==
state->full_state->lit.delim_end) { state->full_state->lit.delim_end) {
i += 1; i += 1;
tokens->push_back({start, i, TokenKind::Regexp}); tokens->push_back({start, i, TokenKind::K_REGEXP});
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
break; break;
@@ -625,7 +626,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
state->full_state->lit.brace_level--; state->full_state->lit.brace_level--;
if (state->full_state->lit.brace_level == 0) { if (state->full_state->lit.brace_level == 0) {
i += 1; i += 1;
tokens->push_back({start, i, TokenKind::Regexp}); tokens->push_back({start, i, TokenKind::K_REGEXP});
state->full_state->in_state = RubyFullState::NONE; state->full_state->in_state = RubyFullState::NONE;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
break; break;
@@ -635,7 +636,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
} }
if (i == len) if (i == len)
tokens->push_back({start, len, TokenKind::Regexp}); tokens->push_back({start, len, TokenKind::K_REGEXP});
continue; continue;
} }
if (i == 0 && len == 6) { if (i == 0 && len == 6) {
@@ -643,7 +644,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
text[i + 3] == 'g' && text[i + 4] == 'i' && text[i + 5] == 'n') { text[i + 3] == 'g' && text[i + 4] == 'i' && text[i + 5] == 'n') {
state->full_state->in_state = RubyFullState::COMMENT; state->full_state->in_state = RubyFullState::COMMENT;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
tokens->push_back({0, len, TokenKind::Comment}); tokens->push_back({0, len, TokenKind::K_COMMENT});
return state; return state;
} }
} }
@@ -664,7 +665,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
indented = true; indented = true;
if (text[j] == '~' || text[j] == '-') if (text[j] == '~' || text[j] == '-')
j++; j++;
tokens->push_back({i, j, TokenKind::Operator}); tokens->push_back({i, j, TokenKind::K_OPERATOR});
if (j >= len) if (j >= len)
continue; continue;
std::string delim; std::string delim;
@@ -685,7 +686,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
} }
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
if (!delim.empty()) { if (!delim.empty()) {
tokens->push_back({s, j, TokenKind::Annotation}); tokens->push_back({s, j, TokenKind::K_ANNOTATION});
state->heredocs.push_back({delim, interpolation, indented}); state->heredocs.push_back({delim, interpolation, indented});
state->full_state->in_state = RubyFullState::HEREDOC; state->full_state->in_state = RubyFullState::HEREDOC;
heredoc_first = true; heredoc_first = true;
@@ -694,7 +695,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
} }
if (text[i] == '/' && state->full_state->expecting_expr) { if (text[i] == '/' && state->full_state->expecting_expr) {
tokens->push_back({i, i + 1, TokenKind::Regexp}); tokens->push_back({i, i + 1, TokenKind::K_REGEXP});
state->full_state->in_state = RubyFullState::REGEXP; state->full_state->in_state = RubyFullState::REGEXP;
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
state->full_state->lit.delim_start = '/'; state->full_state->lit.delim_start = '/';
@@ -703,12 +704,12 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
continue; continue;
} else if (text[i] == '#') { } else if (text[i] == '#') {
if (i == 0 && len > 4 && text[i + 1] == '!') { if (line_num == 0 && i == 0 && len > 4 && text[i + 1] == '!') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
tokens->push_back({0, len, TokenKind::Shebang}); tokens->push_back({0, len, TokenKind::K_SHEBANG});
return state; return state;
} }
tokens->push_back({i, len, TokenKind::Comment}); tokens->push_back({i, len, TokenKind::K_COMMENT});
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
return state; return state;
} else if (text[i] == '.') { } else if (text[i] == '.') {
@@ -720,7 +721,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
} }
} }
tokens->push_back({start, i, TokenKind::Operator}); tokens->push_back({start, i, TokenKind::K_OPERATOR});
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
continue; continue;
} else if (text[i] == ':') { } else if (text[i] == ':') {
@@ -728,7 +729,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
uint32_t start = i; uint32_t start = i;
i++; i++;
if (i >= len) { if (i >= len) {
tokens->push_back({start, i, TokenKind::Operator}); tokens->push_back({start, i, TokenKind::K_OPERATOR});
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
continue; continue;
} }
@@ -737,7 +738,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
} }
if (text[i] == '\'' || text[i] == '"') { if (text[i] == '\'' || text[i] == '"') {
tokens->push_back({start, i, TokenKind::Label}); tokens->push_back({start, i, TokenKind::K_LABEL});
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
continue; continue;
} }
@@ -748,22 +749,22 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
while (i < len && identifier_char(text[i])) while (i < len && identifier_char(text[i]))
i++; i++;
tokens->push_back({start, i, TokenKind::Label}); tokens->push_back({start, i, TokenKind::K_LABEL});
continue; continue;
} }
uint32_t op_len = operator_trie.match(text, i, len, identifier_char); uint32_t op_len = operator_trie.match(text, i, len, identifier_char);
if (op_len > 0) { if (op_len > 0) {
tokens->push_back({start, i + op_len, TokenKind::Label}); tokens->push_back({start, i + op_len, TokenKind::K_LABEL});
i += op_len; i += op_len;
continue; continue;
} }
if (identifier_start_char(text[i])) { if (identifier_start_char(text[i])) {
uint32_t word_len = get_next_word(text, i, len); uint32_t word_len = get_next_word(text, i, len);
tokens->push_back({start, i + word_len, TokenKind::Label}); tokens->push_back({start, i + word_len, TokenKind::K_LABEL});
i += word_len; i += word_len;
continue; continue;
} }
tokens->push_back({start, i, TokenKind::Operator}); tokens->push_back({start, i, TokenKind::K_OPERATOR});
continue; continue;
} else if (text[i] == '@') { } else if (text[i] == '@') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
@@ -779,7 +780,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
while (i < len && identifier_char(text[i])) while (i < len && identifier_char(text[i]))
i++; i++;
tokens->push_back({start, i, TokenKind::VariableInstance}); tokens->push_back({start, i, TokenKind::K_VARIABLEINSTANCE});
continue; continue;
} else if (text[i] == '$') { } else if (text[i] == '$') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
@@ -802,7 +803,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
} else { } else {
continue; continue;
} }
tokens->push_back({start, i, TokenKind::VariableGlobal}); tokens->push_back({start, i, TokenKind::K_VARIABLEGLOBAL});
continue; continue;
} else if (text[i] == '?') { } else if (text[i] == '?') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
@@ -818,7 +819,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
if (i < len && isxdigit(text[i])) if (i < len && isxdigit(text[i]))
i++; i++;
tokens->push_back({start, i, TokenKind::Char}); tokens->push_back({start, i, TokenKind::K_CHAR});
continue; continue;
} else if (i < len && text[i] == 'u') { } else if (i < len && text[i] == 'u') {
i++; i++;
@@ -838,26 +839,26 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
else else
continue; continue;
tokens->push_back({start, i, TokenKind::Char}); tokens->push_back({start, i, TokenKind::K_CHAR});
continue; continue;
} else if (i < len) { } else if (i < len) {
i++; i++;
tokens->push_back({start, i, TokenKind::Char}); tokens->push_back({start, i, TokenKind::K_CHAR});
continue; continue;
} }
} else if (i < len && text[i] != ' ') { } else if (i < len && text[i] != ' ') {
i++; i++;
tokens->push_back({start, i, TokenKind::Char}); tokens->push_back({start, i, TokenKind::K_CHAR});
continue; continue;
} else { } else {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
tokens->push_back({start, i, TokenKind::Operator}); tokens->push_back({start, i, TokenKind::K_OPERATOR});
continue; continue;
} }
} else if (text[i] == '{') { } else if (text[i] == '{') {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
state->interp_level++; state->interp_level++;
state->full_state->brace_level++; state->full_state->brace_level++;
@@ -869,11 +870,11 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (state->interp_level == 0 && !state->interp_stack.empty()) { if (state->interp_level == 0 && !state->interp_stack.empty()) {
state->full_state = state->interp_stack.top(); state->full_state = state->interp_stack.top();
state->interp_stack.pop(); state->interp_stack.pop();
tokens->push_back({i, i + 1, TokenKind::Interpolation}); tokens->push_back({i, i + 1, TokenKind::K_INTERPOLATION});
} else { } else {
state->full_state->brace_level--; state->full_state->brace_level--;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
} }
i++; i++;
@@ -881,7 +882,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
} else if (text[i] == '(') { } else if (text[i] == '(') {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
state->full_state->brace_level++; state->full_state->brace_level++;
i++; i++;
@@ -890,14 +891,14 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
state->full_state->brace_level--; state->full_state->brace_level--;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
i++; i++;
continue; continue;
} else if (text[i] == '[') { } else if (text[i] == '[') {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
state->full_state->brace_level++; state->full_state->brace_level++;
i++; i++;
@@ -906,13 +907,13 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
state->full_state->brace_level--; state->full_state->brace_level--;
uint8_t brace_color = uint8_t brace_color =
(uint8_t)TokenKind::Brace1 + (state->full_state->brace_level % 5); (uint8_t)TokenKind::K_BRACE1 + (state->full_state->brace_level % 5);
tokens->push_back({i, i + 1, (TokenKind)brace_color}); tokens->push_back({i, i + 1, (TokenKind)brace_color});
i++; i++;
continue; continue;
} else if (text[i] == '\'') { } else if (text[i] == '\'') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
tokens->push_back({i, i + 1, TokenKind::String}); tokens->push_back({i, i + 1, TokenKind::K_STRING});
state->full_state->in_state = RubyFullState::STRING; state->full_state->in_state = RubyFullState::STRING;
state->full_state->lit.delim_start = '\''; state->full_state->lit.delim_start = '\'';
state->full_state->lit.delim_end = '\''; state->full_state->lit.delim_end = '\'';
@@ -921,7 +922,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
} else if (text[i] == '"') { } else if (text[i] == '"') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
tokens->push_back({i, i + 1, TokenKind::String}); tokens->push_back({i, i + 1, TokenKind::K_STRING});
state->full_state->in_state = RubyFullState::STRING; state->full_state->in_state = RubyFullState::STRING;
state->full_state->lit.delim_start = '"'; state->full_state->lit.delim_start = '"';
state->full_state->lit.delim_end = '"'; state->full_state->lit.delim_end = '"';
@@ -930,7 +931,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
continue; continue;
} else if (text[i] == '`') { } else if (text[i] == '`') {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
tokens->push_back({i, i + 1, TokenKind::String}); tokens->push_back({i, i + 1, TokenKind::K_STRING});
state->full_state->in_state = RubyFullState::STRING; state->full_state->in_state = RubyFullState::STRING;
state->full_state->lit.delim_start = '`'; state->full_state->lit.delim_start = '`';
state->full_state->lit.delim_end = '`'; state->full_state->lit.delim_end = '`';
@@ -1001,8 +1002,9 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
delim_end = delim_start; delim_end = delim_start;
break; break;
} }
tokens->push_back({i, i + prefix_len + 1, tokens->push_back(
(is_regexp ? TokenKind::Regexp : TokenKind::String)}); {i, i + prefix_len + 1,
(is_regexp ? TokenKind::K_REGEXP : TokenKind::K_STRING)});
state->full_state->in_state = state->full_state->in_state =
is_regexp ? RubyFullState::REGEXP : RubyFullState::STRING; is_regexp ? RubyFullState::REGEXP : RubyFullState::STRING;
state->full_state->lit.delim_start = delim_start; state->full_state->lit.delim_start = delim_start;
@@ -1110,47 +1112,47 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i--; i--;
} }
} }
tokens->push_back({start, i, TokenKind::Number}); tokens->push_back({start, i, TokenKind::K_NUMBER});
continue; continue;
} else if (identifier_start_char(text[i])) { } else if (identifier_start_char(text[i])) {
state->full_state->expecting_expr = false; state->full_state->expecting_expr = false;
uint32_t length; uint32_t length;
if ((length = base_keywords_trie.match(text, i, len, identifier_char))) { if ((length = base_keywords_trie.match(text, i, len, identifier_char))) {
tokens->push_back({i, i + length, TokenKind::Keyword}); tokens->push_back({i, i + length, TokenKind::K_KEYWORD});
i += length; i += length;
continue; continue;
} else if ((length = expecting_keywords_trie.match(text, i, len, } else if ((length = expecting_keywords_trie.match(text, i, len,
identifier_char))) { identifier_char))) {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
tokens->push_back({i, i + length, TokenKind::Keyword}); tokens->push_back({i, i + length, TokenKind::K_KEYWORD});
i += length; i += length;
continue; continue;
} else if ((length = operator_keywords_trie.match(text, i, len, } else if ((length = operator_keywords_trie.match(text, i, len,
identifier_char))) { identifier_char))) {
tokens->push_back({i, i + length, TokenKind::KeywordOperator}); tokens->push_back({i, i + length, TokenKind::K_KEYWORDOPERATOR});
i += length; i += length;
continue; continue;
} else if ((length = expecting_operators_trie.match( } else if ((length = expecting_operators_trie.match(
text, i, len, identifier_char)) > 0) { text, i, len, identifier_char)) > 0) {
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
tokens->push_back({i, i + length, TokenKind::KeywordOperator}); tokens->push_back({i, i + length, TokenKind::K_KEYWORDOPERATOR});
i += length; i += length;
continue; continue;
} else if ((length = types_trie.match(text, i, len, identifier_char))) { } else if ((length = types_trie.match(text, i, len, identifier_char))) {
tokens->push_back({i, i + length, TokenKind::Type}); tokens->push_back({i, i + length, TokenKind::K_TYPE});
i += length; i += length;
continue; continue;
} else if ((length = methods_trie.match(text, i, len, identifier_char))) { } else if ((length = methods_trie.match(text, i, len, identifier_char))) {
tokens->push_back({i, i + length, TokenKind::Function}); tokens->push_back({i, i + length, TokenKind::K_FUNCTION});
i += length; i += length;
continue; continue;
} else if ((length = } else if ((length =
builtins_trie.match(text, i, len, identifier_char))) { builtins_trie.match(text, i, len, identifier_char))) {
tokens->push_back({i, i + length, TokenKind::Constant}); tokens->push_back({i, i + length, TokenKind::K_CONSTANT});
i += length; i += length;
continue; continue;
} else if ((length = errors_trie.match(text, i, len, identifier_char))) { } else if ((length = errors_trie.match(text, i, len, identifier_char))) {
tokens->push_back({i, i + length, TokenKind::Error}); tokens->push_back({i, i + length, TokenKind::K_ERROR});
i += length; i += length;
continue; continue;
} else if (text[i] >= 'A' && text[i] <= 'Z') { } else if (text[i] >= 'A' && text[i] <= 'Z') {
@@ -1158,10 +1160,10 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i += get_next_word(text, i, len); i += get_next_word(text, i, len);
if (i - start >= 5 && text[i - 5] == 'E' && text[i - 4] == 'r' && if (i - start >= 5 && text[i - 5] == 'E' && text[i - 4] == 'r' &&
text[i - 3] == 'r' && text[i - 2] == 'o' && text[i - 1] == 'r') { text[i - 3] == 'r' && text[i - 2] == 'o' && text[i - 1] == 'r') {
tokens->push_back({start, i, TokenKind::Error}); tokens->push_back({start, i, TokenKind::K_ERROR});
continue; continue;
} }
tokens->push_back({start, i, TokenKind::Constant}); tokens->push_back({start, i, TokenKind::K_CONSTANT});
continue; continue;
} else { } else {
uint32_t start = i; uint32_t start = i;
@@ -1169,36 +1171,36 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
text[i + 2] == 'u' && text[i + 3] == 'e' && text[i + 2] == 'u' && text[i + 3] == 'e' &&
((i + 4 < len && !identifier_char(text[i + 4])) || i + 4 == len)) { ((i + 4 < len && !identifier_char(text[i + 4])) || i + 4 == len)) {
i += 4; i += 4;
tokens->push_back({start, i, TokenKind::True}); tokens->push_back({start, i, TokenKind::K_TRUE});
continue; continue;
} }
if (i + 4 < len && text[i] == 'f' && text[i + 1] == 'a' && if (i + 4 < len && text[i] == 'f' && text[i + 1] == 'a' &&
text[i + 2] == 'l' && text[i + 3] == 's' && text[i + 4] == 'e' && text[i + 2] == 'l' && text[i + 3] == 's' && text[i + 4] == 'e' &&
((i + 5 < len && !identifier_char(text[i + 5])) || i + 5 == len)) { ((i + 5 < len && !identifier_char(text[i + 5])) || i + 5 == len)) {
i += 5; i += 5;
tokens->push_back({start, i, TokenKind::False}); tokens->push_back({start, i, TokenKind::K_FALSE});
continue; continue;
} }
if (i + 3 < len && text[i] == 'd' && text[i + 1] == 'e' && if (i + 3 < len && text[i] == 'd' && text[i + 1] == 'e' &&
text[i + 2] == 'f') { text[i + 2] == 'f') {
i += 3; i += 3;
tokens->push_back({start, i, TokenKind::Keyword}); tokens->push_back({start, i, TokenKind::K_KEYWORD});
while (i < len && (text[i] == ' ' || text[i] == '\t')) while (i < len && (text[i] == ' ' || text[i] == '\t'))
i++; i++;
while (i < len) { while (i < len) {
if (identifier_start_char(text[i])) { if (identifier_start_char(text[i])) {
uint32_t width = get_next_word(text, i, len); uint32_t width = get_next_word(text, i, len);
if (text[i] >= 'A' && text[i] <= 'Z') if (text[i] >= 'A' && text[i] <= 'Z')
tokens->push_back({i, i + width, TokenKind::Constant}); tokens->push_back({i, i + width, TokenKind::K_CONSTANT});
else if (width == 4 && (text[i] >= 's' && text[i + 1] == 'e' && else if (width == 4 && (text[i] >= 's' && text[i + 1] == 'e' &&
text[i + 2] == 'l' && text[i + 3] == 'f')) text[i + 2] == 'l' && text[i + 3] == 'f'))
tokens->push_back({i, i + width, TokenKind::Keyword}); tokens->push_back({i, i + width, TokenKind::K_KEYWORD});
i += width; i += width;
if (i < len && text[i] == '.') { if (i < len && text[i] == '.') {
i++; i++;
continue; continue;
} }
tokens->push_back({i - width, i, TokenKind::Function}); tokens->push_back({i - width, i, TokenKind::K_FUNCTION});
break; break;
} else { } else {
break; break;
@@ -1210,15 +1212,15 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
i++; i++;
if (i < len && text[i] == ':') { if (i < len && text[i] == ':') {
i++; i++;
tokens->push_back({start, i, TokenKind::Label}); tokens->push_back({start, i, TokenKind::K_LABEL});
continue; continue;
} else if (i < len && (text[i] == '!' || text[i] == '?')) { } else if (i < len && (text[i] == '!' || text[i] == '?')) {
i++; i++;
tokens->push_back({start, i, TokenKind::Function}); tokens->push_back({start, i, TokenKind::K_FUNCTION});
} else { } else {
uint32_t tmp = i; uint32_t tmp = i;
if (tmp < len && (text[tmp] == '(' || text[tmp] == '{')) { if (tmp < len && (text[tmp] == '(' || text[tmp] == '{')) {
tokens->push_back({start, i, TokenKind::Function}); tokens->push_back({start, i, TokenKind::K_FUNCTION});
continue; continue;
} else if (tmp < len && (text[tmp] == ' ' || text[tmp] == '\t')) { } else if (tmp < len && (text[tmp] == ' ' || text[tmp] == '\t')) {
tmp++; tmp++;
@@ -1230,7 +1232,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
if (tmp >= len) if (tmp >= len)
continue; continue;
if (!isascii(text[tmp])) { if (!isascii(text[tmp])) {
tokens->push_back({start, i, TokenKind::Function}); tokens->push_back({start, i, TokenKind::K_FUNCTION});
continue; continue;
} else if (text[tmp] == '-' || text[tmp] == '&' || text[tmp] == '%' || } else if (text[tmp] == '-' || text[tmp] == '&' || text[tmp] == '%' ||
text[tmp] == ':') { text[tmp] == ':') {
@@ -1244,7 +1246,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
text[tmp] == '^' || text[tmp] == '<' || text[tmp] == '>') { text[tmp] == '^' || text[tmp] == '<' || text[tmp] == '>') {
continue; continue;
} }
tokens->push_back({start, i, TokenKind::Function}); tokens->push_back({start, i, TokenKind::K_FUNCTION});
} }
continue; continue;
} }
@@ -1252,7 +1254,7 @@ std::shared_ptr<void> ruby_parse(std::vector<Token> *tokens,
uint32_t op_len; uint32_t op_len;
if ((op_len = if ((op_len =
operator_trie.match(text, i, len, [](char) { return false; }))) { operator_trie.match(text, i, len, [](char) { return false; }))) {
tokens->push_back({i, i + op_len, TokenKind::Operator}); tokens->push_back({i, i + op_len, TokenKind::K_OPERATOR});
i += op_len; i += op_len;
state->full_state->expecting_expr = true; state->full_state->expecting_expr = true;
continue; continue;

View File

@@ -1,66 +1,59 @@
#include "ui/bar.h" #include "ui/bar.h"
#include "io/sysio.h" #include "io/sysio.h"
#include "lsp/lsp.h"
#include "main.h" #include "main.h"
#include "syntax/decl.h"
void Bar::work() {
std::lock_guard<std::mutex> lock(mtx);
Editor *editor = editors[current_editor];
bar_line =
bar_contents(mode, editor->lang.name, editor->warnings.size(),
editor->lsp ? editor->lsp->lsp->command : "",
editor->filename, editor->filename, editor->cursor.row + 1,
editor->root->line_count + 1, screen.col);
}
void Bar::log(std::string message) {
std::lock_guard<std::mutex> lock(mtx);
log_line = message;
}
void Bar::render() { void Bar::render() {
Editor *editor = editors[current_editor]; std::lock_guard<std::mutex> lock(mtx);
USING(LSPInstance);
uint32_t row = screen.row - 2; uint32_t row = screen.row - 2;
uint32_t col = 0;
uint32_t width = screen.col; uint32_t width = screen.col;
UNUSED(width); std::string &line = bar_line.line;
uint32_t color = 0; uint32_t i = 0;
uint32_t black = 0x0b0e14; uint32_t col = 0;
uint32_t grey = 0x33363c; while (i < line.length()) {
uint32_t dark_grey = 0x24272d; uint32_t cluster_len =
uint32_t name_color = 0xced4df; grapheme_next_character_break_utf8(line.c_str() + i, line.length() - i);
uint32_t lang_color = editor->lang.color; std::string cluster = line.substr(i, cluster_len);
const char *symbol = "󱓧 "; int width = display_width(cluster.c_str(), cluster_len);
const char *name = "EDITOR"; Highlight highlight = bar_line.get_highlight(col);
switch (mode) { update(row, col, cluster.c_str(), highlight.fg, highlight.bg,
case NORMAL: highlight.flags);
color = 0x82AAFF; col += width;
symbol = ""; i += cluster_len;
name = "NORMAL"; for (int w = 1; w < width; w++)
break; update(row, col - w, "\x1b", highlight.fg, highlight.bg, highlight.flags);
case INSERT:
color = 0xFF8F40;
symbol = "󱓧 ";
name = "INSERT";
break;
case SELECT:
color = 0x9ADE7A;
symbol = "󱩧 ";
name = "SELECT";
break;
case RUNNER:
color = 0xFFD700;
symbol = "";
name = "RUNNER";
break;
case JUMPER:
color = 0xF29CC3;
symbol = "";
name = "JUMPER";
break;
} }
update(row, col, " ", black, color, CF_BOLD); while (col < width)
update(row, ++col, symbol, black, color, CF_BOLD); update(row, col++, " ", 0, 0, 0);
update(row, ++col, "\x1b", black, color, CF_BOLD); col = 0;
update(row, ++col, " ", black, color, CF_BOLD); row++;
for (uint32_t i = 0; i < 6; i++) if (mode == RUNNER) {
update(row, ++col, {name[i], 0}, black, color, CF_BOLD); update(row, col++, ":", 0xFFFFFF, 0, 0);
update(row, ++col, " ", black, color, CF_BOLD); for (char c : command)
update(row, ++col, "", color, grey, CF_BOLD); update(row, col++, (char[2]){c, 0}, 0xFFFFFF, 0, 0);
update(row, ++col, "", grey, dark_grey, CF_BOLD); } else {
update(row, ++col, " ", name_color, dark_grey, CF_BOLD); for (char c : log_line)
update(row, ++col, editor->lang.symbol, lang_color, dark_grey, 0); update(row, col++, (char[2]){c, 0}, 0xFFFFFF, 0, 0);
update(row, ++col, "\x1b", lang_color, dark_grey, 0); }
update(row, ++col, " ", name_color, dark_grey, CF_BOLD); while (col < width)
std::string filename = filename_from_path(editor->filename); update(row, col++, " ", 0, 0, 0);
for (uint32_t i = 0; i < filename.length(); i++)
update(row, ++col, {filename[i], 0}, name_color, dark_grey, CF_BOLD);
update(row, ++col, " ", name_color, dark_grey, CF_BOLD);
update(row, ++col, "", dark_grey, 1, CF_BOLD);
} }
void Bar::handle(KeyEvent event) { void Bar::handle(KeyEvent event) {
@@ -68,11 +61,26 @@ void Bar::handle(KeyEvent event) {
if (event.c[0] == 0x1B) { if (event.c[0] == 0x1B) {
mode = NORMAL; mode = NORMAL;
} else if (event.c[0] == '\n' || event.c[0] == '\r') { } else if (event.c[0] == '\n' || event.c[0] == '\r') {
// execute command while stripping starting `[:;]` command = trim(command);
if (command == "w") {
save_file(editors[current_editor]);
} else if (command == "q") {
running = false;
} else if (command == "wq") {
save_file(editors[current_editor]);
running = false;
}
mode = NORMAL; mode = NORMAL;
command = ""; command = "";
} else if (isprint((unsigned char)(event.c[0]))) { } else if (isprint((unsigned char)(event.c[0]))) {
} else if (event.c[0] == 0x7F || event.c[0] == 0x08) { // backspace command += event.c[0];
} else if (event.c[0] == 0x7F || event.c[0] == 0x08) {
if (command.length() > 0) {
command = command.substr(0, command.length() - 1);
} else {
mode = NORMAL;
command = "";
}
} }
} else if (event.key_type == KEY_SPECIAL) { } else if (event.key_type == KEY_SPECIAL) {
switch (event.special_key) { switch (event.special_key) {

View File

@@ -1,5 +1,6 @@
#include "ui/completionbox.h" #include "ui/completionbox.h"
#include "editor/completions.h" #include "editor/completions.h"
#include "io/sysio.h"
#include "utils/utils.h" #include "utils/utils.h"
std::string item_kind_name(uint8_t kind) { std::string item_kind_name(uint8_t kind) {
@@ -70,7 +71,9 @@ void CompletionBox::render_update() {
uint32_t max_label_len = 0; uint32_t max_label_len = 0;
uint32_t max_detail_len = 0; uint32_t max_detail_len = 0;
uint32_t max_kind_len = 0; uint32_t max_kind_len = 0;
for (auto i : session->visible) { for (uint32_t x = session->scroll;
x < session->scroll + 8 && x < session->visible.size(); x++) {
uint32_t i = session->visible[x];
if (i >= session->items.size()) if (i >= session->items.size())
continue; continue;
auto &item = session->items[i]; auto &item = session->items[i];
@@ -80,7 +83,9 @@ void CompletionBox::render_update() {
max_kind_len = max_kind_len =
MAX(max_kind_len, (uint32_t)item_kind_name(item.kind).size()); MAX(max_kind_len, (uint32_t)item_kind_name(item.kind).size());
} }
size.row = session->visible.size() + 2; uint32_t total = session->visible.size();
uint32_t rows = MIN(total, 8);
size.row = rows + 2;
size.col = 2 + 2 + max_label_len + 1 + max_detail_len + 2 + max_kind_len + 1; size.col = 2 + 2 + max_label_len + 1 + max_detail_len + 2 + max_kind_len + 1;
cells.assign(size.row * size.col, {" ", 0, 0, 0, 0, 0}); cells.assign(size.row * size.col, {" ", 0, 0, 0, 0, 0});
auto set = [&](uint32_t r, uint32_t c, const char *text, uint32_t fg, auto set = [&](uint32_t r, uint32_t c, const char *text, uint32_t fg,
@@ -94,8 +99,10 @@ void CompletionBox::render_update() {
for (uint32_t c = 1; c < size.col - 1; c++) for (uint32_t c = 1; c < size.col - 1; c++)
set(0, c, "", border_fg, 0, 0); set(0, c, "", border_fg, 0, 0);
set(0, size.col - 1, "", border_fg, 0, 0); set(0, size.col - 1, "", border_fg, 0, 0);
for (uint32_t row_idx = 0; row_idx < session->visible.size(); row_idx++) { uint32_t start = session->scroll;
uint32_t r = row_idx + 1; uint32_t end = MIN(start + 8, session->visible.size());
for (uint32_t row_idx = start; row_idx < end; row_idx++) {
uint32_t r = (row_idx - start) + 1;
auto &item = session->items[session->visible[row_idx]]; auto &item = session->items[session->visible[row_idx]];
uint32_t bg = (session->visible[row_idx] == session->select) ? sel_bg : 1; uint32_t bg = (session->visible[row_idx] == session->select) ? sel_bg : 1;
uint32_t fg = 0xFFFFFF; uint32_t fg = 0xFFFFFF;
@@ -129,6 +136,12 @@ void CompletionBox::render_update() {
for (uint32_t c = 1; c < size.col - 1; c++) for (uint32_t c = 1; c < size.col - 1; c++)
set(bottom, c, "", border_fg, 0, 0); set(bottom, c, "", border_fg, 0, 0);
set(bottom, size.col - 1, "", border_fg, 0, 0); set(bottom, size.col - 1, "", border_fg, 0, 0);
if (session->visible.size() > 8) {
std::string info = std::to_string(start + 1) + "-" + std::to_string(end) +
"/" + std::to_string(session->visible.size());
for (size_t i = 0; i < info.size() && i < size.col - 2; i++)
set(bottom, 1 + i, (char[2]){info[i], 0}, border_fg, 0, 0);
}
} }
void CompletionBox::render(Coord pos) { void CompletionBox::render(Coord pos) {
@@ -139,11 +152,12 @@ void CompletionBox::render(Coord pos) {
if (start_row < 0) if (start_row < 0)
start_row = pos.row + 1; start_row = pos.row + 1;
int32_t start_col = pos.col; int32_t start_col = pos.col;
// if (start_col + size.col > cols) { Coord screen_size = get_size();
// start_col = cols - size.col; if (start_col + size.col > screen_size.col) {
// if (start_col < 0) start_col = screen_size.col - size.col;
// start_col = 0; if (start_col < 0)
// } start_col = 0;
}
position = {(uint32_t)start_row, (uint32_t)start_col}; position = {(uint32_t)start_row, (uint32_t)start_col};
for (uint32_t r = 0; r < size.row; r++) for (uint32_t r = 0; r < size.row; r++)
for (uint32_t c = 0; c < size.col; c++) for (uint32_t c = 0; c < size.col; c++)

View File

@@ -148,11 +148,12 @@ void DiagnosticBox::render(Coord pos) {
if (start_row < 0) if (start_row < 0)
start_row = pos.row + 1; start_row = pos.row + 1;
int32_t start_col = pos.col; int32_t start_col = pos.col;
// if (start_col + size.col > cols) { Coord screen_size = get_size();
// start_col = cols - size.col; if (start_col + size.col > screen_size.col) {
// if (start_col < 0) start_col = screen_size.col - size.col;
// start_col = 0; if (start_col < 0)
// } start_col = 0;
}
for (uint32_t r = 0; r < size.row; r++) for (uint32_t r = 0; r < size.row; r++)
for (uint32_t c = 0; c < size.col; c++) for (uint32_t c = 0; c < size.col; c++)
update(start_row + r, start_col + c, cells[r * size.col + c].utf8, update(start_row + r, start_col + c, cells[r * size.col + c].utf8,

View File

@@ -24,6 +24,7 @@ void HoverBox::scroll(int32_t number) {
void HoverBox::render_first(bool scroll) { void HoverBox::render_first(bool scroll) {
if (!scroll) { if (!scroll) {
// TODO: call syntax highlighter here
} }
uint32_t longest_line = 0; uint32_t longest_line = 0;
uint32_t current_width = 0; uint32_t current_width = 0;
@@ -104,11 +105,12 @@ void HoverBox::render(Coord pos) {
if (start_row < 0) if (start_row < 0)
start_row = pos.row + 1; start_row = pos.row + 1;
int32_t start_col = pos.col; int32_t start_col = pos.col;
// if (start_col + size.col > cols) { Coord screen_size = get_size();
// start_col = cols - size.col; if (start_col + size.col > screen_size.col) {
// if (start_col < 0) start_col = screen_size.col - size.col;
// start_col = 0; if (start_col < 0)
// } start_col = 0;
}
for (uint32_t r = 0; r < size.row; r++) for (uint32_t r = 0; r < size.row; r++)
for (uint32_t c = 0; c < size.col; c++) for (uint32_t c = 0; c < size.col; c++)
update(start_row + r, start_col + c, cells[r * size.col + c].utf8, update(start_row + r, start_col + c, cells[r * size.col + c].utf8,

View File

@@ -1,6 +1,9 @@
#include "config.h"
#include "utils/utils.h" #include "utils/utils.h"
std::unordered_map<std::string, Language> languages;
std::unordered_map<std::string, std::string> language_extensions;
std::unordered_map<std::string, LSP> lsps;
void log(const char *fmt, ...) { void log(const char *fmt, ...) {
FILE *fp = fopen("/tmp/log.txt", "a"); FILE *fp = fopen("/tmp/log.txt", "a");
if (!fp) if (!fp)
@@ -40,34 +43,50 @@ std::string get_exe_dir() {
return path.substr(0, path.find_last_of('/')); return path.substr(0, path.find_last_of('/'));
} }
char *load_file(const char *path, uint32_t *out_len) { char *load_file(const char *path, uint32_t *out_len, bool *out_eol) {
std::ifstream file(path, std::ios::in | std::ios::binary | std::ios::ate); std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file.is_open()) if (!file.is_open())
return nullptr; return nullptr;
std::streamsize len = file.tellg(); std::streamsize len = file.tellg();
if (len < 0 || static_cast<uint32_t>(len) > 0xFFFFFFFF) if (len < 0 || static_cast<uint64_t>(len) > 0xFFFFFFFF)
return nullptr; return nullptr;
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
bool add_newline = false; unsigned char bom[3] = {0};
if (len > 0) { file.read(reinterpret_cast<char *>(bom), 3);
file.seekg(-1, std::ios::end); if ((bom[0] == 0xFF && bom[1] == 0xFE) || (bom[0] == 0xFE && bom[1] == 0xFF))
char last_char; return nullptr;
file.read(&last_char, 1); bool has_utf8_bom = (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF);
if (last_char != '\n') uint32_t skip = has_utf8_bom ? 3 : 0;
add_newline = true; uint32_t data_len = static_cast<uint32_t>(len) - skip;
} file.seekg(skip, std::ios::beg);
file.seekg(0, std::ios::beg); char *buf = (char *)malloc(data_len + 1);
uint32_t alloc_size = static_cast<uint32_t>(len) + (add_newline ? 1 : 0);
char *buf = (char *)malloc(alloc_size);
if (!buf) if (!buf)
return nullptr; return nullptr;
if (!file.read(buf, len)) { file.read(buf, data_len);
free(buf); bool has_cr = memchr(buf, '\r', data_len) != nullptr;
return nullptr; bool has_lf = memchr(buf, '\n', data_len) != nullptr;
if (!has_cr && !has_lf) {
uint32_t write = data_len;
buf[write++] = '\n';
*out_len = write;
return buf;
} }
if (add_newline) if (!has_cr) {
buf[len++] = '\n'; *out_eol = true;
*out_len = static_cast<uint32_t>(len); uint32_t write = data_len;
if (buf[write - 1] != '\n')
buf[write++] = '\n';
*out_len = write;
return buf;
}
*out_eol = false;
uint32_t write = 0;
for (uint32_t i = 0; i < data_len; ++i)
if (buf[i] != '\r')
buf[write++] = buf[i];
if (buf[write - 1] != '\n')
buf[write++] = '\n';
*out_len = write;
return buf; return buf;
} }
@@ -86,39 +105,13 @@ static std::string file_extension(const char *filename) {
return ext; return ext;
} }
char *detect_file_type(const char *filename) {
magic_t magic = magic_open(MAGIC_MIME_TYPE);
if (!magic)
return nullptr;
if (magic_load(magic, nullptr) != 0) {
magic_close(magic);
return nullptr;
}
const char *type = magic_file(magic, filename);
if (!type) {
magic_close(magic);
return nullptr;
}
char *result = strdup(type);
magic_close(magic);
return result;
}
Language language_for_file(const char *filename) { Language language_for_file(const char *filename) {
std::string ext = file_extension(filename); std::string ext = file_extension(filename);
std::string lang_name; std::string lang_name;
if (!ext.empty()) { if (!ext.empty()) {
auto it = kExtToLang.find(ext); auto it = language_extensions.find(ext);
if (it != kExtToLang.end()) if (it != language_extensions.end())
return kLanguages.find(it->second)->second; return languages.find(it->second)->second;
}
char *mime = detect_file_type(filename);
if (mime) {
std::string mime_type(mime);
free(mime);
auto it = kMimeToLang.find(mime_type);
if (it != kMimeToLang.end())
return kLanguages.find(it->second)->second;
} }
return Language{}; return Language{};
} }

View File

@@ -98,9 +98,11 @@ uint32_t count_clusters(const char *line, size_t len, size_t from, size_t to) {
return count; return count;
} }
uint32_t utf8_byte_offset_to_utf16(const char *s, uint32_t byte_pos) { size_t utf8_offset_to_utf16(const char *s, size_t utf8_len, size_t byte_pos) {
uint32_t utf16_units = 0; if (byte_pos > utf8_len)
uint32_t i = 0; return 0;
size_t utf16_units = 0;
size_t i = 0;
while (i < byte_pos) { while (i < byte_pos) {
unsigned char c = s[i]; unsigned char c = s[i];
if ((c & 0x80) == 0x00) { if ((c & 0x80) == 0x00) {
@@ -120,10 +122,10 @@ uint32_t utf8_byte_offset_to_utf16(const char *s, uint32_t byte_pos) {
return utf16_units; return utf16_units;
} }
uint32_t utf16_offset_to_utf8(const char *s, uint32_t utf16_pos) { size_t utf16_offset_to_utf8(const char *s, size_t utf8_len, size_t utf16_pos) {
uint32_t utf16_units = 0; size_t utf16_units = 0;
uint32_t i = 0; size_t i = 0;
while (utf16_units < utf16_pos) { while (utf16_units < utf16_pos && i < utf8_len) {
unsigned char c = s[i]; unsigned char c = s[i];
if ((c & 0x80) == 0x00) { if ((c & 0x80) == 0x00) {
i += 1; i += 1;

View File

@@ -1,88 +0,0 @@
{
"Default": {
"fg": "#EEEEEE"
},
"Shebang": {
"fg": "#7dcfff"
},
"Error": {
"fg": "#EF5168"
},
"Comment": {
"fg": "#AAAAAA",
"italic": true
},
"String": {
"fg": "#AAD94C"
},
"Escape": {
"fg": "#7dcfff"
},
"Interpolation": {
"fg": "#7dcfff"
},
"Regexp": {
"fg": "#D2A6FF"
},
"Number": {
"fg": "#E6C08A"
},
"True": {
"fg": "#7AE93C"
},
"False": {
"fg": "#EF5168"
},
"Char": {
"fg": "#FFAF70"
},
"Keyword": {
"fg": "#FF8F40"
},
"KeywordOperator": {
"fg": "#F07178"
},
"Operator": {
"fg": "#FFFFFF",
"italic": true
},
"Function": {
"fg": "#FFAF70"
},
"Type": {
"fg": "#F07178"
},
"Constant": {
"fg": "#7dcfff"
},
"VariableInstance": {
"fg": "#95E6CB"
},
"VariableGlobal": {
"fg": "#F07178"
},
"Annotation": {
"fg": "#7dcfff"
},
"Directive": {
"fg": "#FF8F40"
},
"Label": {
"fg": "#D2A6FF"
},
"Brace1": {
"fg": "#D2A6FF"
},
"Brace2": {
"fg": "#FFAFAF"
},
"Brace3": {
"fg": "#FFFF00"
},
"Brace4": {
"fg": "#0FFF0F"
},
"Brace5": {
"fg": "#FF0F0F"
}
}