get the actual terminal width

This commit is contained in:
Abraham Toriz 2021-06-28 23:40:41 -05:00
parent e59211f1f9
commit 5d3b50d552
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
3 changed files with 29 additions and 1 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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(),
)
}
}