Skip to content

Commit

Permalink
Temporary fix to an issue where ANSI truncates to 0 by default (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
nidnogg authored May 28, 2024
1 parent bf965ba commit 40c71e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zeitfetch"
version = "0.1.10"
version = "0.1.11"
edition = "2021"
authors = ["Henrique V (nidnogg)"]
description = "Instantaneous snapshots of cross-platform system information"
Expand Down
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{env, process::exit};
extern crate termsize;

const ASCII_LOGO: &str = r"
_ _ __ _ _
Expand All @@ -24,7 +25,13 @@ pub struct Args {
impl Ctx {
pub fn new() -> Self {
let args = Args::parse_args();
let width = termsize::get().map(|w| w.cols.into());
let width: Option<usize> =
termsize::get().map(|w| if w.cols == 0 { 80 } else { w.cols.into() });
// TO-DO debug why termsize is unable to set width with cargo build --release. This commented code results in rows 0 cols 0.
// See https://github.com/nidnogg/zeitfetch/issues/14 for more details.
// termsize::get().map(|size| {
// println!("rows {} cols {}", size.rows, size.cols)
// });
Ctx { width, args }
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ fn generate_info(ctx: &cli::Ctx) -> Result<(), Box<dyn std::error::Error>> {
let mut buf = Vec::new();
table.print(&mut buf)?;

// Ansi truncating.
// TO-DO debug why termsize is unable to set width with cargo build --release.
// See https://github.com/nidnogg/zeitfetch/issues/14 for more details.
// println!("{:?}", ctx.width);
str::from_utf8(&buf)?
.lines()
.map(|s| match ctx.width {
Expand Down

0 comments on commit 40c71e8

Please sign in to comment.