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", "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]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.11.0"
@ -467,6 +477,7 @@ dependencies = [
"rusqlite", "rusqlite",
"serde", "serde",
"serde_yaml", "serde_yaml",
"terminal_size",
"textwrap 0.14.2", "textwrap 0.14.2",
"thiserror", "thiserror",
"toml", "toml",

View File

@ -17,6 +17,7 @@ serde_yaml = "0.8"
toml = "0.5" toml = "0.5"
itertools = "0.10" itertools = "0.10"
textwrap = "0.14" textwrap = "0.14"
terminal_size = "0.1"
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.7.2" pretty_assertions = "0.7.2"

View File

@ -4,6 +4,7 @@ use std::str::FromStr;
use clap::ArgMatches; use clap::ArgMatches;
use chrono::{DateTime, Utc, Local, TimeZone}; use chrono::{DateTime, Utc, Local, TimeZone};
use terminal_size::{Width, terminal_size};
use crate::error; use crate::error;
use crate::database::Database; use crate::database::Database;
@ -12,6 +13,14 @@ use crate::config::Config;
use super::Command; use super::Command;
fn term_width() -> usize {
if let Some((Width(w), _)) = terminal_size() {
w as usize
} else {
80
}
}
enum Sheet { enum Sheet {
All, All,
Full, 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(),
)
} }
} }