mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 12:05:34 +00:00
fixing various issues
This commit is contained in:
parent
f5cba5b33c
commit
e6c59658ae
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2673,7 +2673,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "television"
|
name = "television"
|
||||||
version = "0.1.7"
|
version = "0.1.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"better-panic",
|
"better-panic",
|
||||||
|
@ -42,30 +42,14 @@ fn get_current_shell() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_raw_aliases(shell: &str) -> Vec<String> {
|
fn get_raw_aliases(shell: &str) -> Vec<String> {
|
||||||
match shell {
|
let output = std::process::Command::new(shell)
|
||||||
"bash" => {
|
.arg("-i")
|
||||||
let output = std::process::Command::new("bash")
|
.arg("-c")
|
||||||
.arg("-i")
|
.arg("alias")
|
||||||
.arg("-c")
|
.output()
|
||||||
.arg("alias")
|
.expect("failed to execute process");
|
||||||
.output()
|
let aliases = String::from_utf8(output.stdout).unwrap();
|
||||||
.expect("failed to execute process");
|
aliases.lines().map(ToString::to_string).collect()
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
@ -128,7 +112,7 @@ impl OnAir for Channel {
|
|||||||
.matched_items(
|
.matched_items(
|
||||||
offset
|
offset
|
||||||
..(num_entries + offset)
|
..(num_entries + offset)
|
||||||
.min(snapshot.matched_item_count()),
|
.min(snapshot.matched_item_count()),
|
||||||
)
|
)
|
||||||
.map(move |item| {
|
.map(move |item| {
|
||||||
snapshot.pattern().column_pattern(0).indices(
|
snapshot.pattern().column_pattern(0).indices(
|
||||||
|
@ -85,9 +85,9 @@ impl Picker {
|
|||||||
self.view_offset = self.view_offset.saturating_sub(1);
|
self.view_offset = self.view_offset.saturating_sub(1);
|
||||||
}
|
}
|
||||||
} else {
|
} 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.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));
|
self.relative_select(Some(0));
|
||||||
return;
|
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.view_offset += 1;
|
||||||
self.relative_select(Some(
|
self.relative_select(Some(
|
||||||
self.selected().unwrap_or(0).min(height - 3),
|
self.selected().unwrap_or(0).min(height.saturating_sub(3)),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
self.relative_select(Some(
|
self.relative_select(Some(
|
||||||
|
@ -426,6 +426,9 @@ impl Television {
|
|||||||
.style(Style::default());
|
.style(Style::default());
|
||||||
|
|
||||||
let input_block_inner = input_block.inner(layout.input);
|
let input_block_inner = input_block.inner(layout.input);
|
||||||
|
if input_block_inner.area() == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
f.render_widget(input_block, layout.input);
|
f.render_widget(input_block, layout.input);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ impl Layout {
|
|||||||
// split the main block into two vertical chunks (help bar + rest)
|
// split the main block into two vertical chunks (help bar + rest)
|
||||||
let hz_chunks = layout::Layout::default()
|
let hz_chunks = layout::Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Length(9), Constraint::Fill(1)])
|
.constraints([Constraint::Max(9), Constraint::Fill(1)])
|
||||||
.split(main_block);
|
.split(main_block);
|
||||||
|
|
||||||
// split the help bar into three horizontal chunks (left + center + right)
|
// split the help bar into three horizontal chunks (left + center + right)
|
||||||
@ -95,13 +95,13 @@ impl Layout {
|
|||||||
// left block: results + input field
|
// left block: results + input field
|
||||||
let left_chunks = layout::Layout::default()
|
let left_chunks = layout::Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Min(10), Constraint::Length(3)])
|
.constraints([Constraint::Min(3), Constraint::Length(3)])
|
||||||
.split(vt_chunks[0]);
|
.split(vt_chunks[0]);
|
||||||
|
|
||||||
// right block: preview title + preview
|
// right block: preview title + preview
|
||||||
let right_chunks = layout::Layout::default()
|
let right_chunks = layout::Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Length(3), Constraint::Min(10)])
|
.constraints([Constraint::Length(3), Constraint::Min(3)])
|
||||||
.split(vt_chunks[1]);
|
.split(vt_chunks[1]);
|
||||||
|
|
||||||
Self::new(
|
Self::new(
|
||||||
@ -145,5 +145,5 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UI size
|
// UI size
|
||||||
const UI_WIDTH_PERCENT: u16 = 90;
|
const UI_WIDTH_PERCENT: u16 = 95;
|
||||||
const UI_HEIGHT_PERCENT: u16 = 90;
|
const UI_HEIGHT_PERCENT: u16 = 95;
|
||||||
|
@ -3,8 +3,8 @@ use crate::previewers::{
|
|||||||
Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG,
|
Preview, PreviewContent, FILE_TOO_LARGE_MSG, PREVIEW_NOT_SUPPORTED_MSG,
|
||||||
};
|
};
|
||||||
use crate::television::Television;
|
use crate::television::Television;
|
||||||
use crate::ui::BORDER_COLOR;
|
|
||||||
use crate::ui::layout::Layout;
|
use crate::ui::layout::Layout;
|
||||||
|
use crate::ui::BORDER_COLOR;
|
||||||
use crate::utils::strings::{shrink_with_ellipsis, EMPTY_STRING};
|
use crate::utils::strings::{shrink_with_ellipsis, EMPTY_STRING};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use ratatui::layout::{Alignment, Rect};
|
use ratatui::layout::{Alignment, Rect};
|
||||||
@ -174,9 +174,9 @@ impl Television {
|
|||||||
self.preview_scroll.unwrap_or(0),
|
self.preview_scroll.unwrap_or(0),
|
||||||
self.preview_pane_height,
|
self.preview_pane_height,
|
||||||
)
|
)
|
||||||
.block(preview_block)
|
.block(preview_block)
|
||||||
.alignment(Alignment::Left)
|
.alignment(Alignment::Left)
|
||||||
.scroll((self.preview_scroll.unwrap_or(0), 0))
|
.scroll((self.preview_scroll.unwrap_or(0), 0))
|
||||||
}
|
}
|
||||||
// meta
|
// meta
|
||||||
PreviewContent::Loading => self
|
PreviewContent::Loading => self
|
||||||
@ -235,6 +235,9 @@ impl Television {
|
|||||||
return paragraph.clone();
|
return paragraph.clone();
|
||||||
}
|
}
|
||||||
let message_len = message.len();
|
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_char_str = fill_char.to_string();
|
||||||
let fill_line = fill_char_str.repeat(inner.width as usize);
|
let fill_line = fill_char_str.repeat(inner.width as usize);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user