diff --git a/.config/config.toml b/.config/config.toml index 454dcbf..2e286e0 100644 --- a/.config/config.toml +++ b/.config/config.toml @@ -15,3 +15,4 @@ ctrl-down = "ScrollPreviewDown" ctrl-up = "ScrollPreviewUp" ctrl-d = "ScrollPreviewHalfPageDown" ctrl-u = "ScrollPreviewHalfPageUp" +enter = "SelectEntry" diff --git a/Cargo.toml b/Cargo.toml index 5d494f6..efe7890 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,3 +68,12 @@ unicode-width = "0.2.0" [build-dependencies] anyhow = "1.0.86" vergen-gix = { version = "1.0.0", features = ["build", "cargo"] } + +[profile.release] +opt-level = 3 +debug = "none" +strip = "symbols" +debug-assertions = false +overflow-checks = false +lto = "fat" +panic = "abort" diff --git a/src/action.rs b/src/action.rs index 3827d71..ded6fe9 100644 --- a/src/action.rs +++ b/src/action.rs @@ -16,6 +16,7 @@ pub enum Action { Resize(u16, u16), ClearScreen, // results actions + SelectEntry, SelectNextEntry, SelectPrevEntry, // navigation actions diff --git a/src/app.rs b/src/app.rs index 4f39775..bc5f856 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,3 +1,4 @@ +/// NOTE: outdated /// /// The general idea /// ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ @@ -57,7 +58,7 @@ use tracing::{debug, info}; use crate::{ action::Action, cli::UnitTvChannel, - components::{television::Television, Component}, + components::{television::Television, Component, Entry}, config::Config, event::{Event, EventLoop, Key}, render::{render, RenderingTask}, @@ -114,7 +115,7 @@ impl App { }) } - pub async fn run(&mut self) -> Result<()> { + pub async fn run(&mut self) -> Result> { let mut tui = Tui::new()?.frame_rate(self.frame_rate); // Rendering loop @@ -146,15 +147,14 @@ impl App { action_tx.send(action)?; } - self.handle_actions().await?; + let maybe_selected = self.handle_actions().await?; if self.should_quit { // send a termination signal to the event loop self.event_abort_tx.send(())?; - break; + return Ok(maybe_selected); } } - Ok(()) } async fn convert_event_to_action(&self, event: Event) -> Action { @@ -196,7 +196,7 @@ impl App { } } - async fn handle_actions(&mut self) -> Result<()> { + async fn handle_actions(&mut self) -> Result> { while let Ok(action) = self.action_rx.try_recv() { if action != Action::Tick && action != Action::Render { debug!("{action:?}"); @@ -215,6 +215,11 @@ impl App { self.should_suspend = false; self.render_tx.send(RenderingTask::Resume)? } + Action::SelectEntry => { + self.should_quit = true; + self.render_tx.send(RenderingTask::Quit)?; + return Ok(self.television.lock().await.get_selected_entry()); + } Action::ClearScreen => self.render_tx.send(RenderingTask::ClearScreen)?, Action::Resize(w, h) => self.render_tx.send(RenderingTask::Resize(w, h))?, Action::Render => self.render_tx.send(RenderingTask::Render)?, @@ -224,6 +229,6 @@ impl App { self.action_tx.send(action)? }; } - Ok(()) + Ok(None) } } diff --git a/src/components.rs b/src/components.rs index 5ddce9b..7ef715e 100644 --- a/src/components.rs +++ b/src/components.rs @@ -15,6 +15,8 @@ mod previewers; pub mod television; mod utils; +pub use finders::Entry; + /// `Component` is a trait that represents a visual and interactive element of the user interface. /// /// Implementors of this trait can be registered with the main application loop and will be able to diff --git a/src/components/finders/env.rs b/src/components/finders/env.rs index 562eb67..989c7c2 100644 --- a/src/components/finders/env.rs +++ b/src/components/finders/env.rs @@ -113,7 +113,6 @@ impl Finder for EnvVarFinder { value_indices.sort_unstable(); value_indices.dedup(); should_add_value_indices = !value_indices.is_empty(); - info!("value_indices: {:?}", value_indices); let value_indices = value_indices.drain(..); Entry { diff --git a/src/components/television.rs b/src/components/television.rs index 285f833..0a7d652 100644 --- a/src/components/television.rs +++ b/src/components/television.rs @@ -88,7 +88,7 @@ impl Television { self.channel.find(pattern); } - fn get_selected_entry(&self) -> Option { + pub fn get_selected_entry(&self) -> Option { self.picker_state .selected() .and_then(|i| self.channel.get_result(i as u32)) diff --git a/src/components/utils/files.rs b/src/components/utils/files.rs index 5348b7c..72c0a02 100644 --- a/src/components/utils/files.rs +++ b/src/components/utils/files.rs @@ -19,8 +19,6 @@ pub fn walk_builder(path: &Path, n_threads: usize) -> WalkBuilder { types_builder.add_defaults(); builder.types(types_builder.build().unwrap()); - builder.hidden(false); - builder.threads(n_threads); builder } diff --git a/src/main.rs b/src/main.rs index 59a4f5a..5e14161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use clap::Parser; use cli::Cli; use color_eyre::Result; +use tracing::info; use crate::app::App; @@ -22,6 +23,8 @@ async fn main() -> Result<()> { let args = Cli::parse(); let mut app = App::new(args.channel, args.tick_rate, args.frame_rate).await?; - app.run().await?; + if let Some(entry) = app.run().await? { + info!("{}", entry.name); + } Ok(()) }