Skip to content

Commit

Permalink
chore(tui): keybindings improvements (#18)
Browse files Browse the repository at this point in the history
* chore(tui): keybindings improvements

* chore: clippy fix
  • Loading branch information
wolf4ood authored Sep 24, 2024
1 parent bd22a5a commit 7a261a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
21 changes: 17 additions & 4 deletions edc-connector-tui/src/components/header/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ impl InfoComponent {
}

fn view_key_bindings(&self, props: &InfoSheet, f: &mut Frame, rect: Rect) {
let layout = Layout::horizontal(vec![
Constraint::Percentage(20),
Constraint::Percentage(20),
Constraint::Percentage(20),
Constraint::Percentage(20),
Constraint::Percentage(20),
])
.split(rect);
let max = props
.iter_key_bindings()
.map(|(name, _)| name.len())
.max()
.unwrap_or(0);

let list = props
let lines = props
.iter_key_bindings()
.map(|(name, value)| {
let padding = max + 2 - name.len();
Expand All @@ -70,9 +78,14 @@ impl InfoComponent {
Span::raw(value),
])
})
.collect::<List>()
.block(Block::default());
.collect::<Vec<Line>>();

f.render_widget(list, rect)
let lists = lines
.chunks(5)
.map(|chunks| chunks.iter().map(Clone::clone).collect::<List>());

for (idx, list) in lists.enumerate() {
f.render_widget(list, layout[idx])
}
}
}
9 changes: 6 additions & 3 deletions edc-connector-tui/src/components/resources/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ impl<T> Default for ResourceComponent<T> {

impl<T> ResourceComponent<T> {
pub fn info_sheet(&self) -> InfoSheet {
InfoSheet::default().key_binding("<y>", "Copy value")
InfoSheet::default()
.key_binding("<j/down>", "Down")
.key_binding("<k/down>", "Up")
.key_binding("<y>", "Copy value")
}
}

Expand Down Expand Up @@ -83,8 +86,8 @@ impl<T: DrawableResource> ResourceComponent<T> {

fn handle_key(&self, key: KeyEvent) -> Vec<ComponentMsg<ResourceMsg>> {
match key.code {
KeyCode::Char('j') => vec![(ComponentMsg(ResourceMsg::MoveDown))],
KeyCode::Char('k') => vec![(ComponentMsg(ResourceMsg::MoveUp))],
KeyCode::Char('j') | KeyCode::Down => vec![(ComponentMsg(ResourceMsg::MoveDown))],
KeyCode::Char('k') | KeyCode::Up => vec![(ComponentMsg(ResourceMsg::MoveUp))],
KeyCode::Char('y') => vec![(ComponentMsg(ResourceMsg::Yank))],
_ => vec![],
}
Expand Down
8 changes: 6 additions & 2 deletions edc-connector-tui/src/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl<T: TableEntry, M> UiTable<T, M> {

pub fn info_sheet(&self) -> InfoSheet {
InfoSheet::default()
.key_binding("<j/down>", "Down")
.key_binding("<k/down>", "Up")
}

pub fn with_elements(name: String, elements: Vec<T>, show_block: bool) -> Self {
Expand Down Expand Up @@ -152,8 +154,10 @@ impl<T: TableEntry, M> UiTable<T, M> {
vec![]
}
}
KeyCode::Char('j') => vec![(ComponentMsg(TableLocalMsg::MoveDown.into()))],
KeyCode::Char('k') => vec![(ComponentMsg(TableLocalMsg::MoveUp.into()))],
KeyCode::Char('j') | KeyCode::Down => {
vec![(ComponentMsg(TableLocalMsg::MoveDown.into()))]
}
KeyCode::Char('k') | KeyCode::Up => vec![(ComponentMsg(TableLocalMsg::MoveUp.into()))],
_ => vec![],
}
}
Expand Down
1 change: 0 additions & 1 deletion edc-connector-tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ mod tui {
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// Sets a custom config file
#[arg(short, long, value_name = "FILE")]
config: Option<PathBuf>,
#[command(subcommand)]
Expand Down

0 comments on commit 7a261a2

Please sign in to comment.