diff --git a/Cargo.lock b/Cargo.lock index a149e04d..1dd6e759 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,7 +663,7 @@ dependencies = [ [[package]] name = "hl" -version = "0.10.6" +version = "0.10.7" dependencies = [ "ansi_term", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 4f0ce9ae..e4791bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["command-line-utilities"] description = "Utility for viewing json-formatted log files." keywords = ["cli", "human", "log"] name = "hl" -version = "0.10.6" +version = "0.10.7" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/formatting.rs b/src/formatting.rs index fa99ff64..380a02fd 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -158,11 +158,11 @@ impl RecordFormatter { }); }); }; - // - // eol - // - s.batch(|buf| buf.push(b'\n')); }); + // + // eol + // + buf.push(b'\n') } fn format_field>( diff --git a/src/output.rs b/src/output.rs index ece2bb98..7863636b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -4,7 +4,7 @@ use std::io::Write; #[cfg(unix)] use std::os::unix::process::ExitStatusExt; use std::path::PathBuf; -use std::process::{Child, Command, Stdio}; +use std::process::{Child, Command, ExitStatus, Stdio}; use crate::error::*; @@ -40,21 +40,28 @@ impl Pager { Ok(Self { process }) } + + #[cfg(unix)] + fn recover(status: ExitStatus) { + if let Some(signal) = status.signal() { + if signal == 9 { + eprintln!("\x1bm\nhl: pager killed"); + if atty::is(atty::Stream::Stdin) { + Command::new("stty").arg("echo").status().ok(); + } + } + } + } + + #[cfg(not(unix))] + #[allow(unused_variables)] + fn recover(status: ExitStatus) {} } impl Drop for Pager { fn drop(&mut self) { - let status = self.process.wait().ok(); - #[cfg(unix)] - if let Some(status) = status { - if let Some(signal) = status.signal() { - if signal == 9 { - eprintln!("\x1bm\nhl: pager killed"); - if atty::is(atty::Stream::Stdin) { - Command::new("stty").arg("echo").status().ok(); - } - } - } + if let Some(status) = self.process.wait().ok() { + Self::recover(status); } } } diff --git a/src/theme.rs b/src/theme.rs index 86d0b385..a1112534 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -69,6 +69,7 @@ impl Theme { current: None, }; f(&mut styler); + styler.reset() } } @@ -193,6 +194,12 @@ pub struct Styler<'a, B: Push> { } impl<'a, B: Push> Styler<'a, B> { + fn reset(&mut self) { + if let Some(style) = self.pack.reset { + self.pack.styles[style].apply(self.buf) + } + } + #[inline(always)] fn set(&mut self, e: Element) -> Option { self.set_style(self.pack.elements[e]) @@ -257,6 +264,11 @@ impl StylePack { fn load(s: &themecfg::StylePack) -> Self { let mut result = Self::default(); + let items = s.items(); + if items.len() != 0 { + result.styles.push(Style::reset()); + result.reset = Some(0); + } for (&element, style) in s.items() { result.add(element, &Style::from(style)) }