Skip to content

Commit

Permalink
lto and select entry
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpasmantier committed Oct 5, 2024
1 parent 4b2b84d commit 7081186
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions .config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ ctrl-down = "ScrollPreviewDown"
ctrl-up = "ScrollPreviewUp"
ctrl-d = "ScrollPreviewHalfPageDown"
ctrl-u = "ScrollPreviewHalfPageUp"
enter = "SelectEntry"
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum Action {
Resize(u16, u16),
ClearScreen,
// results actions
SelectEntry,
SelectNextEntry,
SelectPrevEntry,
// navigation actions
Expand Down
19 changes: 12 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// NOTE: outdated
///
/// The general idea
/// ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -114,7 +115,7 @@ impl App {
})
}

pub async fn run(&mut self) -> Result<()> {
pub async fn run(&mut self) -> Result<Option<Entry>> {
let mut tui = Tui::new()?.frame_rate(self.frame_rate);

// Rendering loop
Expand Down Expand Up @@ -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<Key>) -> Action {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl App {
}
}

async fn handle_actions(&mut self) -> Result<()> {
async fn handle_actions(&mut self) -> Result<Option<Entry>> {
while let Ok(action) = self.action_rx.try_recv() {
if action != Action::Tick && action != Action::Render {
debug!("{action:?}");
Expand All @@ -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)?,
Expand All @@ -224,6 +229,6 @@ impl App {
self.action_tx.send(action)?
};
}
Ok(())
Ok(None)
}
}
2 changes: 2 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/components/finders/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/television.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Television {
self.channel.find(pattern);
}

fn get_selected_entry(&self) -> Option<Entry> {
pub fn get_selected_entry(&self) -> Option<Entry> {
self.picker_state
.selected()
.and_then(|i| self.channel.get_result(i as u32))
Expand Down
2 changes: 0 additions & 2 deletions src/components/utils/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use cli::Cli;
use color_eyre::Result;
use tracing::info;

use crate::app::App;

Expand All @@ -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(())
}

0 comments on commit 7081186

Please sign in to comment.