mui 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +18 -10
  3. data/CHANGELOG.md +162 -0
  4. data/README.md +309 -6
  5. data/docs/_config.yml +56 -0
  6. data/docs/configuration.md +314 -0
  7. data/docs/getting-started.md +140 -0
  8. data/docs/index.md +55 -0
  9. data/docs/jobs.md +297 -0
  10. data/docs/keybindings.md +229 -0
  11. data/docs/plugins.md +285 -0
  12. data/docs/syntax-highlighting.md +155 -0
  13. data/lib/mui/color_manager.rb +140 -6
  14. data/lib/mui/color_scheme.rb +1 -0
  15. data/lib/mui/command_completer.rb +11 -2
  16. data/lib/mui/command_history.rb +89 -0
  17. data/lib/mui/command_line.rb +32 -2
  18. data/lib/mui/command_registry.rb +21 -2
  19. data/lib/mui/config.rb +3 -1
  20. data/lib/mui/editor.rb +90 -2
  21. data/lib/mui/floating_window.rb +53 -1
  22. data/lib/mui/handler_result.rb +13 -7
  23. data/lib/mui/highlighters/search_highlighter.rb +2 -1
  24. data/lib/mui/highlighters/syntax_highlighter.rb +4 -1
  25. data/lib/mui/insert_completion_state.rb +15 -2
  26. data/lib/mui/key_handler/base.rb +87 -0
  27. data/lib/mui/key_handler/command_mode.rb +68 -0
  28. data/lib/mui/key_handler/insert_mode.rb +10 -41
  29. data/lib/mui/key_handler/normal_mode.rb +24 -51
  30. data/lib/mui/key_handler/operators/paste_operator.rb +9 -3
  31. data/lib/mui/key_handler/search_mode.rb +10 -7
  32. data/lib/mui/key_handler/visual_mode.rb +15 -10
  33. data/lib/mui/key_notation_parser.rb +159 -0
  34. data/lib/mui/key_sequence.rb +67 -0
  35. data/lib/mui/key_sequence_buffer.rb +85 -0
  36. data/lib/mui/key_sequence_handler.rb +163 -0
  37. data/lib/mui/key_sequence_matcher.rb +79 -0
  38. data/lib/mui/line_renderer.rb +52 -1
  39. data/lib/mui/mode_manager.rb +3 -2
  40. data/lib/mui/screen.rb +30 -6
  41. data/lib/mui/search_state.rb +74 -27
  42. data/lib/mui/syntax/language_detector.rb +33 -1
  43. data/lib/mui/syntax/lexers/c_lexer.rb +2 -0
  44. data/lib/mui/syntax/lexers/css_lexer.rb +121 -0
  45. data/lib/mui/syntax/lexers/go_lexer.rb +207 -0
  46. data/lib/mui/syntax/lexers/html_lexer.rb +118 -0
  47. data/lib/mui/syntax/lexers/javascript_lexer.rb +219 -0
  48. data/lib/mui/syntax/lexers/markdown_lexer.rb +210 -0
  49. data/lib/mui/syntax/lexers/ruby_lexer.rb +3 -0
  50. data/lib/mui/syntax/lexers/rust_lexer.rb +150 -0
  51. data/lib/mui/syntax/lexers/typescript_lexer.rb +225 -0
  52. data/lib/mui/terminal_adapter/base.rb +21 -0
  53. data/lib/mui/terminal_adapter/curses.rb +37 -11
  54. data/lib/mui/themes/default.rb +263 -132
  55. data/lib/mui/version.rb +1 -1
  56. data/lib/mui/window.rb +105 -39
  57. data/lib/mui/window_manager.rb +7 -0
  58. data/lib/mui/wrap_cache.rb +40 -0
  59. data/lib/mui/wrap_helper.rb +84 -0
  60. data/lib/mui.rb +15 -0
  61. metadata +26 -3
