mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-24 13:59:49 -04:00
wip: U/X columns: key binds
This commit is contained in:
parent
1cc59e4e2f
commit
01c2180c20
@ -15,8 +15,8 @@ use ratatui::{
|
|||||||
use tui_prompts::{State, Status, TextPrompt, TextState};
|
use tui_prompts::{State, Status, TextPrompt, TextState};
|
||||||
use tui_textarea::{CursorMove, TextArea};
|
use tui_textarea::{CursorMove, TextArea};
|
||||||
|
|
||||||
pub mod render;
|
|
||||||
mod cmd;
|
mod cmd;
|
||||||
|
pub mod render;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ pub struct AppState<'ws> {
|
|||||||
pub table_state: TableState,
|
pub table_state: TableState,
|
||||||
pub command_state: TextState<'ws>,
|
pub command_state: TextState<'ws>,
|
||||||
dirty: bool,
|
dirty: bool,
|
||||||
popup: Vec<String>
|
popup: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ws> Default for AppState<'ws> {
|
impl<'ws> Default for AppState<'ws> {
|
||||||
@ -198,9 +198,7 @@ impl<'ws> Workspace<'ws> {
|
|||||||
"Command Mode:".to_string(),
|
"Command Mode:".to_string(),
|
||||||
"* ESC: Exit command mode".to_string(),
|
"* ESC: Exit command mode".to_string(),
|
||||||
],
|
],
|
||||||
_ => vec![
|
_ => vec!["General help".to_string()],
|
||||||
"General help".to_string(),
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,20 +274,20 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.book.insert_columns(self.book.location.col, count)?;
|
self.book.insert_columns(self.book.location.col, count)?;
|
||||||
self.book.evaluate();
|
self.book.evaluate();
|
||||||
Ok(true)
|
Ok(true)
|
||||||
},
|
}
|
||||||
Ok(Some(Cmd::InsertRow(count))) => {
|
Ok(Some(Cmd::InsertRow(count))) => {
|
||||||
self.book.insert_rows(self.book.location.row, count)?;
|
self.book.insert_rows(self.book.location.row, count)?;
|
||||||
self.book.evaluate();
|
self.book.evaluate();
|
||||||
Ok(true)
|
Ok(true)
|
||||||
},
|
}
|
||||||
Ok(Some(Cmd::Quit)) => {
|
Ok(Some(Cmd::Quit)) => {
|
||||||
// TODO(zaphar): We probably need to do better than this
|
// TODO(zaphar): We probably need to do better than this
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
},
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
self.enter_dialog_mode(vec![format!("Unrecognized commmand {}", cmd_text)]);
|
self.enter_dialog_mode(vec![format!("Unrecognized commmand {}", cmd_text)]);
|
||||||
Ok(false)
|
Ok(false)
|
||||||
},
|
}
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
self.enter_dialog_mode(vec![msg.to_owned()]);
|
self.enter_dialog_mode(vec![msg.to_owned()]);
|
||||||
Ok(false)
|
Ok(false)
|
||||||
@ -306,12 +304,27 @@ impl<'ws> Workspace<'ws> {
|
|||||||
KeyCode::Char(':') => {
|
KeyCode::Char(':') => {
|
||||||
self.enter_command_mode();
|
self.enter_command_mode();
|
||||||
}
|
}
|
||||||
KeyCode::Char('h') if key.modifiers == KeyModifiers::CONTROL => {
|
|
||||||
self.enter_dialog_mode(self.render_help_text());
|
|
||||||
}
|
|
||||||
KeyCode::Char('s') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('s') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
self.save_file()?;
|
self.save_file()?;
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('s')
|
||||||
|
if key.modifiers == KeyModifiers::HYPER
|
||||||
|
|| key.modifiers == KeyModifiers::SUPER =>
|
||||||
|
{
|
||||||
|
self.save_file()?;
|
||||||
|
}
|
||||||
|
KeyCode::Char('l') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
|
let Address { row: _, col } = &self.book.location;
|
||||||
|
self.book
|
||||||
|
.set_col_size(*col, self.book.get_col_size(*col)? + 1)?;
|
||||||
|
}
|
||||||
|
KeyCode::Char('h') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
|
let Address { row: _, col } = &self.book.location;
|
||||||
|
let curr_size = self.book.get_col_size(*col)?;
|
||||||
|
if curr_size > 1 {
|
||||||
|
self.book.set_col_size(*col, curr_size - 1)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
KeyCode::Char('r') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('r') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
let (row_count, _) = self.book.get_size()?;
|
let (row_count, _) = self.book.get_size()?;
|
||||||
self.book.update_entry(
|
self.book.update_entry(
|
||||||
@ -342,19 +355,19 @@ impl<'ws> Workspace<'ws> {
|
|||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
return Ok(Some(ExitCode::SUCCESS));
|
return Ok(Some(ExitCode::SUCCESS));
|
||||||
}
|
}
|
||||||
KeyCode::Char('j') => {
|
KeyCode::Char('j') | KeyCode::Down if key.modifiers != KeyModifiers::CONTROL => {
|
||||||
self.move_down()?;
|
self.move_down()?;
|
||||||
self.handle_movement_change();
|
self.handle_movement_change();
|
||||||
}
|
}
|
||||||
KeyCode::Char('k') => {
|
KeyCode::Char('k') | KeyCode::Up if key.modifiers != KeyModifiers::CONTROL => {
|
||||||
self.move_up()?;
|
self.move_up()?;
|
||||||
self.handle_movement_change();
|
self.handle_movement_change();
|
||||||
}
|
}
|
||||||
KeyCode::Char('h') => {
|
KeyCode::Char('h') | KeyCode::Left if key.modifiers != KeyModifiers::CONTROL => {
|
||||||
self.move_left()?;
|
self.move_left()?;
|
||||||
self.handle_movement_change();
|
self.handle_movement_change();
|
||||||
}
|
}
|
||||||
KeyCode::Char('l') => {
|
KeyCode::Char('l') | KeyCode::Right if key.modifiers != KeyModifiers::CONTROL => {
|
||||||
self.move_right()?;
|
self.move_right()?;
|
||||||
self.handle_movement_change();
|
self.handle_movement_change();
|
||||||
}
|
}
|
||||||
@ -405,7 +418,7 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.state.pop_modality();
|
self.state.pop_modality();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_edit_mode(&mut self) -> Result<()> {
|
fn exit_edit_mode(&mut self) -> Result<()> {
|
||||||
self.text_area.set_cursor_line_style(Style::default());
|
self.text_area.set_cursor_line_style(Style::default());
|
||||||
self.text_area.set_cursor_style(Style::default());
|
self.text_area.set_cursor_style(Style::default());
|
||||||
|
@ -131,3 +131,5 @@ fn test_quit_cmd() {
|
|||||||
let cmd = output.unwrap();
|
let cmd = output.unwrap();
|
||||||
assert_eq!(cmd, Cmd::Quit);
|
assert_eq!(cmd, Cmd::Quit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(zaphar): Interaction testing for input.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user