Minor code cleanup
This commit is contained in:
parent
4d1560717e
commit
c3dee47b46
11
README.md
11
README.md
@ -1,7 +1,7 @@
|
||||
# Oxidized Kilo
|
||||
|
||||
An experimental reimplementation of the [Kilo](https://viewsourcecode.org/snaptoken/kilo/index.html)
|
||||
tutorial with a Rust implementation.
|
||||
A reimplementation of the [Kilo](https://viewsourcecode.org/snaptoken/kilo/index.html)
|
||||
tutorial in Rust.
|
||||
|
||||
## Implementation notes:
|
||||
* The `editor` prefix has been removed from all the editor methods. Since this implementation
|
||||
@ -10,6 +10,9 @@ uses `impl`s on a shared `Editor` struct, the prefix is redundant
|
||||
implemented in a more idiomatic Rust fashion.
|
||||
* Row structs are referenced by their index in the Editor struct, rather than as a direct reference in method calls.
|
||||
This generally simplifies dealing with the rules of Rust (borrow checker).
|
||||
* The `prompt` method of the editor can not take an arbitrary formatting string, due to Rust requiring a string literal
|
||||
for string formatting macros.
|
||||
|
||||
### Known issues:
|
||||
* Tab key does not expand to an indent
|
||||
### Additions / Changes
|
||||
* Reverse coloring for search results, so comment types can have different colors
|
||||
* Two separate vectors are used to define the two types of keywords, rather than the weird pipe suffix
|
@ -146,6 +146,7 @@ pub enum KeyCode<T = char> {
|
||||
EndKey,
|
||||
PageUp,
|
||||
PageDown,
|
||||
Tab,
|
||||
/// Control key chords
|
||||
Ctrl(T),
|
||||
/// Function keys (F1, etc.) T holds the index
|
||||
@ -285,6 +286,7 @@ impl Editor {
|
||||
'\x08' => return Some(Backspace),
|
||||
'\x7f' => return Some(Backspace),
|
||||
'\r' => return Some(Enter),
|
||||
'\t' => return Some(Tab),
|
||||
ch => {
|
||||
if ch.is_ascii_control() {
|
||||
return Some(Ctrl(ctrl_to_letter(ch)));
|
||||
@ -790,6 +792,7 @@ impl Editor {
|
||||
self.cursor_x = self.rows[self.cursor_y].chars.len();
|
||||
}
|
||||
}
|
||||
Tab => self.insert_char('\t'),
|
||||
Ctrl(c) => match c {
|
||||
'f' => self.find(),
|
||||
's' => {
|
||||
|
20
src/main.rs
20
src/main.rs
@ -23,10 +23,8 @@ lazy_static! {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
// 'Access' the saved termios instance, to make sure it is set
|
||||
// before you enable raw mode.
|
||||
let mutex = Arc::clone(&ORIGINAL_TERMIOS);
|
||||
let _ = mutex.lock().unwrap();
|
||||
// Save existing Termios settings
|
||||
lazy_static::initialize(&ORIGINAL_TERMIOS);
|
||||
|
||||
// Disable canonical/"cooked" terminal mode
|
||||
enable_raw_mode();
|
||||
@ -48,18 +46,8 @@ fn main() -> Result<(), Error> {
|
||||
loop {
|
||||
editor.refresh_screen();
|
||||
|
||||
match editor.process_keypress() {
|
||||
Some(key) => {
|
||||
match key {
|
||||
editor::KeyCode::OtherKey('\0') => (),
|
||||
_ => {
|
||||
//println!("{:?}\r\n", key)
|
||||
|
||||
()
|
||||
}
|
||||
}
|
||||
}
|
||||
None => break,
|
||||
if editor.process_keypress().is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user