Skip to content

Commit

Permalink
toml configuration and fix keys
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier committed Sep 30, 2024
1 parent 7f13c15 commit 048ce76
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 33 deletions.
12 changes: 6 additions & 6 deletions .config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"Input": {
"<q>": "Quit", // Quit the application
"<esc>": "Quit", // Quit the application
"<ctrl-d>": "Quit", // Another way to quit
"<ctrl-c>": "Quit", // Yet another way to quit
"<ctrl-z>": "Suspend", // Suspend the application
"<tab>": "GoToNextPane", // Move to the next pane
"<backtab>": "GoToPrevPane", // Move to the previous pane
"<ctrl-up>": "GoToPaneUp", // Move to the pane above
"<ctrl-down>": "GoToPaneDown", // Move to the pane below
// "<ctrl-up>": "GoToPaneUp", // Move to the pane above
// "<ctrl-down>": "GoToPaneDown", // Move to the pane below
"<ctrl-left>": "GoToPaneLeft", // Move to the pane to the left
"<ctrl-right>": "GoToPaneRight", // Move to the pane to the right
"<down>": "SelectNextEntry", // Move to the next entry
"<up>": "SelectPrevEntry", // Move to the previous entry
"<ctrl-n>": "SelectNextEntry", // Move to the next entry
"<ctrl-p>": "SelectPrevEntry", // Move to the previous entry
"ctrl-down": "ScrollPreviewDown", // Scroll the preview down
"ctrl-up": "ScrollPreviewUp", // Scroll the preview up
"<ctrl-down>": "ScrollPreviewDown", // Scroll the preview down
"<ctrl-up>": "ScrollPreviewUp", // Scroll the preview up
"<ctrl-d>": "ScrollPreviewHalfPageDown", // Scroll the preview half a page down
"<ctrl-u>": "ScrollPreviewHalfPageUp", // Scroll the preview half a page up

},
}
}
29 changes: 17 additions & 12 deletions .config/config.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
FIXME: this doesn't work
[keybindings]
Input = {
"<q>": "Quit", // Quit the application
"<ctrl-d>": "Quit", // Another way to quit
"<ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-z>": "Suspend", // Suspend the application
},

Help = {
"<q>" = "Quit" # Quit the help panel
}
[keybindings.Input]
q = "Quit"
esc = "Quit"
ctrl-c = "Quit"
ctrl-z = "Suspend"
tab = "GoToNextPane"
backtab = "GoToPrevPane"
ctrl-left = "GoToPaneLeft"
ctrl-right = "GoToPaneRight"
down = "SelectNextEntry"
up = "SelectPrevEntry"
ctrl-n = "SelectNextEntry"
ctrl-p = "SelectPrevEntry"
ctrl-down = "ScrollPreviewDown"
ctrl-up = "ScrollPreviewUp"
ctrl-d = "ScrollPreviewHalfPageDown"
ctrl-u = "ScrollPreviewHalfPageUp"
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## improvements
- [x] async finder initialization
- [x] async finder search
- [ ] use nucleo for env
- [x] use nucleo for env
- [ ] better keymaps

## feature ideas
Expand Down
7 changes: 4 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ pub struct App {
frame_rate: f64,
//components: Arc<Mutex<Vec<Box<dyn Component>>>>,
television: Arc<Mutex<Television>>,
active_component: usize,
should_quit: bool,
should_suspend: bool,
mode: Mode,
Expand Down Expand Up @@ -103,7 +102,6 @@ impl App {
tick_rate,
frame_rate,
television,
active_component: 0,
should_quit: false,
should_suspend: false,
config: Config::new()?,
Expand Down Expand Up @@ -151,6 +149,7 @@ impl App {
self.handle_actions().await?;

if self.should_quit {
// send a termination signal to the event loop
self.event_abort_tx.send(())?;
break;
}
Expand All @@ -163,7 +162,8 @@ impl App {
Event::Input(keycode) => {
info!("{:?}", keycode);
// if the current component is the television
// and the mode is input, we want to handle
// and the mode is input, automatically handle
// (these mappings aren't exposed to the user)
if self.television.lock().await.is_input_focused() {
match keycode {
Key::Backspace => return Action::DeletePrevChar,
Expand All @@ -187,6 +187,7 @@ impl App {
Action::NoOp
});
}
// terminal events
Event::Tick => Action::Tick,
Event::Resize(x, y) => Action::Resize(x, y),
Event::FocusGained => Action::Resume,
Expand Down
6 changes: 4 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::{
event::{convert_raw_event_to_key, Key},
};

const CONFIG: &str = include_str!("../.config/config.json5");
//const CONFIG: &str = include_str!("../.config/config.json5");
const CONFIG: &str = include_str!("../.config/config.toml");

#[derive(Clone, Debug, Deserialize, Default)]
pub struct AppConfig {
Expand Down Expand Up @@ -49,7 +50,8 @@ lazy_static! {

impl Config {
pub fn new() -> Result<Self, config::ConfigError> {
let default_config: Config = json5::from_str(CONFIG).unwrap();
//let default_config: Config = json5::from_str(CONFIG).unwrap();
let default_config: Config = toml::from_str(CONFIG).unwrap();
let data_dir = get_data_dir();
let config_dir = get_config_dir();
let mut builder = config::Config::builder()
Expand Down
39 changes: 30 additions & 9 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ pub enum Event<I> {

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash)]
pub enum Key {
CtrlBackspace,
CtrlDelete,
AltBackspace,
AltDelete,
Backspace,
Enter,
Left,
Right,
Up,
Down,
CtrlBackspace,
CtrlEnter,
CtrlLeft,
CtrlRight,
CtrlUp,
CtrlDown,
CtrlDelete,
AltBackspace,
AltDelete,
Home,
End,
PageUp,
Expand Down Expand Up @@ -127,11 +133,26 @@ pub fn convert_raw_event_to_key(event: KeyEvent) -> Key {
KeyModifiers::ALT => Key::AltDelete,
_ => Key::Delete,
},
Enter => Key::Char('\n'),
Left => Key::Left,
Right => Key::Right,
Up => Key::Up,
Down => Key::Down,
Enter => match event.modifiers {
KeyModifiers::CONTROL => Key::CtrlEnter,
_ => Key::Enter,
},
Up => match event.modifiers {
KeyModifiers::CONTROL => Key::CtrlUp,
_ => Key::Up,
},
Down => match event.modifiers {
KeyModifiers::CONTROL => Key::CtrlDown,
_ => Key::Down,
},
Left => match event.modifiers {
KeyModifiers::CONTROL => Key::CtrlLeft,
_ => Key::Left,
},
Right => match event.modifiers {
KeyModifiers::CONTROL => Key::CtrlRight,
_ => Key::Right,
},
Home => Key::Home,
End => Key::End,
PageUp => Key::PageUp,
Expand Down
1 change: 1 addition & 0 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub async fn render(
tui.enter()?;
}
RenderingTask::Quit => {
tui.exit()?;
break Ok(());
}
}
Expand Down

0 comments on commit 048ce76

Please sign in to comment.