~hime/protochat

f98197b1d5207eab030be80a37033929091086cb — drbawb 11 months ago a9bdf6a
(ui): implement Home & End keys

- (term) adds event handlers for `KeyCode::Home` and `KeyCode::End`.
- (buffer) adds `goto_head` and `goto_tail` methods for `InputBuffer`.
2 files changed, 16 insertions(+), 0 deletions(-)

M linetest/src/shell/ui/buffer.rs
M linetest/src/shell/ui/term.rs
M linetest/src/shell/ui/buffer.rs => linetest/src/shell/ui/buffer.rs +8 -0
@@ 236,6 236,14 @@ impl InputBuffer {
        }
    }

    pub fn goto_head(&mut self) {
        self.pos = 0;
    }

    pub fn goto_tail(&mut self) {
        self.pos = self.buffer.len();
    }

    pub fn take(&mut self) -> String {
        let mut old_buffer = String::new();
        std::mem::swap(&mut self.buffer, &mut old_buffer);

M linetest/src/shell/ui/term.rs => linetest/src/shell/ui/term.rs +8 -0
@@ 147,6 147,14 @@ impl TermInterface {
                    self.syslog.scroll_down();
                },

                event::KeyCode::Home => {
                    self.buffer.goto_head();
                },

                event::KeyCode::End => {
                    self.buffer.goto_tail();
                },

                _ => {},
            },
        }