Skip to content

Commit

Permalink
Remove truncation when termsize does not report width
Browse files Browse the repository at this point in the history
This is an issue for terminals that report their width asynchronously.
If zeitfetch is started before the terminal has reported its width, we
should not truncate instead of falling back to a default size.
  • Loading branch information
triarius committed Jan 24, 2024
1 parent 8d3a9a9 commit b2a9999
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ASCII_LOGO: &str = r"
";
pub struct Ctx {
pub args: Args,
pub width: usize,
pub width: Option<usize>,
}

#[derive(Debug, Default)]
Expand All @@ -24,7 +24,7 @@ pub struct Args {
impl Ctx {
pub fn new() -> Self {
let args = Args::parse_args();
let width = termsize::get().map(|w| w.cols).unwrap_or(80).into();
let width = termsize::get().map(|w| w.cols.into());
Ctx { width, args }
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ fn generate_info(ctx: &cli::Ctx) -> Result<(), Box<dyn std::error::Error>> {

str::from_utf8(&buf)?
.lines()
.map(|s| ansi::truncate(s, ctx.width))
.for_each(|s| println!("{}", s));
.map(|s| match ctx.width {
Some(width) => ansi::truncate(s, width),
None => s.to_owned(),
})
.for_each(|s| println!("{s}"));

Ok(())
}
Expand Down

0 comments on commit b2a9999

Please sign in to comment.