fixing various issues

This commit is contained in:
alexpasmantier 2024-10-31 13:15:40 +01:00
parent f5cba5b33c
commit e6c59658ae
6 changed files with 29 additions and 39 deletions

2
Cargo.lock generated
View File

@ -2673,7 +2673,7 @@ dependencies = [
[[package]]
name = "television"
version = "0.1.7"
version = "0.1.8"
dependencies = [
"anyhow",
"better-panic",

View File

@ -42,30 +42,14 @@ fn get_current_shell() -> Option<String> {
}
fn get_raw_aliases(shell: &str) -> Vec<String> {
match shell {
"bash" => {
let output = std::process::Command::new("bash")
.arg("-i")
.arg("-c")
.arg("alias")
.output()
.expect("failed to execute process");
let aliases = String::from_utf8(output.stdout).unwrap();
aliases.lines().map(ToString::to_string).collect()
}
"zsh" => {
let output = std::process::Command::new("zsh")
.arg("-i")
.arg("-c")
.arg("alias")
.output()
.expect("failed to execute process");
let aliases = String::from_utf8(output.stdout).unwrap();
aliases.lines().map(ToString::to_string).collect()
}
// TODO: add more shells
_ => Vec::new(),
}
let output = std::process::Command::new(shell)
.arg("-i")
.arg("-c")
.arg("alias")
.output()
.expect("failed to execute process");
let aliases = String::from_utf8(output.stdout).unwrap();
aliases.lines().map(ToString::to_string).collect()
}
impl Channel {
@ -128,7 +112,7 @@ impl OnAir for Channel {
.matched_items(
offset
..(num_entries + offset)
.min(snapshot.matched_item_count()),
.min(snapshot.matched_item_count()),
)
.map(move |item| {
snapshot.pattern().column_pattern(0).indices(

View File

@ -85,9 +85,9 @@ impl Picker {
self.view_offset = self.view_offset.saturating_sub(1);
}
} else {
self.view_offset = total_items.saturating_sub(height - 2);
self.view_offset = total_items.saturating_sub(height.saturating_sub(2));
self.select(Some(total_items.saturating_sub(1)));
self.relative_select(Some(height - 3));
self.relative_select(Some(height.saturating_sub(3)));
}
}
@ -99,10 +99,10 @@ impl Picker {
self.relative_select(Some(0));
return;
}
if self.relative_selected().unwrap_or(0) == height - 3 {
if self.relative_selected().unwrap_or(0) == height.saturating_sub(3) {
self.view_offset += 1;
self.relative_select(Some(
self.selected().unwrap_or(0).min(height - 3),
self.selected().unwrap_or(0).min(height.saturating_sub(3)),
));
} else {
self.relative_select(Some(

View File

@ -426,6 +426,9 @@ impl Television {
.style(Style::default());
let input_block_inner = input_block.inner(layout.input);
if input_block_inner.area() == 0 {
return Ok(());
}
f.render_widget(input_block, layout.input);

View File

@ -61,7 +61,7 @@ impl Layout {
// split the main block into two vertical chunks (help bar + rest)
let hz_chunks = layout::Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(9), Constraint::Fill(1)])
.constraints([Constraint::Max(9), Constraint::Fill(1)])
.split(main_block);
// split the help bar into three horizontal chunks (left + center + right)
@ -95,13 +95,13 @@ impl Layout {
// left block: results + input field
let left_chunks = layout::Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(10), Constraint::Length(3)])
.constraints([Constraint::Min(3), Constraint::Length(3)])
.split(vt_chunks[0]);
// right block: preview title + preview
let right_chunks = layout::Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Min(10)])
.constraints([Constraint::Length(3), Constraint::Min(3)])
.split(vt_chunks[1]);
Self::new(
@ -145,5 +145,5 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
}
// UI size
const UI_WIDTH_PERCENT: u16 = 90;
const UI_HEIGHT_PERCENT: u16 = 90;
const UI_WIDTH_PERCENT: u16 = 95;
const UI_HEIGHT_PERCENT: u16 = 95;

View File

@ -3,8 +3,8 @@ use crate::previewers::{
Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG,
};
use crate::television::Television;
use crate::ui::BORDER_COLOR;
use crate::ui::layout::Layout;
use crate::ui::BORDER_COLOR;
use crate::utils::strings::{shrink_with_ellipsis, EMPTY_STRING};
use color_eyre::eyre::Result;
use ratatui::layout::{Alignment, Rect};
@ -174,9 +174,9 @@ impl Television {
self.preview_scroll.unwrap_or(0),
self.preview_pane_height,
)
.block(preview_block)
.alignment(Alignment::Left)
.scroll((self.preview_scroll.unwrap_or(0), 0))
.block(preview_block)
.alignment(Alignment::Left)
.scroll((self.preview_scroll.unwrap_or(0), 0))
}
// meta
PreviewContent::Loading => self
@ -235,6 +235,9 @@ impl Television {
return paragraph.clone();
}
let message_len = message.len();
if message_len + 8 > inner.width as usize {
return Paragraph::new(Text::from(EMPTY_STRING));
}
let fill_char_str = fill_char.to_string();
let fill_line = fill_char_str.repeat(inner.width as usize);