-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement general purpose settings for sort
Make sort enum and share it with other views that we want to search
- Loading branch information
1 parent
9dc7635
commit 1003a61
Showing
9 changed files
with
229 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::sync::Arc; | ||
|
||
use cli_args::GeneralSort; | ||
use crossterm::event::KeyCode; | ||
|
||
use crate::{ | ||
cli_args::{self, Args}, | ||
Ctx, | ||
}; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct GeneralOptions { | ||
pub sort: GeneralSort, | ||
} | ||
|
||
impl GeneralOptions { | ||
pub fn new(args: &Args) -> Self { | ||
Self { | ||
sort: args.sort.unwrap_or_default(), | ||
} | ||
} | ||
|
||
pub fn handle_keystroke(keycode: &KeyCode, ctx: &Arc<Ctx>) -> bool { | ||
match keycode { | ||
KeyCode::Char('n') => { | ||
let mut general_options = ctx.general_options.write().unwrap(); | ||
general_options.sort = match general_options.sort { | ||
GeneralSort::Name => GeneralSort::DefaultSort, | ||
GeneralSort::DefaultSort => GeneralSort::Name, | ||
}; | ||
|
||
return true; | ||
} | ||
_ => false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.