mirror of
https://github.com/orhun/systeroid
synced 2024-07-23 19:34:58 +00:00
refactor(tui): use Direction enum for indicating the cursor position
This commit is contained in:
parent
f351b80906
commit
21b3aed659
|
@ -345,12 +345,12 @@ impl<'a> App<'a> {
|
|||
}
|
||||
Command::MoveCursor(direction) => {
|
||||
if let Some(input) = &self.input {
|
||||
if direction == 0 {
|
||||
if direction == Direction::Right {
|
||||
if let Some(cursor_position) = self.input_cursor.checked_sub(1) {
|
||||
self.input_cursor = cursor_position as u16;
|
||||
}
|
||||
} else if self.input_cursor != input.width() as u16 {
|
||||
self.input_cursor += direction as u16;
|
||||
self.input_cursor += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ pub enum Command {
|
|||
Set(String, String),
|
||||
/// Scroll the widget.
|
||||
Scroll(ScrollArea, Direction, u8),
|
||||
/// Move cursor to right/left.
|
||||
MoveCursor(u8),
|
||||
/// Move cursor..
|
||||
MoveCursor(Direction),
|
||||
/// Enable the search mode.
|
||||
Search,
|
||||
/// Process the input.
|
||||
|
@ -71,8 +71,8 @@ impl Command {
|
|||
Key::Char(c) => Command::UpdateInput(c),
|
||||
Key::Backspace => Command::ClearInput(false),
|
||||
Key::Delete => Command::ClearInput(true),
|
||||
Key::Left => Command::MoveCursor(1),
|
||||
Key::Right => Command::MoveCursor(0),
|
||||
Key::Left => Command::MoveCursor(Direction::Left),
|
||||
Key::Right => Command::MoveCursor(Direction::Right),
|
||||
Key::Esc => Command::Exit,
|
||||
_ => Command::Nothing,
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ mod tests {
|
|||
Key::Char('a') => Command::UpdateInput('a'),
|
||||
Key::Backspace => Command::ClearInput(false),
|
||||
Key::Delete => Command::ClearInput(true),
|
||||
Key::Left => Command::MoveCursor(1),
|
||||
Key::Right => Command::MoveCursor(0),
|
||||
Key::Left => Command::MoveCursor(Direction::Left),
|
||||
Key::Right => Command::MoveCursor(Direction::Right),
|
||||
Key::Esc => Command::Exit,
|
||||
}
|
||||
assert_command_parser! {
|
||||
|
|
|
@ -50,7 +50,9 @@ generate_option!(
|
|||
generate_option!(
|
||||
Direction,
|
||||
Up => "up",
|
||||
Right => "right",
|
||||
Down => "down",
|
||||
Left => "left",
|
||||
Top => "top",
|
||||
Bottom => "bottom",
|
||||
);
|
||||
|
|
|
@ -101,7 +101,7 @@ fn test_tui() -> Result<()> {
|
|||
)?;
|
||||
|
||||
app.run_command(Command::ClearInput(false))?;
|
||||
app.run_command(Command::MoveCursor(2))?;
|
||||
app.run_command(Command::MoveCursor(Direction::Left))?;
|
||||
app.run_command(Command::ClearInput(true))?;
|
||||
app.run_command(Command::ClearInput(true))?;
|
||||
"kill"
|
||||
|
|
Loading…
Reference in a new issue