From 04b056c202b59c5040b5dcf37c42c02bda97295c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Fri, 28 Jan 2022 01:52:51 +0300 Subject: [PATCH] feat(args): add `--query` argument for tui --- systeroid-tui/src/app.rs | 11 ++++++++--- systeroid-tui/src/args.rs | 4 ++++ systeroid-tui/src/lib.rs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/systeroid-tui/src/app.rs b/systeroid-tui/src/app.rs index 51e5573..c730167 100644 --- a/systeroid-tui/src/app.rs +++ b/systeroid-tui/src/app.rs @@ -43,13 +43,13 @@ pub struct App<'a> { impl<'a> App<'a> { /// Constructs a new instance. - pub fn new(sysctl: &'a mut Sysctl) -> Self { + pub fn new(sysctl: &'a mut Sysctl, search_query: Option) -> Self { let mut app = Self { running: true, - input: None, + search_mode: search_query.is_some(), + input: search_query, input_time: None, input_cursor: 0, - search_mode: false, docs_scroll_amount: 0, options: None, parameter_list: SelectableList::default(), @@ -66,6 +66,11 @@ impl<'a> App<'a> { sysctl, }; app.parameter_list.items = app.sysctl.parameters.clone(); + if app.search_mode { + app.search(); + app.input = None; + app.search_mode = false; + } #[cfg(feature = "clipboard")] { app.clipboard = match DisplayServer::select().try_context() { diff --git a/systeroid-tui/src/args.rs b/systeroid-tui/src/args.rs index 35062bd..037ddc3 100644 --- a/systeroid-tui/src/args.rs +++ b/systeroid-tui/src/args.rs @@ -18,6 +18,8 @@ pub struct Args { pub tick_rate: u64, /// Path of the Linux kernel documentation. pub kernel_docs: Option, + /// Query to search on startup. + pub search_query: Option, /// Do not parse/show Linux kernel documentation. pub no_docs: bool, } @@ -38,6 +40,7 @@ impl Args { "set the path of the kernel documentation", "", ); + opts.optopt("q", "query", "set the query to search", ""); opts.optflag("n", "no-docs", "do not show the kernel documentation"); opts.optflag("h", "help", "display this help and exit"); opts.optflag("V", "version", "output version information and exit"); @@ -70,6 +73,7 @@ impl Args { .ok()? .unwrap_or(250), kernel_docs: matches.opt_str("D").map(PathBuf::from), + search_query: matches.opt_str("q"), no_docs: matches.opt_present("n"), }) } diff --git a/systeroid-tui/src/lib.rs b/systeroid-tui/src/lib.rs index 3c48606..b8768cb 100644 --- a/systeroid-tui/src/lib.rs +++ b/systeroid-tui/src/lib.rs @@ -48,7 +48,7 @@ pub fn run(args: Args, output: Output) -> Result<()> { if !args.no_docs { sysctl.update_docs_from_cache(args.kernel_docs.as_ref(), &Cache::init()?)?; } - let mut app = App::new(&mut sysctl); + let mut app = App::new(&mut sysctl, args.search_query); while app.running { terminal.draw(|frame| ui::render(frame, &mut app))?; match event_handler.next()? {