formatting

This commit is contained in:
alexpasmantier 2024-10-27 23:31:40 +01:00
parent 8223e073a0
commit ddedbc11da
18 changed files with 86 additions and 68 deletions

View File

@ -52,7 +52,6 @@
*/
use std::sync::Arc;
use color_eyre::Result;
use tokio::sync::{mpsc, Mutex};
use tracing::{debug, info};

View File

@ -51,10 +51,7 @@ fn get_raw_aliases(shell: &str) -> Vec<String> {
.output()
.expect("failed to execute process");
let aliases = String::from_utf8(output.stdout).unwrap();
aliases
.lines()
.map(ToString::to_string)
.collect()
aliases.lines().map(ToString::to_string).collect()
}
"zsh" => {
let output = std::process::Command::new("zsh")
@ -64,10 +61,7 @@ fn get_raw_aliases(shell: &str) -> Vec<String> {
.output()
.expect("failed to execute process");
let aliases = String::from_utf8(output.stdout).unwrap();
aliases
.lines()
.map(ToString::to_string)
.collect()
aliases.lines().map(ToString::to_string).collect()
}
// TODO: add more shells
_ => Vec::new(),

View File

@ -40,9 +40,15 @@ impl Channel {
);
let injector = matcher.injector();
for (name, value) in std::env::vars() {
let _ = injector.push(EnvVar { name: preprocess_line(&name), value: preprocess_line(&value) }, |e, cols| {
let _ = injector.push(
EnvVar {
name: preprocess_line(&name),
value: preprocess_line(&value),
},
|e, cols| {
cols[0] = (e.name.clone() + &e.value).into();
});
},
);
}
Channel {
matcher,

View File

@ -165,7 +165,13 @@ async fn load_files(paths: Vec<PathBuf>, injector: Injector<String>) {
Box::new(move |result| {
if let Ok(entry) = result {
if entry.file_type().unwrap().is_file() {
let file_path = preprocess_line(&*entry.path().strip_prefix(&current_dir).unwrap().to_string_lossy());
let file_path = preprocess_line(
&*entry
.path()
.strip_prefix(&current_dir)
.unwrap()
.to_string_lossy(),
);
let _ = injector.push(file_path, |e, cols| {
cols[0] = e.clone().into();
});

View File

@ -206,11 +206,9 @@ async fn crawl_for_repos(
if entry.file_type().unwrap().is_dir() {
// if the entry is a .git directory, add its parent to the list of git repos
if entry.path().ends_with(".git") {
let parent_path = preprocess_line(&*entry
.path()
.parent()
.unwrap()
.to_string_lossy());
let parent_path = preprocess_line(
&*entry.path().parent().unwrap().to_string_lossy(),
);
debug!("Found git repo: {:?}", parent_path);
let _ = injector.push(parent_path, |e, cols| {
cols[0] = e.clone().into();

View File

@ -153,8 +153,7 @@ impl EventLoop {
pub fn new(tick_rate: f64, init: bool) -> Self {
let (tx, rx) = mpsc::unbounded_channel();
let tx_c = tx.clone();
let tick_interval =
Duration::from_secs_f64(1.0 / tick_rate);
let tick_interval = Duration::from_secs_f64(1.0 / tick_rate);
let (abort, mut abort_recv) = mpsc::unbounded_channel();

View File

@ -164,10 +164,11 @@ impl FilePreviewer {
"Computing highlights in the background for {:?}",
entry_c.name
);
let lines: Vec<String> =
reader.lines().map_while(Result::ok).map(
|line| preprocess_line(&line),
).collect();
let lines: Vec<String> = reader
.lines()
.map_while(Result::ok)
.map(|line| preprocess_line(&line))
.collect();
match syntax::compute_highlights_for_path(
&PathBuf::from(&entry_c.name),

View File

@ -377,8 +377,9 @@ impl Television {
// bottom left block: input
self.draw_input_box(f, &layout)?;
let selected_entry =
self.get_selected_entry(Some(Mode::Channel)).unwrap_or(ENTRY_PLACEHOLDER);
let selected_entry = self
.get_selected_entry(Some(Mode::Channel))
.unwrap_or(ENTRY_PLACEHOLDER);
let preview = block_on(self.previewer.preview(&selected_entry));
// top right block: preview title

View File

@ -6,11 +6,11 @@ pub mod keymap;
pub mod layout;
pub mod logo;
pub mod metadata;
mod mode;
pub mod preview;
mod remote_control;
pub mod results;
pub mod spinner;
mod mode;
// input
//const DEFAULT_INPUT_FG: Color = Color::Rgb(200, 200, 200);
//const DEFAULT_RESULTS_COUNT_FG: Color = Color::Rgb(150, 150, 150);

View File

@ -80,8 +80,11 @@ impl Television {
// MISC line (quit, help, etc.)
// Quit ⏼
let quit_keys = keys_for_action(keymap, &Action::Quit);
let quit_row =
Row::new(build_cells_for_key_groups("⏼ Quit", vec![quit_keys], key_color));
let quit_row = Row::new(build_cells_for_key_groups(
"⏼ Quit",
vec![quit_keys],
key_color,
));
let widths = vec![Constraint::Fill(1), Constraint::Fill(2)];
@ -132,8 +135,11 @@ impl Television {
// Quit
let quit_keys = keys_for_action(keymap, &Action::Quit);
let quit_row =
Row::new(build_cells_for_key_groups("⏼ Quit", vec![quit_keys], key_color));
let quit_row = Row::new(build_cells_for_key_groups(
"⏼ Quit",
vec![quit_keys],
key_color,
));
Ok(Table::new(
vec![results_row, select_entry_row, switch_channels_row, quit_row],
@ -185,8 +191,7 @@ fn build_cells_for_key_groups(
key_groups: Vec<Vec<String>>,
key_color: Color,
) -> Vec<Cell> {
if key_groups.is_empty() || key_groups.iter().all(Vec::is_empty)
{
if key_groups.is_empty() || key_groups.iter().all(Vec::is_empty) {
return vec![group_name.into(), "No keybindings".into()];
}
let non_empty_groups = key_groups.iter().filter(|keys| !keys.is_empty());

View File

@ -8,7 +8,6 @@ use ratatui::{
use crate::television::Television;
use crate::ui::mode::mode_color;
const METADATA_FIELD_NAME_COLOR: Color = Color::DarkGray;
const METADATA_FIELD_VALUE_COLOR: Color = Color::Gray;

View File

@ -5,7 +5,6 @@ const CHANNEL_COLOR: Color = Color::LightYellow;
const REMOTE_CONTROL_COLOR: Color = Color::LightMagenta;
const SEND_TO_CHANNEL_COLOR: Color = Color::LightCyan;
pub fn mode_color(mode: Mode) -> Color {
match mode {
Mode::Channel => CHANNEL_COLOR,

View File

@ -56,8 +56,15 @@ impl Television {
u32::try_from(self.rc_picker.view_offset)?,
);
let channel_list =
build_results_list(rc_block, &entries, ListDirection::TopToBottom, Some(ResultsListColors::default().result_name_fg(mode_color(self.mode))));
let channel_list = build_results_list(
rc_block,
&entries,
ListDirection::TopToBottom,
Some(
ResultsListColors::default()
.result_name_fg(mode_color(self.mode)),
),
);
f.render_stateful_widget(
channel_list,
@ -134,8 +141,7 @@ impl Television {
}
fn draw_rc_logo(f: &mut Frame, area: Rect, color: Color) {
let logo_block = Block::default()
.style(Style::default().fg(color));
let logo_block = Block::default().style(Style::default().fg(color));
let logo_paragraph = build_remote_logo_paragraph()
.alignment(Alignment::Center)

View File

@ -134,7 +134,8 @@ where
last_match_end,
start,
),
Style::default().fg(results_list_colors.result_preview_fg),
Style::default()
.fg(results_list_colors.result_preview_fg),
));
spans.push(Span::styled(
slice_at_char_boundaries(preview, start, end),
@ -147,7 +148,8 @@ where
preview,
preview_match_ranges.last().unwrap().1 as usize,
)..],
Style::default().fg(results_list_colors.result_preview_fg),
Style::default()
.fg(results_list_colors.result_preview_fg),
));
}
} else {
@ -160,7 +162,9 @@ where
Line::from(spans)
}))
.direction(list_direction)
.highlight_style(Style::default().bg(results_list_colors.result_selected_bg))
.highlight_style(
Style::default().bg(results_list_colors.result_selected_bg),
)
.highlight_symbol("> ")
.block(results_block)
}

View File

@ -175,8 +175,7 @@ mod tests {
test_replace_nonprintable("Hello\tWorld!", "Hello World!");
test_replace_nonprintable(
" -- AND
",
" -- AND",
", " -- AND",
)
}

View File

@ -36,7 +36,9 @@ pub fn cli_channel_derive(input: TokenStream) -> TokenStream {
}
fn has_exclude_attr(attrs: &[syn::Attribute]) -> bool {
attrs.iter().any(|attr| attr.path().is_ident("exclude_from_cli"))
attrs
.iter()
.any(|attr| attr.path().is_ident("exclude_from_cli"))
}
fn impl_cli_channel(ast: &syn::DeriveInput) -> TokenStream {