Skip to content

Commit

Permalink
Rust setup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Sep 22, 2024
1 parent e8b208f commit da96995
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tui/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ impl Float {
// Returns true if the floating window is finished.
pub fn handle_key_event(&mut self, key: &KeyEvent) -> bool {
match key.code {
KeyCode::Enter | KeyCode::Char('p') | KeyCode::Char('d') | KeyCode::Esc
KeyCode::Enter
| KeyCode::Char('p')
| KeyCode::Char('d')
| KeyCode::Char('g')
| KeyCode::Esc
if self.content.is_finished() =>
{
true
Expand Down
4 changes: 3 additions & 1 deletion tui/src/floating_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use zips::zip_result;
pub enum FloatingTextMode {
Preview,
Description,
ActionsGuide,
}

pub struct FloatingText {
Expand Down Expand Up @@ -182,6 +183,7 @@ impl FloatingText {
match mode {
FloatingTextMode::Preview => "Command Preview",
FloatingTextMode::Description => "Command Description",
FloatingTextMode::ActionsGuide => "Important Actions Guide",
}
}

Expand Down Expand Up @@ -299,7 +301,7 @@ impl FloatContent for FloatingText {
Shortcut::new(vec!["k", "Up"], "Scroll up"),
Shortcut::new(vec!["h", "Left"], "Scroll left"),
Shortcut::new(vec!["l", "Right"], "Scroll right"),
Shortcut::new(vec!["Enter", "p", "d"], "Close window"),
Shortcut::new(vec!["Enter", "p", "d", "g"], "Close window"),
],
}
}
Expand Down
1 change: 1 addition & 0 deletions tui/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
}
hints.push(Shortcut::new(vec!["Tab"], "Next tab"));
hints.push(Shortcut::new(vec!["Shift-Tab"], "Previous tab"));
hints.push(Shortcut::new(vec!["g"], "Important actions guide"));
ShortcutList {
scope_name: "Command list",
hints,
Expand Down
22 changes: 21 additions & 1 deletion tui/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ use ratatui::{
const MIN_WIDTH: u16 = 77;
const MIN_HEIGHT: u16 = 19;
const TITLE: &str = concat!("Linux Toolbox - ", env!("BUILD_DATE"));
const ACTIONS_GUIDE: &str = "D - disk modifications (ex. partitioning) (privileged)
FI - flatpak installation
FM - file modification
I - installation (privileged)
SI - full system installation
SS - systemd actions (privileged)
RP - package removal
P* - privileged *
";

pub struct AppState {
/// Selected theme
Expand Down Expand Up @@ -188,7 +198,7 @@ impl AppState {

let list_chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(60), Constraint::Percentage(40)].as_ref())
.constraints([Constraint::Percentage(85), Constraint::Percentage(15)].as_ref())
.split(chunks[1]);

self.filter.draw_searchbar(frame, chunks[0], &self.theme);
Expand Down Expand Up @@ -365,6 +375,7 @@ impl AppState {
KeyCode::Char('/') => self.enter_search(),
KeyCode::Char('t') => self.theme.next(),
KeyCode::Char('T') => self.theme.prev(),
KeyCode::Char('g') => self.toggle_task_list_guide(),
_ => {}
},
Focus::List if key.kind != KeyEventKind::Release => match key.code {
Expand All @@ -383,6 +394,7 @@ impl AppState {
KeyCode::Char('/') => self.enter_search(),
KeyCode::Char('t') => self.theme.next(),
KeyCode::Char('T') => self.theme.prev(),
KeyCode::Char('g') => self.toggle_task_list_guide(),
KeyCode::Char('v') | KeyCode::Char('V') => self.toggle_multi_select(),
KeyCode::Char(' ') if self.multi_select => self.toggle_selection(),
_ => {}
Expand Down Expand Up @@ -558,6 +570,14 @@ impl AppState {
self.selection.select(Some(0));
self.update_items();
}

fn toggle_task_list_guide(&mut self) {
self.spawn_float(
FloatingText::new(ACTIONS_GUIDE.to_string(), FloatingTextMode::ActionsGuide),
80,
80,
);
}
}

#[cfg(feature = "tips")]
Expand Down

0 comments on commit da96995

Please sign in to comment.