{"id":13496653,"url":"https://github.com/rhysd/kiro-editor","last_synced_at":"2025-05-15T21:06:50.478Z","repository":{"id":54254281,"uuid":"204309656","full_name":"rhysd/kiro-editor","owner":"rhysd","description":"A small terminal UTF-8 text editor written in Rust 📝🦀","archived":false,"fork":false,"pushed_at":"2021-08-27T16:51:57.000Z","size":1200,"stargazers_count":743,"open_issues_count":6,"forks_count":32,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-15T21:06:12.271Z","etag":null,"topics":["rust","terminal","text-editor","utf-8"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-25T14:59:44.000Z","updated_at":"2025-05-10T20:42:56.000Z","dependencies_parsed_at":"2022-08-13T10:10:24.067Z","dependency_job_id":null,"html_url":"https://github.com/rhysd/kiro-editor","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fkiro-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fkiro-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fkiro-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fkiro-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/kiro-editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422764,"owners_count":22068678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","terminal","text-editor","utf-8"],"created_at":"2024-07-31T19:01:55.005Z","updated_at":"2025-05-15T21:06:50.457Z","avatar_url":"https://github.com/rhysd.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"Kiro\n====\n[![crates.io][crates-io-badge]][crates-io]\n[![Build Status][build-badge]][ci]\n\n[Kiro][] is a tiny UTF-8 text editor on terminal written in Rust. Kiro was started as a Rust port of\nawesome minimal text editor [kilo][] and has grown with various extensions \u0026 improvements.\n\n\u003cimg width=539 height=396 src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/main.gif?raw=true\" alt=\"main screenshot\"/\u003e\n\nIt provides basic features as a minimal text editor:\n\n- Open/Save text files\n- Create new text files and empty text buffer on memory\n- Edit a text (put/delete characters, insert/delete lines, ...)\n- Simple syntax highlighting\n- Simple incremental text search\n\nAnd Kiro extends [kilo][] to improve editing (please see 'Extended Features' section and 'Implementation'\nsection below for more details):\n\n- Support editing UTF-8 characters like '🐶' (kilo only supports ASCII characters)\n- Undo/Redo\n- More useful shortcuts (Alt modifier is supported)\n- 24bit colors (true colors) and 256 colors support using [gruvbox][] retro color palette with 16\n  colors fallback\n- More efficient screen rendering and highlighting (kilo renders entire screen each time)\n- Open multiple files (switch buffers by Ctrl-X/Alt-X)\n- Resizing terminal window supported. Screen size is responsible\n- Highlight more languages (Rust, Go, JavaScript, C++) and items (statements, types, number literals, ...)\n- Automatically closes the message bar at bottom of line\n- Modular implementation for each logics such as parsing key inputs, rendering screen, calculating\n  highlight, modifying text buffer (kilo implements everything in one `kilo.c` with several global\n  variables)\n- Incremental text search is fixed and improved (kiro only highlights current match and only hits\n  once per line).\n\n[Kiro][] aims to support kinds of xterm terminals on Unix-like systems. For example Terminal.app,\niTerm2.app, Gnome-Terminal, (hopefully) Windows Terminal on WSL.\n\nI learned various things by making this project following ['Build Your Own Text Editor' guide][byote].\nPlease read 'Implementation' section below to find some interesting topics.\n\n\n\n## Installation\n\nPlease install [`kiro-editor`][crates-io] package by building from sources using [cargo][].\n\n```\n$ cargo install kiro-editor\n```\n\nNote: Please use a Rust stable toolchain as new as possible.\n\nFor NetBSD, `kiro-editor` package is available.\n\nhttps://pkgsrc.se/editors/kiro-editor\n\n\n\n## Usage\n\n### CLI\n\nInstalling [`kiro-editor`][crates-io] package introduces `kiro` command in your system.\n\n```sh\n$ kiro                 # Start with an empty text buffer\n$ kiro file1 file2...  # Open files to edit\n```\n\nPlease see `kiro --help` for command usage.\n\n\n### Edit Text\n\nKiro is a mode-less text editor. Like other famous mode-less text editors such as Nano, Emacs,\nGedit or NotePad.exe, you can edit text in terminal window using a keyboard.\n\nAnd several keys with Ctrl or Alt modifiers are mapped to various features. You don't need to\nremember all mappings. Please type `Ctrl-?` to know all mappings in editor.\n\n- **Operations**\n\n| Mapping  | Description                                                                         |\n|----------|-------------------------------------------------------------------------------------|\n| `Ctrl-?` | Show all key mappings in editor screen.                                             |\n| `Ctrl-Q` | Quit Kiro. If current text is not saved yet, you need to input `Ctrl-Q` twice.      |\n| `Ctrl-S` | Save current buffer to file. Prompt shows up to enter file name for unnamed buffer. |\n| `Ctrl-G` | Incremental text search.                                                            |\n| `Ctrl-O` | Open file or empty buffer.                                                          |\n| `Ctrl-X` | Switch to next buffer.                                                              |\n| `Alt-X`  | Switch to previous buffer.                                                          |\n| `Ctrl-L` | Refresh screen.                                                                     |\n\n- **Moving cursor**\n\n| Mapping                             | Description                        |\n|-------------------------------------|------------------------------------|\n| `Ctrl-P` or `↑`                    | Move cursor up.                    |\n| `Ctrl-N` or `↓`                    | Move cursor down.                  |\n| `Ctrl-F` or `→`                    | Move cursor right.                 |\n| `Ctrl-B` or `←`                    | Move cursor left.                  |\n| `Ctrl-A` or `Alt-←` or `HOME`      | Move cursor to head of line.       |\n| `Ctrl-E` or `Alt-→` or `END`       | Move cursor to end of line.        |\n| `Ctrl-[` or `Ctrl-V` or `PAGE DOWN` | Next page.                         |\n| `Ctrl-]` or `Alt-V` or `PAGE UP`    | Previous page.                     |\n| `Alt-F` or `Ctrl-→`                | Move cursor to next word.          |\n| `Alt-B` or `Ctrl-←`                | Move cursor to previous word.      |\n| `Alt-N` or `Ctrl-↓`                | Move cursor to next paragraph.     |\n| `Alt-P` or `Ctrl-↑`                | Move cursor to previous paragraph. |\n| `Alt-\u003c`                             | Move cursor to top of file.        |\n| `Alt-\u003e`                             | Move cursor to bottom of file.     |\n\n- **Edit text**\n\n| Mapping                 | Description               |\n|-------------------------|---------------------------|\n| `Ctrl-H` or `BACKSPACE` | Delete character          |\n| `Ctrl-D` or `DELETE`    | Delete next character     |\n| `Ctrl-W`                | Delete a word             |\n| `Ctrl-J`                | Delete until head of line |\n| `Ctrl-K`                | Delete until end of line  |\n| `Ctrl-M`                | Insert new line           |\n| `Ctrl-U`                | Undo last change          |\n| `Ctrl-R`                | Redo last undo change     |\n\nHere is some screenshots for basic features.\n\n- **Create a new file**\n\n\u003cimg width=365 height=220 src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/new_file.gif?raw=true\" alt=\"screenshot for creating a new file\" /\u003e\n\n- **Incremental text search**\n\n\u003cimg width=380 height=220 src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/search.gif?raw=true\" alt=\"screenshot for incremental text search\" /\u003e\n\n\n### Extended Features\n\n#### Support Editing UTF-8 Text\n\nKiro is a UTF-8 text editor. So you can open/create/insert/delete/search UTF-8 text including double width\ncharacters support.\n\n![UTF-8 supports](https://github.com/rhysd/ss/blob/master/kiro-editor/multibyte_chars.gif?raw=true)\n\nNote that emojis using `U+200D` (zero width joiner) like '👪' are not supported yet.\n\nPlease read 'Support Editing UTF-8 Text' subsection for implementation details.\n\n#### 24-bit colors (true colors) and 256 colors support\n\nKiro utilizes colors as much as possible looking your terminal supports. It outputs 24-bit colors\nwith [gruvbox][] color scheme falling back to 256 colors or eventually to 16 colors.\n\n- **24-bit colors**\n\n\u003cimg src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/colors_true.png?raw=true\" alt=\"24-bit colors screenshot\" width=562 height=343 /\u003e\n\n- **256 colors**\n\n\u003cimg src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/colors_256.png?raw=true\" alt=\"256 colors screenshot\" width=562 height=339 /\u003e\n\n- **16 colors**\n\n\u003cimg src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/colors_16.png?raw=true\" alt=\"16 colors screenshot\" width=554 height=339 /\u003e\n\n#### Handle window resize\n\nTerminal notifies a window resize event via SIGWINCH signal. Kiro catches the signal and properly redraws\nits screen with new window size.\n\n![resize window](https://github.com/rhysd/ss/blob/master/kiro-editor/resize.gif?raw=true)\n\n### Undo/Redo\n\nKiro supports undo/redo editing (`Ctrl-U` for undo, `Ctrl-R` for redo). Max number of history entries\nis 1000. After exceeding it, oldest entry is removed on adding new change to text.\n\n\u003cimg src=\"https://github.com/rhysd/ss/blob/master/kiro-editor/undo_redo.gif?raw=true\" alt=\"undo/redo screencast\" width=589 height=412 /\u003e\n\nPlease read 'Text editing as sequence of diffs' subsection.\n\n\n\n## Implementation\n\nThis project was a study to understand how a text editor can be implemented interacting with a\nterminal application. I learned many things related to interactions between terminal and application\nand several specs of terminal escape sequences such as VT100 or xterm.\n\nI started from porting an awesome minimal text editor [kilo][] following a guide\n['Built Your Own Text Editor'][byote]. And then I added several improvements to my implementation.\n\nHere I write topics which were particularly interesting for me.\n\n\n### Efficient Rendering and Highlighting\n\n[kilo][] updates rendering and highlighting each time you input a key. This implementation is great\nto make implementation simple and it works fine.\n\nHowever, it is insufficient and I felt some performance issue on editing larger (10000~ lines) C file.\n\nSo [Kiro][] improves the implementation to render the screen and to update highlighting only when\nnecessary.\n\n[Kiro][] has a variable `dirty_start` in `Screen` struct of [screen.rs](./src/screen.rs). It manages\nfrom which line rendering should be started.\n\nFor example, let's say we have C code bellow:\n\n```c\nint main() {\n    printf(\"hello\\n\");\n}\n```\n\nAnd put `!` like `printf(\"hello!\\n\");`.\n\nIn the case, first line does not change. So we don't need to update the line. However, Kiro renders\nthe `}` line also even if the line does not change. This is because modifying text may cause highlight\nof lines after the line. For example, when deleting `\"` after `\\n`, string literal is not terminated so\nnext line continues string literal highlighting.\n\nHighlighting has the similar characteristic. Though [kilo][] calculates highlighting of entire text buffer\neach time you input key, actually the lines after bottom of screen are not rendered.\nFor current syntax highlighting, changes to former lines may affect later lines highlighting\n(e.g. block comments `/* */`), changes to later lines don't affect former lines highlighting. So Kiro\nstops calculating highlights at the line of bottom of screen.\n\n\n### UTF-8 Support\n\n[kilo][] only supports ASCII text. Width of ASCII character is fixed to 1 byte. This assumption reduces\ncomplexity of implementation of kilo greatly because:\n\n- every character can be represented as `char` (almost the same as `u8` in Rust)\n- any character in ASCII text can be accessed via byte index in O(1)\n- length of text is the same as number of bytes of the text\n\nSo kilo can contain text buffer as simple `char *` and accesses characters in it via byte index.\nIn addition, display width of all printable ASCII characters is fixed except for `0x09` tab character.\n\nBut actually there are more characters in the world defined as Unicode characters. Since I'm Japanese,\nthe characters such as Kanji or Hiragana I'm daily using are not ASCII. And the most major text encoding\nis UTF-8. So I determined to extend Kiro editor to support UTF-8.\n\nIn UTF-8, byte length of character is variable. Any character takes 1~4 bytes (or more in special case).\nThe important point here is that accessing to character in UTF-8 text is not O(1). To access to N-th\ncharacter or to know length of text, it requires to check characters from head of the text.\n\nAccessing to character in text and getting text length happen frequently while updating text buffer\nand highlights. So checking them in O(N) for each time is not efficient. To solve this problem, Kiro\ncontains byte indices of each characters in line text as `Vec\u003cusize\u003e`. These indices are only existing\nwhen at least one character in line text is non-ASCII character.\n\n![UTF-8 support diagram](./assets/utf-8-support-diagram.png)\n\nIn `Row` struct which represents one text line, `indices` field (`Vec\u003cusize\u003e`) is dedicated to store\nbyte indices of each character.\n\nIn the first case `\"Rust is nice\"`, all characters are ASCII so byte index can be used to access to\ncharacters in the text. In the case, `indices` field is an empty (and capacity is set to zero). A `Vec`\ninstance with zero capacity is guaranteed not to allocate heap memory. So the memory overhead here is\n24 bytes of `Vec\u003cusize\u003e` instance itself (pointer, capacity as `usize` and length as `usize`) only.\n\nIn the second case `\"Rust🦀良い\"`, there are some non-ASCII characters so `self.indices` caches byte\nindices of each characters. Thanks to this cache, each character can be accessed in O(1) and its text\nlength can be obtained in O(1) as `self.indices.len()`. `Row` also contains a rendered text and updates\nit when internal text buffer is updated by `TextBuffer`. So `self.indices` cache is also updated at\nthe same timing efficiently.\n\nThough keeping byte indices in `Vec\u003cusize\u003e` is quite memory inefficient, the indices are only required\nwhen the line text contains non-ASCII characters. In terms of programming code editor, it is relatively\nrare case, I believe.\n\n\n### Text Editing  as Sequence of Diffs\n\nIn Kiro editor, every text edit is represented as diff of text. So text editing means applying diffs to\ncurrent text buffer. Undo is represented as 'unapplying' diffs. Redo is represented as applying diffs\nagain.\n\nOne undo is represented as multiple diffs, not one diff. This is because users usually don't want to\nundo per inserting one character. So diffs each character inserts a character is put together as one\nundo.\n\n![UTF-8 support diagram](./assets/undo-redo-support-diagram.png)\n\nAt first a user inputs \"abc\" to text. The input is represented as 3 diffs of each\ncharacters and they consist of one undo unit. So inserting \"abc\" is reverted at once on undo though\nit is represented as multiple diffs.\nThen a user backs cursor by one character and delete characters \"ab\" until head of line. It is represented\nas one diff.\nFinally a user adds a new line by ENTER key. Inserting line is represented as two diffs. At first, editor\ntruncates a text after cursor (\"c\") and then it inserts new line \"c\" to next line to the cursor. These\ntwo diffs consist of one undo unit.\n\nBy managing history of text editing with undo units, every text edit can be represented as sequence of\ndiffs. Redo applies diffs in one undo unit to current text buffer. And undo unapplies diffs in one undo\nunit to current text buffer.\n\nNormal input is also treated as redo internally so that editor doesn't need to handle normal input with\nseparate implementation.\n\n### Porting C editor to Rust\n\n#### Separate one C source into several Rust modules\n\nTo simplify and minimize implementation, [kilo][] uses some global variables and local `static`\nvariables. Editor's state is stored in a global variable `E` and it is referred everywhere.\n\nWhile porting the code to Rust, I split `kilo.c` into some Rust modules for each logics. I removed\nthe global variables and local static variables by moving them to each logic's structs.\n\n- [`editor.rs`](src/editor.rs): Exports `Editor` struct, which manages an editor lifecycle; Runs loop\n  which gets key input, updates a text buffer and highlight then renders screen.\n- [`text_buffer.rs`](src/text_buffer.rs): Exports `TextBuffer` struct, which manages an editing text\n  buffer as `Vec\u003cRow\u003e`. It also contains metadata such as file name and file type of the buffer.\n- [`edit_diff.rs`](src/edit_diff.rs): Editing text is defined as applying sequence of diffs to text.\n  This module exports an enum `EditDiff` which represents the diff and logic to apply it to text.\n- [`row.rs`](src/row.rs): Exports `Row` struct which represents one line of text buffer and contains\n  actual text and rendered text. Since Kiro is dedicated for UTF-8 text editing, internal text buffer\n  is also kept as UTF-8 string. When the internal text buffer is updated by `Editor`, it automatically\n  updates rendered text also. It may also contain character indices for UTF-8 non-ASCII characters\n  (Please see below 'UTF-8 Support' section).\n- [`history.rs`](src/history.rs): It exports struct `History` which manages the edit history. The history\n  is represented as sequence of edit diffs. It manages the state of undo/redo and how many changes should\n  happen on one undo/redo operation.\n- [`input.rs`](src/input.rs): Exports `StdinRawMode` struct and `InputSequences` iterator.\n  `StdinRawMode` setups STDIN as raw mode (disable various terminal features such as echo back).\n  `InputSequences` reads user's key input as byte sequence with timeout and parses it as stream of\n  key sequence. VT100 and xterm escape sequences like `\\x1b[D` for `←` key are parsed here.\n- [`highlight.rs`](src/highlight.rs): Exports `Highlighting` struct, which contains highlight information\n  of each character in text buffer. It also manages highlighting in an editor lifecycle. It calculates\n  highlights of characters which is rendered and updates its information.\n- [`screen.rs`](src/screen.rs): Exports `Screen` struct, which represents screen rendering. It renders\n  each `Row` with highlight colors by outputting characters and escape sequences to STDOUT. As described\n  in previous section, it manages efficient rendering. It also manages and renders status bar and message\n  bar located at bottom of screen.\n- [`status_bar.rs`](src/status_bar.rs): Exports `StatusBar` struct which manages fields displayed in the\n  status bar. It has flag `redraw` to determine if it should be re-rendered.\n- [`prompt.rs`](src/prompt.rs): Exports structs related to user prompt using message bar. This module\n  has logic to run user prompt and text search. Callbacks while prompt is represented as a `PromptAction`\n  trait.\n- [`term_color.rs`](src/term_color.rs): Exports small `TermColor` enum and `Color` enum, which represents\n  terminal colors. This module also has logic to detect 24-bit colors and 256 colors support of terminal.\n- [`language.rs`](src/language.rs): Exports small `Language` enum, which represents file types like\n  C, Rust, Go, JavaScript, C++. It contains logic to detect a file type from file name.\n- [`signal.rs`](src/signal.rs): Exports `SigwinchWatcher` struct, which receives SIGWINCH signal and\n  notifies it to `Screen`. The signal is sent when terminal window size changed. `Screen` requires\n  the notification for resizing the screen.\n- [`error.rs`](src/error.rs): Exports `Error` enum and `Result\u003cT\u003e` type to handle all kinds of error\n  which may occur in Kiro editor.\n\n#### Error handling and resource clean up\n\n[kilo][] outputs message by `perror()` and immediately exits on error. It also cleans up STDIN\nconfiguration with `atexit` hook.\n\nKiro is implemented in Rust. So it utilizes Rust idioms to handle errors with `io::Result` and `?`\noperator. It reduces codes for error handling so that I could focus on implementing editor logics.\n\nFor resource clean up, Rust's `Drop` crate works greatly in `input.rs`.\n\n```rust\nstruct StdinRawMode {\n    stdin: io::Stdin,\n    // ...\n}\n\nimpl StdinRawMode {\n    fn new() -\u003e io::Result\u003cStdinRawMode\u003e {\n        // Setup terminal raw mode of stdin here\n        // ...\n    }\n}\n\nimpl Drop for StdinRawMode {\n    fn drop(\u0026mut self) {\n        // Restore original terminal mode of stdin here\n    }\n}\n\nimpl Deref for StdinRawMode {\n    type Target = io::Stdin;\n    fn deref(\u0026self) -\u003e \u0026Self::Target {\n        \u0026self.stdin\n    }\n}\n\nimpl DerefMut for StdinRawMode {\n    fn deref_mut(\u0026mut self) -\u003e \u0026mut Self::Target {\n        \u0026mut self.stdin\n    }\n}\n```\n\nThe `drop()` method is called when `StdinRawMode` instance dies. So user doesn't need to remember\nthe clean up. And `StdinRawMode` also implements `Deref` and `DerefMut` so that it behaves almost\nas if it were `Stdin`. By wrapping `io::Stdin` like this, I could add the ability to enter/leave\nterminal raw mode to `io::Stdin`.\n\n#### Abstract input and output of editor\n\n```rust\npub struct Editor\u003cI, W\u003e\nwhere\n    I: Iterator\u003cItem = io::Result\u003cInputSeq\u003e\u003e,\n    W: Write,\n{\n    // ...\n}\n\nimpl\u003cI, W\u003e Editor\u003cI, W\u003e\nwhere\n    I: Iterator\u003cItem = io::Result\u003cInputSeq\u003e\u003e,\n    W: Write,\n{\n    // Initialize Editor struct with given input and output\n    pub fn new(input: I, output: W) -\u003e io::Result\u003cEditor\u003cI, W\u003e\u003e {\n        // ...\n    }\n}\n```\n\nThe input of terminal text editor is a stream of input sequences from terminal which include\nuser's key input and control sequences. The input is represented with `Iterator` trait of input sequence.\nHere `InputSeq` represents one key input or one control sequence.\n\nThe output of terminal text editor is also stream of sequences to terminal which include output\nstrings and control sequences. It's done by simply writing to stdout. So it is represented with\n`Write` trait.\n\nThe benefit of these abstractions are testability of each modules. By creating a dummy struct which\nimplements `Iterator\u003cItem = io::Result\u003cInputSeq\u003e\u003e`, the input can be easily replaced with dummy input.\nSince [kilo][] does not have tests, these abstractions are not necessary for it.\n\n```rust\nstruct DummyInput(Vec\u003cInputSeq\u003e);\n\nimpl Iterator for DummyInput {\n    type Item = io::Result\u003cInputSeq\u003e;\n\n    fn next(\u0026mut self) -\u003e Option\u003cSelf::Item\u003e {\n        if self.0.is_empty() {\n            None\n        } else {\n            Some(Ok(self.0.remove(0)))\n        }\n    }\n}\n\n// Dummy Ctrl-Q input to editor\nlet dummy_input = DummyInput(vec![ InputSeq::ctrl(b'q') ]);\n```\n\nAnd by implementing a small struct which simply discards output, we can ignore the output. It does\nnot need to draw screen in terminal window. And it does not rely on global state (terminal raw mode)\nso that tests can run in parallel. As the result tests can run faster and terminal window doesn't mess up.\n\n```rust\nstruct Discard;\n\nimpl Write for Discard {\n    fn write(\u0026mut self, buf: \u0026[u8]) -\u003e io::Result\u003cusize\u003e {\n        Ok(buf.len())\n    }\n\n    fn flush(\u0026mut self) -\u003e io::Result\u003c()\u003e {\n        Ok(())\n    }\n}\n```\n\nBy using these mocks the input and output of editor can be tested easily as follows:\n\n```rust\n#[test]\nfn test_editor() {\n    let mut editor = Editor::new(dummy_input, Discard).unwrap();\n    editor.edit().unwrap();\n    for line in editor.lines() {\n        // Check lines of the current text buffer\n    }\n}\n```\n\n#### Dependant Crates\n\nThis project depends on some small crates. I selected them carefully not to prevent learning how a\ntext editor on terminal works.\n\n- [termios][]: Safe binding to `termios` interface provided by OS.\n- [term_size][]: Safe binding to getting terminal window size with ioctl(2).\n- [unicode-width][]: Small library to calculate Unicode character's display width.\n- [term][]: Library for terminfo and terminal colors. This project uses this library only to parse\n  terminfo for 256 colors support.\n- [signal-hook][]: Small wrapper for signal handler to catch SIGWINCH for resize support.\n- [getopts][]: Fairly small library to parse command line arguments. Kiro only has quite simple CLI\n  options so [clap][] is too heavy.\n\n\n### TODO\n\n- Unit tests are not sufficient. More tests should be added\n- Improve scrolling performance (Is terminal scrolling available?)\n- Minimal documentation\n- Text selection and copy from or paste to system clipboard\n- Keeping all highlights (`Vec\u003cHighlight\u003e`) is not memory efficient. Keep bits only for current\n  screen (`rowoff..rowoff+num_rows`)\n- Use parser library [combine](https://github.com/Marwes/combine) or [nom](https://github.com/Geal/nom)\n  to calculate highlighting. Need some investigation since highlight parser must stop calculating when\n  current line exceeds the bottom line of screen. Also [syntect](https://github.com/trishume/syntect) is\n  interesting.\n\n\n### Future Works\n\n- Use incremental parsing for accurate syntax highlighting\n- Support more systems and terminals\n- Look editor configuration file such as [EditorConfig](https://editorconfig.org/)\n  or [`.vscode` VS Code workspace settings](https://code.visualstudio.com/docs/getstarted/settings)\n- Support emojis using `U+200D`\n- WebAssembly support\n- Mouse support\n- Completion, go to definition and look up using language servers\n\n\n### Development\n\nBenchmarks are done by [cargo bench][cargo-bench] and fuzzing is done by [cargo fuzz][cargo-fuzz] and [libFuzzer][libfuzzer].\n\n```sh\n# Create release build\ncargo build --release\n\n# Run tests\ncargo test\n\n# Run benchmarks\ncargo +nightly bench -- --logfile out.txt \u0026\u0026 cat out.txt\n\n# Run fuzzing\ncargo +nightly fuzz run input_text\n```\n\n\n\n## License\n\nThis project is distributed under [the MIT License](./LICENSE.txt).\n\n\n[Kiro]: https://github.com/rhysd/kiro-editor\n[kilo]: https://github.com/antirez/kilo\n[byote]: https://viewsourcecode.org/snaptoken/kilo/\n[gruvbox]: https://github.com/morhetz/gruvbox\n[cargo]: https://github.com/rust-lang/cargo\n[build-badge]: https://github.com/rhysd/kiro-editor/workflows/CI/badge.svg\n[ci]: https://github.com/rhysd/kiro-editor/actions\n[crates-io]: https://crates.io/crates/kiro-editor\n[crates-io-badge]: https://img.shields.io/crates/v/kiro-editor.svg\n[termios]: https://crates.io/crates/termios\n[term_size]: https://crates.io/crates/term_size\n[unicode-width]: https://crates.io/crates/unicode-width\n[term]: https://crates.io/crates/term\n[signal-hook]: https://crates.io/crates/signal-hook\n[getopts]: https://crates.io/crates/getopts\n[clap]: https://crates.io/crates/clap\n[cargo-bench]: https://doc.rust-lang.org/cargo/commands/cargo-bench.html\n[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz\n[libfuzzer]: https://llvm.org/docs/LibFuzzer.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fkiro-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Fkiro-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fkiro-editor/lists"}