aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-05-23 22:28:06 -0400
committerJesse Luehrs <doy@tozt.net>2020-05-23 22:28:06 -0400
commitae16ddeb2adc33b1ec23abfae29a553c920d8af4 (patch)
treeb7d165e0205ef421c9affc91c352223fbb9c8441
parent71723e6b35876f0511638cd4473634f9716a6bea (diff)
downloadrbw-ae16ddeb2adc33b1ec23abfae29a553c920d8af4.tar.gz
rbw-ae16ddeb2adc33b1ec23abfae29a553c920d8af4.zip
wrap log lines when necessary
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/rbw/main.rs7
3 files changed, 10 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2ea6e96..21ba51e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1144,6 +1144,8 @@ dependencies = [
"snafu",
"structopt",
"tempfile",
+ "term_size",
+ "textwrap",
"tokio",
"uuid",
"zeroize",
diff --git a/Cargo.toml b/Cargo.toml
index 97fb3b2..b5184fd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,6 +38,8 @@ serde_path_to_error = "0.1"
snafu = "0.6"
structopt = { version = "0.3", features = ["paw", "wrap_help"] }
tempfile = "3.1"
+term_size = "0.3"
+textwrap = "0.11"
tokio = { version = "0.2", features = ["full"] }
uuid = { version = "0.8", features = ["v4"] }
zeroize = "1.1"
diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs
index 9160ded..50edd6f 100644
--- a/src/bin/rbw/main.rs
+++ b/src/bin/rbw/main.rs
@@ -239,7 +239,12 @@ fn main(opt: Opt) {
env_logger::Env::default().default_filter_or("info"),
)
.format(|buf, record| {
- writeln!(buf, "{}: {}", record.level(), record.args())
+ if let Some((w, _)) = term_size::dimensions() {
+ let out = format!("{}: {}", record.level(), record.args());
+ writeln!(buf, "{}", textwrap::fill(&out, w - 1))
+ } else {
+ writeln!(buf, "{}: {}", record.level(), record.args())
+ }
})
.init();