From 5d3b50d552288686bbae0e138dc2b0aebea29625 Mon Sep 17 00:00:00 2001 From: Abraham Toriz Date: Mon, 28 Jun 2021 23:40:41 -0500 Subject: [PATCH] get the actual terminal width --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/commands/display.rs | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 181f0b1..aa917d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,6 +415,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -467,6 +477,7 @@ dependencies = [ "rusqlite", "serde", "serde_yaml", + "terminal_size", "textwrap 0.14.2", "thiserror", "toml", diff --git a/Cargo.toml b/Cargo.toml index c2ef8f3..17225c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ serde_yaml = "0.8" toml = "0.5" itertools = "0.10" textwrap = "0.14" +terminal_size = "0.1" [dev-dependencies] pretty_assertions = "0.7.2" diff --git a/src/commands/display.rs b/src/commands/display.rs index 48ac3d5..3a2adf5 100644 --- a/src/commands/display.rs +++ b/src/commands/display.rs @@ -4,6 +4,7 @@ use std::str::FromStr; use clap::ArgMatches; use chrono::{DateTime, Utc, Local, TimeZone}; +use terminal_size::{Width, terminal_size}; use crate::error; use crate::database::Database; @@ -12,6 +13,14 @@ use crate::config::Config; use super::Command; +fn term_width() -> usize { + if let Some((Width(w), _)) = terminal_size() { + w as usize + } else { + 80 + } +} + enum Sheet { All, Full, @@ -76,6 +85,13 @@ impl<'a> Command<'a> for DisplayCommand { } }; - args.format.print_formatted(sheets_to_display, out, Utc::now(), Local.offset_from_utc_datetime(&Utc::now().naive_utc()), args.ids, 100) + args.format.print_formatted( + sheets_to_display, + out, + Utc::now(), + Local.offset_from_utc_datetime(&Utc::now().naive_utc()), + args.ids, + term_width(), + ) } }