diff options
| author | Federico Igne <undyamon@disroot.org> | 2024-01-22 23:46:37 +0100 |
|---|---|---|
| committer | Federico Igne <undyamon@disroot.org> | 2024-01-22 23:46:37 +0100 |
| commit | 7d009e0ca4a1af10cc6d31fb5982e38dcab9ee71 (patch) | |
| tree | 0eeecddcdcc34abc199aba3af3e25be151c9e3e2 /lib/editor.ml | |
| parent | 0b2c183dbf275fbca3f9e0522cc583f85edccab5 (diff) | |
| download | sandy-7d009e0ca4a1af10cc6d31fb5982e38dcab9ee71.tar.gz sandy-7d009e0ca4a1af10cc6d31fb5982e38dcab9ee71.zip | |
feat: add support for rendering text (i.e. tabs)
This allows to have differences between the "raw" content of the buffer
and its visualization on screen. At the time of writing this handles the
rendering of tabs (i.e. '\t') as a fixed amount of spaces, but will be
useful for syntax highlighting as well.
Diffstat (limited to 'lib/editor.ml')
| -rw-r--r-- | lib/editor.ml | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/editor.ml b/lib/editor.ml index f91e66d..69dc666 100644 --- a/lib/editor.ml +++ b/lib/editor.ml | |||
| @@ -11,6 +11,7 @@ type editor = { | |||
| 11 | offset : int * int; | 11 | offset : int * int; |
| 12 | cursor : cursor; | 12 | cursor : cursor; |
| 13 | buffer : Buffer.t option; | 13 | buffer : Buffer.t option; |
| 14 | rendered : bool; | ||
| 14 | pending : Key.t Sequence.t; | 15 | pending : Key.t Sequence.t; |
| 15 | i_pending : Command.t Sequence.t; | 16 | i_pending : Command.t Sequence.t; |
| 16 | n_pending : Command.t Sequence.t; | 17 | n_pending : Command.t Sequence.t; |
| @@ -25,6 +26,7 @@ let init (c : Config.t) : editor = | |||
| 25 | offset = (0, 0); | 26 | offset = (0, 0); |
| 26 | cursor = (1, 1); | 27 | cursor = (1, 1); |
| 27 | buffer = List.hd c.files |> Option.map ~f:Buffer.from_file; | 28 | buffer = List.hd c.files |> Option.map ~f:Buffer.from_file; |
| 29 | rendered = true; | ||
| 28 | pending = Key.stream; | 30 | pending = Key.stream; |
| 29 | i_pending = Command.i_stream; | 31 | i_pending = Command.i_stream; |
| 30 | n_pending = Command.n_stream; | 32 | n_pending = Command.n_stream; |
| @@ -104,10 +106,13 @@ module Action = struct | |||
| 104 | let aux e = | 106 | let aux e = |
| 105 | let x, y = e.offset | 107 | let x, y = e.offset |
| 106 | and ((r, c) as size) = e.term.size | 108 | and ((r, c) as size) = e.term.size |
| 107 | and fill = Sequence.singleton '~' in | 109 | and fill = Sequence.singleton '~' |
| 110 | and limit = | ||
| 111 | Buffer.(if e.rendered then rendered_view else unrendered_view) | ||
| 112 | in | ||
| 108 | let view = | 113 | let view = |
| 109 | Option.( | 114 | Option.( |
| 110 | e.buffer >>| Buffer.view x y r c | 115 | e.buffer >>| limit x y r c |
| 111 | |> value ~default:(welcome size) | 116 | |> value ~default:(welcome size) |
| 112 | |> Text.extend ~fill r) | 117 | |> Text.extend ~fill r) |
| 113 | in | 118 | in |
| @@ -117,6 +122,11 @@ module Action = struct | |||
| 117 | 122 | ||
| 118 | (* TODO: save logic *) | 123 | (* TODO: save logic *) |
| 119 | let quit n = Stdlib.exit n | 124 | let quit n = Stdlib.exit n |
| 125 | |||
| 126 | (* Debug *) | ||
| 127 | let get_rendered e = (e.rendered, e) | ||
| 128 | let set_rendered r e = ((), { e with rendered = r }) | ||
| 129 | let toggle_rendered = get_rendered >>| not >>= set_rendered | ||
| 120 | let noop = return () | 130 | let noop = return () |
| 121 | end | 131 | end |
| 122 | 132 | ||
| @@ -352,6 +362,8 @@ let handle_normal_command = | |||
| 352 | (* | Key 's' -> *) | 362 | (* | Key 's' -> *) |
| 353 | (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) | 363 | (* (Buffer.Action.delete_after |> on_focused_buffer_or_new) *) |
| 354 | (* *> set_mode Insert *) | 364 | (* *> set_mode Insert *) |
| 365 | (* Debug *) | ||
| 366 | | Simple (Ctrl 'R') -> toggle_rendered | ||
| 355 | | _ -> noop | 367 | | _ -> noop |
| 356 | 368 | ||
| 357 | let handle_next_command m e = | 369 | let handle_next_command m e = |
