diff --git a/crates/hyfetch/src/bin/hyfetch.rs b/crates/hyfetch/src/bin/hyfetch.rs index 70d9c939..028bdea4 100644 --- a/crates/hyfetch/src/bin/hyfetch.rs +++ b/crates/hyfetch/src/bin/hyfetch.rs @@ -46,7 +46,7 @@ use tracing::debug; fn main() -> Result<()> { add_pkg_path().expect("failed to add pkg path"); - + #[cfg(windows)] if let Err(err) = enable_ansi_support::enable_ansi_support() { debug!(%err, "could not enable ANSI escape code support"); @@ -590,7 +590,7 @@ fn create_config( let end = (start + flags_per_page).min(filtered_indices.len()); let mut visible_rows: usize = 0; if start >= end { - println!("No presets matched this filter.\n"); + println!("No presets matched this filter."); } else { for row in filtered_indices[start..end].chunks(usize::from(flags_per_row)) { let row = row @@ -610,7 +610,7 @@ fn create_config( } println!( - "Use arrow keys to go to the previous/next page. Type to filter and press Enter to select." + "Use the up/down arrow keys to go to the previous/next page. Type to filter and press Enter to select." ); printc( format!( @@ -670,10 +670,10 @@ fn create_config( preset = selection.unwrap_or(Preset::Rainbow); break; }, - KeyCode::Left | KeyCode::Up => { - page = (page + num_pages - 1) % num_pages; + KeyCode::Up => { + page = (page + num_pages - 1) % num_pages; }, - KeyCode::Right | KeyCode::Down => { + KeyCode::Down => { page = (page + 1) % num_pages; }, KeyCode::Backspace => { @@ -887,26 +887,26 @@ fn create_config( } else { detected_dst.unwrap() }; - + let running_dst_sml = if Distro::detect(&detected_dst_small_fmt).is_some() { detected_dst_small_fmt } else { "".to_string() }; - + // load ascii let small_asc = get_distro_ascii(Some(&running_dst_sml), backend).context("failed to get distro ascii")?; let small_asc = small_asc.to_normalized().context("failed to normalize ascii")?; - + let mut asc = asc; - let mut logo_chosen: Option = distro.cloned(); - - if small_asc.lines != asc.lines && running_dst_sml != "" { + let mut logo_chosen: Option = distro.cloned(); + + if small_asc.lines != asc.lines && running_dst_sml != "" { let ds_arrangements = [ ("Default", asc.clone()), ("Small", small_asc.clone()) - ]; + ]; let arrangements: IndexMap, NormalizedAsciiArt> = ds_arrangements.map(|(k, a)| (k.into(), a)).into(); @@ -943,15 +943,15 @@ fn create_config( // prints small logo w/ big logo for row in &asciis.into_iter().chunks(usize::from(ascii_per_row)) { - + let row: Vec> = row.collect(); - + for i in 0..usize::from(asc.h).checked_add(1).unwrap() { let mut line = Vec::new(); for lines in &row { line.push(&*lines[i]); } - printc(line.join(" "), color_mode).context("failed to print ascii line")?; + printc(line.join(" "), color_mode).context("failed to print ascii line")?; } println!(); @@ -962,7 +962,7 @@ fn create_config( let choice = literal_input("Your choice?", &opts[..], "default", true, color_mode) .context("failed to ask for choice input") .context("failed to select logo type").context("failed to ask for choice input")?; - + if choice.to_lowercase() == "small" { logo_chosen = Some(running_dst_sml); asc = small_asc; @@ -1091,7 +1091,7 @@ fn create_config( // Save choice color_align = if choice == "horizontal" { ColorAlignment::Horizontal } else if choice == "vertical" { ColorAlignment::Vertical } - else { + else { arrangements.into_iter() .find_map(|(k, ca)| { if k.to_lowercase() == choice { diff --git a/hyfetch/main.py b/hyfetch/main.py index a5862f1a..95dc56fa 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -151,38 +151,6 @@ def create_config() -> Config: matched.sort() return [idx for _, _, idx in matched] - def print_flag_page(filtered_indices: list[int], page_num: int, text_filter: str, hint: str | None): - num_pages = max(1, ceil(len(filtered_indices) / flags_per_page)) - clear_screen(title) - print_title_prompt("Let's choose a flag!") - printc('Available flag presets:') - print(f'Page: {page_num + 1} of {num_pages}') - print() - - start = page_num * flags_per_page - end = min(start + flags_per_page, len(filtered_indices)) - - if start >= end: - print('No presets matched this filter.') - print() - else: - current = filtered_indices[start:end] - for i in range(0, len(current), flags_per_row): - row = [flag_entries[idx][1] for idx in current[i:i + flags_per_row]] - print_flag_row(row) - print() - - tmp = PRESETS['rainbow'].set_light_dl_def(light_dark).color_text('preset') - print('Use arrow keys to go to the previous/next page. Type to filter and press Enter to select.') - printc(f'Which {tmp} do you want to use? (default: rainbow)') - print(f'> {text_filter}', end='', flush=True) - if hint: - print(f'\n{hint}', end='') - - def print_flag_row(current: list[list[str]]): - [printc(' '.join(line)) for line in zip(*current)] - print() - def select_preset_prompt_toolkit() -> str: from prompt_toolkit import PromptSession from prompt_toolkit.application.current import get_app @@ -199,14 +167,12 @@ def create_config() -> Config: indices = filter_flag_indices(text) return max(1, ceil(len(indices) / flags_per_page)) - @kb.add('left') @kb.add('up') def _prev_page(event): nonlocal page_num page_num = (page_num + current_num_pages() - 1) % current_num_pages() event.app.invalidate() - @kb.add('right') @kb.add('down') def _next_page(event): nonlocal page_num @@ -239,8 +205,7 @@ def create_config() -> Config: visible_row_count = 0 if start >= end: lines.append("No presets matched this filter.") - lines.append("") - visible_row_count = 0 + visible_row_count = 0.2 else: current = filtered_indices[start:end] for i in range(0, len(current), flags_per_row): @@ -251,10 +216,10 @@ def create_config() -> Config: # Keep prompt at a fixed vertical position by padding to a full page height. missing_rows = max(0, row_per_page - visible_row_count) - lines.extend([""] * (missing_rows * 5)) + lines.extend([""] * round(missing_rows * 5)) lines.append( - "Use arrow keys to go to the previous/next page. Type to filter and press Enter to select." + "Use the up/down arrow keys to go to the previous/next page. Type to filter and press Enter to select." ) lines.append(f"Which {prompt_header} do you want to use? (default: rainbow)") return lines