diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.rs | 9 | ||||
-rw-r--r-- | src/config.rs | 10 | ||||
-rw-r--r-- | src/display.rs | 8 | ||||
-rw-r--r-- | src/logging.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 12 |
5 files changed, 47 insertions, 9 deletions
@@ -31,6 +31,7 @@ pub struct Options { pub command: Option<Shell<'static>>, pub working_dir: Option<PathBuf>, pub config: Option<PathBuf>, + pub persistent_logging: bool, } impl Default for Options { @@ -46,6 +47,7 @@ impl Default for Options { command: None, working_dir: None, config: None, + persistent_logging: false, } } } @@ -71,6 +73,9 @@ impl Options { .conflicts_with("live-config-reload")) .arg(Arg::with_name("print-events") .long("print-events")) + .arg(Arg::with_name("persistent-logging") + .long("persistent-logging") + .help("Keep the log file after quitting Alacritty")) .arg(Arg::with_name("dimensions") .long("dimensions") .short("d") @@ -129,6 +134,10 @@ impl Options { options.live_config_reload = Some(false); } + if matches.is_present("persistent-logging") { + options.persistent_logging = true; + } + if let Some(mut dimensions) = matches.values_of("dimensions") { let width = dimensions.next().map(|w| w.parse().map(Column)); let height = dimensions.next().map(|h| h.parse().map(Line)); diff --git a/src/config.rs b/src/config.rs index 1837cdf1..8e680ebe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -494,6 +494,10 @@ pub struct Config { #[serde(default, deserialize_with="failure_default")] cursor: Cursor, + /// Keep the log file after quitting + #[serde(default, deserialize_with="failure_default")] + persistent_logging: bool, + // TODO: DEPRECATED #[serde(default, deserialize_with = "failure_default")] custom_cursor_colors: Option<bool>, @@ -1662,6 +1666,12 @@ impl Config { self.scrolling.history = history; } + /// Keep the log file after quitting Alacritty + #[inline] + pub fn persistent_logging(&self) -> bool { + self.persistent_logging + } + pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> { let path = path.into(); let raw = Config::read_file(path.as_path())?; diff --git a/src/display.rs b/src/display.rs index b1e9bce2..3e077750 100644 --- a/src/display.rs +++ b/src/display.rs @@ -411,8 +411,8 @@ impl Display { // Display errors and warnings if self.logger_proxy.errors() { let msg = match self.logger_proxy.log_path() { - Some(path) => format!(" ERROR: Full log at {} ", path), - None => " ERROR: Full log in stderr ".into(), + Some(path) => format!(" ERROR! See log at {} ", path), + None => " ERROR! See log in stderr ".into(), }; let color = Rgb { r: 0xff, @@ -424,8 +424,8 @@ impl Display { }); } else if self.logger_proxy.warnings() { let msg = match self.logger_proxy.log_path() { - Some(path) => format!(" WARNING: Full log at {} ", path), - None => " WARNING: Full log in stderr ".into(), + Some(path) => format!(" WARNING! See log at {} ", path), + None => " WARNING! See log in stderr ".into(), }; let color = Rgb { r: 0xff, diff --git a/src/logging.rs b/src/logging.rs index bca8a7f0..66cd8ddd 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -22,7 +22,7 @@ use log::{self, Level}; use time; use std::env; -use std::fs::{File, OpenOptions}; +use std::fs::{self, File, OpenOptions}; use std::io::{self, LineWriter, Stdout, Write}; use std::path::PathBuf; use std::process; @@ -78,6 +78,10 @@ impl LoggerProxy { self.errors.store(false, Ordering::Relaxed); self.warnings.store(false, Ordering::Relaxed); } + + pub fn delete_log(&mut self) { + self.logfile_proxy.delete_log(); + } } struct Logger { @@ -154,6 +158,17 @@ struct OnDemandLogFileProxy { path: String, } +impl OnDemandLogFileProxy { + fn delete_log(&mut self) { + if self.created.load(Ordering::Relaxed) { + if fs::remove_file(&self.path).is_ok() { + let _ = writeln!(io::stdout(), "Deleted log file at {:?}", self.path); + self.created.store(false, Ordering::Relaxed); + } + } + } +} + struct OnDemandLogFile { file: Option<LineWriter<File>>, created: Arc<AtomicBool>, diff --git a/src/main.rs b/src/main.rs index 8035deb9..3f2f5615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,8 +85,6 @@ fn main() { if let Err(err) = run(config, &options, logger_proxy) { die!("Alacritty encountered an unrecoverable error:\n\n\t{}\n", Red(err)); } - - info!("Goodbye."); } /// Load configuration @@ -115,7 +113,7 @@ fn load_config(options: &cli::Options) -> Config { fn run( mut config: Config, options: &cli::Options, - logger_proxy: LoggerProxy, + mut logger_proxy: LoggerProxy, ) -> Result<(), Box<Error>> { info!("Welcome to Alacritty."); if let Some(config_path) = config.path() { @@ -138,7 +136,7 @@ fn run( // This object contains all of the state about what's being displayed. It's // wrapped in a clonable mutex since both the I/O loop and display need to // access it. - let terminal = Term::new(&config, display.size().to_owned(), Some(logger_proxy)); + let terminal = Term::new(&config, display.size().to_owned(), Some(logger_proxy.clone())); let terminal = Arc::new(FairMutex::new(terminal)); // Find the window ID for setting $WINDOWID @@ -261,5 +259,11 @@ fn run( #[cfg(windows)] unsafe { FreeConsole(); } + info!("Goodbye."); + + if !options.persistent_logging && !config.persistent_logging() { + logger_proxy.delete_log(); + } + Ok(()) } |