@@ -0,0 +1,314 @@
1
+ ---
2
+ title: Configuration
3
+ layout: default
4
+ nav_order: 4
5
+ ---
6
+
7
+ # Configuration
8
+ {: .no_toc }
9
+
10
+ ## Table of contents
11
+ {: .no_toc .text-delta }
12
+
13
+ 1. TOC
14
+ {:toc}
15
+
16
+ ---
17
+
18
+ ## Configuration Files
19
+
20
+ Mui supports two configuration files:
21
+
22
+ | File | Scope |
23
+ |------|-------|
24
+ | `~/.muirc` | Global settings (all projects) |
25
+ | `.lmuirc` | Local settings (current directory) |
26
+
27
+ Local settings (`.lmuirc`) override global settings (`~/.muirc`).
28
+
29
+ Configuration files are written in Ruby using Mui's DSL.
30
+
31
+ ## Basic Settings
32
+
33
+ ### Color Scheme
34
+
35
+ ```ruby
36
+ Mui.set :colorscheme, "tokyo_night"
37
+ ```
38
+
39
+ Available themes (all themes support 256-color palette with 8-color fallback):
40
+
41
+ | Theme | Description |
42
+ |-------|-------------|
43
+ | `mui` | Default theme with eye-friendly gray-based colors |
44
+ | `solarized_dark` | Solarized dark theme |
45
+ | `solarized_light` | Solarized light theme |
46
+ | `monokai` | Monokai theme |
47
+ | `nord` | Nord theme |
48
+ | `gruvbox_dark` | Gruvbox dark theme |
49
+ | `dracula` | Dracula theme |
50
+ | `tokyo_night` | Tokyo Night theme |
51
+
52
+ ### 256-Color Support
53
+
54
+ All bundled themes utilize 256-color palettes for rich syntax highlighting and UI elements. Mui automatically detects your terminal's color capabilities:
55
+
56
+ - **256-color terminals**: Full color palette with all theme colors
57
+ - **8-color terminals**: Automatic fallback to basic 8-color equivalents
58
+
59
+ Most modern terminals (iTerm2, gnome-terminal, Windows Terminal, etc.) support 256 colors. If colors appear incorrect, ensure your terminal's `TERM` environment variable is set correctly (e.g., `xterm-256color`).
60
+
61
+ ### Indentation
62
+
63
+ ```ruby
64
+ # Number of spaces for Tab display
65
+ Mui.set :tabstop, 4
66
+
67
+ # Number of spaces for indent operations (>, <)
68
+ Mui.set :shiftwidth, 4
69
+
70
+ # Use spaces instead of tabs
71
+ Mui.set :expandtab, true
72
+ ```
73
+
74
+ ### Syntax Highlighting
75
+
76
+ ```ruby
77
+ # Enable/disable syntax highlighting
78
+ Mui.set :syntax, true
79
+ ```
80
+
81
+ ### Leader Key
82
+
83
+ ```ruby
84
+ # Set leader key (default: backslash)
85
+ Mui.set :leader, " " # Space as leader
86
+ ```
87
+
88
+ ### Key Timeout
89
+
90
+ ```ruby
91
+ # Timeout for multi-key sequences (milliseconds)
92
+ Mui.set :timeoutlen, 1000
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Custom Key Mappings
98
+
99
+ Define custom key bindings with `Mui.keymap`:
100
+
101
+ ```ruby
102
+ Mui.keymap :mode, "key" do |ctx|
103
+ # action
104
+ end
105
+ ```
106
+
107
+ ### Modes
108
+
109
+ - `:normal` - Normal mode
110
+ - `:insert` - Insert mode
111
+ - `:visual` - Visual mode
112
+ - `:command` - Command mode
113
+
114
+ ### Examples
115
+
116
+ ```ruby
117
+ # Save with <Leader>w
118
+ Mui.keymap :normal, "<Leader>w" do |ctx|
119
+ ctx.editor.execute_command("w")
120
+ end
121
+
122
+ # Quick escape in Insert mode
123
+ Mui.keymap :insert, "jk" do |ctx|
124
+ ctx.change_mode(:normal)
125
+ end
126
+
127
+ # Close buffer with <Leader>q
128
+ Mui.keymap :normal, "<Leader>q" do |ctx|
129
+ ctx.editor.execute_command("q")
130
+ end
131
+ ```
132
+
133
+ ### Special Key Notation
134
+
135
+ | Notation | Key |
136
+ |----------|-----|
137
+ | `<Leader>` | Leader key |
138
+ | `<Space>` | Space bar |
139
+ | `<Tab>` | Tab key |
140
+ | `<S-Tab>`, `<btab>` | Shift+Tab |
141
+ | `<CR>`, `<Enter>` | Enter key |
142
+ | `<Esc>` | Escape key |
143
+ | `<BS>` | Backspace |
144
+ | `<C-x>` | Ctrl+x |
145
+ | `<C-S-x>` | Ctrl+Shift+x |
146
+ | `<S-x>` | Shift+x |
147
+
148
+ ### Multi-key Sequences
149
+
150
+ ```ruby
151
+ # <Leader>ff for find files
152
+ Mui.keymap :normal, "<Leader>ff" do |ctx|
153
+ ctx.editor.execute_command("Files")
154
+ end
155
+
156
+ # <Leader>fg for grep
157
+ Mui.keymap :normal, "<Leader>fg" do |ctx|
158
+ ctx.editor.execute_command("Rg")
159
+ end
160
+
161
+ # Ctrl-x Ctrl-s to save (Emacs style)
162
+ Mui.keymap :normal, "<C-x><C-s>" do |ctx|
163
+ ctx.editor.execute_command("w")
164
+ end
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Custom Commands
170
+
171
+ Define custom Ex commands with `Mui.command`:
172
+
173
+ ```ruby
174
+ Mui.command :name do |ctx|
175
+ # action
176
+ end
177
+ ```
178
+
179
+ ### Examples
180
+
181
+ ```ruby
182
+ # Simple greeting
183
+ Mui.command :hello do |ctx|
184
+ ctx.set_message("Hello, World!")
185
+ end
186
+
187
+ # Command with arguments
188
+ Mui.command :echo do |ctx, *args|
189
+ ctx.set_message(args.join(" "))
190
+ end
191
+
192
+ # Open configuration file
193
+ Mui.command :config do |ctx|
194
+ ctx.editor.execute_command("e ~/.muirc")
195
+ end
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Autocmd Events
201
+
202
+ Execute code when events occur with `Mui.autocmd`:
203
+
204
+ ```ruby
205
+ Mui.autocmd :event, pattern: "*.ext" do |ctx|
206
+ # action
207
+ end
208
+ ```
209
+
210
+ ### Available Events
211
+
212
+ | Event | Trigger |
213
+ |-------|---------|
214
+ | `BufEnter` | When entering a buffer |
215
+ | `BufLeave` | When leaving a buffer |
216
+ | `BufWrite` | When writing a buffer |
217
+ | `BufWritePre` | Before writing a buffer |
218
+ | `BufWritePost` | After writing a buffer |
219
+ | `ModeChanged` | When mode changes |
220
+ | `CursorMoved` | When cursor moves |
221
+ | `TextChanged` | When text is modified |
222
+ | `InsertEnter` | When entering Insert mode |
223
+ | `InsertLeave` | When leaving Insert mode |
224
+ | `InsertCompletion` | When completion is triggered |
225
+ | `JobStarted` | When a job starts |
226
+ | `JobCompleted` | When a job completes |
227
+ | `JobFailed` | When a job fails |
228
+ | `JobCancelled` | When a job is cancelled |
229
+
230
+ ### Examples
231
+
232
+ ```ruby
233
+ # Auto-save on leaving Insert mode
234
+ Mui.autocmd :InsertLeave do |ctx|
235
+ ctx.editor.execute_command("w") if ctx.buffer.modified?
236
+ end
237
+
238
+ # Show message when opening Ruby files
239
+ Mui.autocmd :BufEnter, pattern: "*.rb" do |ctx|
240
+ ctx.set_message("Ruby file loaded")
241
+ end
242
+
243
+ # Format before saving
244
+ Mui.autocmd :BufWritePre, pattern: "*.rb" do |ctx|
245
+ # Run formatter
246
+ end
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Using Plugins
252
+
253
+ Load plugins with `Mui.use`:
254
+
255
+ ```ruby
256
+ Mui.use "mui-lsp"
257
+ Mui.use "mui-git"
258
+ Mui.use "mui-fzf"
259
+ ```
260
+
261
+ See [Plugins]({{ site.baseurl }}/plugins) for more details.
262
+
263
+ ---
264
+
265
+ ## Complete Example
266
+
267
+ ```ruby
268
+ # ~/.muirc
269
+
270
+ # Appearance
271
+ Mui.set :colorscheme, "tokyo_night"
272
+ Mui.set :syntax, true
273
+
274
+ # Indentation
275
+ Mui.set :tabstop, 2
276
+ Mui.set :shiftwidth, 2
277
+ Mui.set :expandtab, true
278
+
279
+ # Leader key
280
+ Mui.set :leader, " "
281
+
282
+ # Plugins
283
+ Mui.use "mui-lsp"
284
+ Mui.use "mui-fzf"
285
+
286
+ # Key mappings
287
+ Mui.keymap :normal, "<Leader>w" do |ctx|
288
+ ctx.editor.execute_command("w")
289
+ end
290
+
291
+ Mui.keymap :normal, "<Leader>q" do |ctx|
292
+ ctx.editor.execute_command("q")
293
+ end
294
+
295
+ Mui.keymap :normal, "<Leader>ff" do |ctx|
296
+ ctx.editor.execute_command("Files")
297
+ end
298
+
299
+ # Custom commands
300
+ Mui.command :reload do |ctx|
301
+ ctx.editor.execute_command("e")
302
+ ctx.set_message("File reloaded")
303
+ end
304
+
305
+ # LSP configuration
306
+ Mui.lsp do
307
+ use :ruby
308
+
309
+ # TypeScript (requires typescript-language-server)
310
+ server :typescript,
311
+ command: ["typescript-language-server", "--stdio"],
312
+ filetypes: ["typescript", "typescriptreact", "javascript", "javascriptreact"]
313
+ end
314
+ ```
@@ -0,0 +1,140 @@
1
+ ---
2
+ title: Getting Started
3
+ layout: default
4
+ nav_order: 2
5
+ ---
6
+
7
+ # Getting Started
8
+ {: .no_toc }
9
+
10
+ ## Table of contents
11
+ {: .no_toc .text-delta }
12
+
13
+ 1. TOC
14
+ {:toc}
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ Install Mui from RubyGems:
21
+
22
+ ```bash
23
+ gem install mui
24
+ ```
25
+
26
+ ### Requirements
27
+
28
+ - Ruby 3.0 or later
29
+ - A terminal that supports 256 colors
30
+
31
+ ## Basic Usage
32
+
33
+ ### Opening a File
34
+
35
+ ```bash
36
+ mui filename.rb
37
+ ```
38
+
39
+ ### Creating a New File
40
+
41
+ ```bash
42
+ mui
43
+ ```
44
+
45
+ Or open a non-existent file path:
46
+
47
+ ```bash
48
+ mui new_file.rb
49
+ ```
50
+
51
+ ## Modes
52
+
53
+ Mui is a modal editor, similar to Vim. Understanding modes is essential.
54
+
55
+ ### Normal Mode
56
+
57
+ The default mode. Used for navigation and commands.
58
+
59
+ - Press `Esc` from any mode to return to Normal mode
60
+
61
+ ### Insert Mode
62
+
63
+ For typing text. Enter from Normal mode with:
64
+
65
+ | Key | Action |
66
+ |-----|--------|
67
+ | `i` | Insert before cursor |
68
+ | `a` | Append after cursor |
69
+ | `o` | Open new line below |
70
+ | `O` | Open new line above |
71
+
72
+ ### Visual Mode
73
+
74
+ For selecting text:
75
+
76
+ | Key | Action |
77
+ |-----|--------|
78
+ | `v` | Character-wise selection |
79
+ | `V` | Line-wise selection |
80
+
81
+ ### Command Mode
82
+
83
+ For Ex commands. Press `:` from Normal mode.
84
+
85
+ ## Essential Commands
86
+
87
+ ### Saving and Quitting
88
+
89
+ | Command | Action |
90
+ |---------|--------|
91
+ | `:w` | Save file |
92
+ | `:q` | Quit (fails if unsaved changes) |
93
+ | `:q!` | Force quit without saving |
94
+ | `:wq` | Save and quit |
95
+
96
+ ### Opening Files
97
+
98
+ | Command | Action |
99
+ |---------|--------|
100
+ | `:e filename` | Open file |
101
+ | `:sp filename` | Open in horizontal split |
102
+ | `:vs filename` | Open in vertical split |
103
+ | `:tabnew filename` | Open in new tab |
104
+
105
+ ### Navigation
106
+
107
+ | Key | Action |
108
+ |-----|--------|
109
+ | `h`, `j`, `k`, `l` | Left, down, up, right |
110
+ | `w`, `b` | Word forward, backward |
111
+ | `0`, `$` | Line start, end |
112
+ | `gg`, `G` | File start, end |
113
+ | `/pattern` | Search forward |
114
+ | `?pattern` | Search backward |
115
+ | `n`, `N` | Next, previous match |
116
+
117
+ ## Configuration
118
+
119
+ Create `~/.muirc` for global settings:
120
+
121
+ ```ruby
122
+ # Set color scheme
123
+ Mui.set :colorscheme, "tokyo_night"
124
+
125
+ # Enable syntax highlighting
126
+ Mui.set :syntax, true
127
+
128
+ # Set indentation
129
+ Mui.set :tabstop, 2
130
+ Mui.set :shiftwidth, 2
131
+ Mui.set :expandtab, true
132
+ ```
133
+
134
+ See [Configuration]({{ site.baseurl }}/configuration) for all options.
135
+
136
+ ## Next Steps
137
+
138
+ - [Key Bindings]({{ site.baseurl }}/keybindings) - Complete key reference
139
+ - [Configuration]({{ site.baseurl }}/configuration) - Customize Mui
140
+ - [Plugins]({{ site.baseurl }}/plugins) - Extend functionality
data/docs/index.md ADDED
@@ -0,0 +1,55 @@
1
+ ---
2
+ title: Home
3
+ layout: home
4
+ nav_order: 1
5
+ ---
6
+
7
+ # Mui (無為)
8
+
9
+ A Vim-like TUI text editor written in Ruby.
10
+ {: .fs-6 .fw-300 }
11
+
12
+ > **無為 (むい, mui)** - "Effortless action" from Taoist philosophy.
13
+ > *"Form without forcing, existing as it is. Yet from nothing, something is born."*
14
+
15
+ [Get Started]({{ site.baseurl }}/getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2 }
16
+ [View on GitHub](https://github.com/S-H-GAMELINKS/mui){: .btn .fs-5 .mb-4 .mb-md-0 .mr-2 }
17
+ [RubyGems](https://rubygems.org/gems/mui){: .btn .btn-green .fs-5 .mb-4 .mb-md-0 }
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ gem install mui
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - **Modal Editing** - Vim-like Normal, Insert, Visual, Command modes
30
+ - **Syntax Highlighting** - Ruby, C, Go, Rust, JavaScript, TypeScript, Markdown, HTML, CSS
31
+ - **Tab Pages & Window Splits** - Multiple files with flexible layouts
32
+ - **Plugin System** - Extend functionality with Ruby gems
33
+ - **LSP Support** - Language Server Protocol via mui-lsp plugin
34
+ - **Japanese/UTF-8 Support** - Full multibyte character support
35
+
36
+ ## Quick Start
37
+
38
+ ```bash
39
+ # Install from RubyGems
40
+ gem install mui
41
+
42
+ # Open a file
43
+ mui myfile.rb
44
+
45
+ # Or start with an empty buffer
46
+ mui
47
+ ```
48
+
49
+ ## Official Plugins
50
+
51
+ | Plugin | Description |
52
+ |--------|-------------|
53
+ | [mui-lsp](https://github.com/S-H-GAMELINKS/mui-lsp) | LSP (Language Server Protocol) support |
54
+ | [mui-git](https://github.com/S-H-GAMELINKS/mui-git) | Git integration |
55
+ | [mui-fzf](https://github.com/S-H-GAMELINKS/mui-fzf) | Fuzzy finder integration with fzf |