feat(args): add --query argument for tui

This commit is contained in:
Orhun Parmaksız 2022-01-28 01:52:51 +03:00
parent e8c052e730
commit 04b056c202
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
3 changed files with 13 additions and 4 deletions

View file

@ -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<String>) -> 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() {

View file

@ -18,6 +18,8 @@ pub struct Args {
pub tick_rate: u64,
/// Path of the Linux kernel documentation.
pub kernel_docs: Option<PathBuf>,
/// Query to search on startup.
pub search_query: Option<String>,
/// Do not parse/show Linux kernel documentation.
pub no_docs: bool,
}
@ -38,6 +40,7 @@ impl Args {
"set the path of the kernel documentation",
"<path>",
);
opts.optopt("q", "query", "set the query to search", "<query>");
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"),
})
}

View file

@ -48,7 +48,7 @@ pub fn run<Output: Write>(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()? {