diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-11-17 14:39:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-17 14:39:13 +0000 |
commit | 6265ef91d5496461fcd1025b21323982f3e47085 (patch) | |
tree | d8ab17aac3c2833d5bb231a5346504c227a242f1 /src/display.rs | |
parent | ea637cde1c82ad971078671aff087236f3fb0fbd (diff) | |
download | alacritty-6265ef91d5496461fcd1025b21323982f3e47085.tar.gz alacritty-6265ef91d5496461fcd1025b21323982f3e47085.zip |
Display errors and warnings
To make sure that all error and information reporting to the user is
unified, all instances of `print!`, `eprint!`, `println!` and
`eprintln!` have been removed and replaced by logging.
When `RUST_LOG` is not specified, the default Alacritty logger now also
prints to both the stderr and a log file. The log file is only created
when a message is written to it and its name is printed to stdout the
first time it is used.
Whenever a warning or an error has been written to the log file/stderr,
a message is now displayed in Alacritty which points to the log file
where the full error is documented.
The message is cleared whenever the screen is cleared using either the
`clear` command or the `Ctrl+L` key binding.
To make sure that log files created by root don't prevent normal users
from interacting with them, the Alacritty log file is `/tmp/Alacritty-$PID.log`.
Since it's still possible that the log file can't be created, the UI
error/warning message now informs the user if the message was only
written to stderr. The reason why it couldn't be created is then printed
to stderr.
To make sure the deletion of the log file at runtime doesn't create any
issues, the file is re-created if a write is attempted without the file
being present.
To help with debugging Alacritty issues, a timestamp and the error
level are printed in all log messages.
All log messages now follow this format:
[YYYY-MM-DD HH:MM] [LEVEL] Message
Since it's not unusual to spawn a lot of different terminal emulators
without restarting, Alacritty can create a ton of different log files.
To combat this problem, logfiles are removed by default after
Alacritty has been closed. If the user wants to persist the log of a
single session, the `--persistent_logging` option can be used. For
persisting all log files, the `persistent_logging` option can be set in
the configuration file
Diffstat (limited to 'src/display.rs')
-rw-r--r-- | src/display.rs | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/display.rs b/src/display.rs index 1a145185..12842649 100644 --- a/src/display.rs +++ b/src/display.rs @@ -28,6 +28,7 @@ use renderer::{self, GlyphCache, QuadRenderer}; use term::{Term, SizeInfo, RenderableCell}; use sync::FairMutex; use window::{self, Window}; +use logging::LoggerProxy; use Rgb; #[derive(Debug)] @@ -99,6 +100,7 @@ pub struct Display { meter: Meter, font_size: font::Size, size_info: SizeInfo, + logger_proxy: LoggerProxy, } /// Can wakeup the render loop from other threads @@ -129,7 +131,11 @@ impl Display { &self.size_info } - pub fn new(config: &Config, options: &cli::Options) -> Result<Display, Error> { + pub fn new( + config: &Config, + options: &cli::Options, + logger_proxy: LoggerProxy + ) -> Result<Display, Error> { // Extract some properties from config let render_timer = config.render_timer(); @@ -218,6 +224,7 @@ impl Display { meter: Meter::new(), font_size: font::Size::new(0.), size_info, + logger_proxy, }) } @@ -420,10 +427,38 @@ impl Display { g: 0x4e, b: 0x53, }; - self.renderer - .with_api(config, &size_info, visual_bell_intensity, |mut api| { - api.render_string(&timing[..], glyph_cache, color); - }); + self.renderer.with_api(config, &size_info, visual_bell_intensity, |mut api| { + api.render_string(&timing[..], size_info.lines() - 2, glyph_cache, color); + }); + } + + // Display errors and warnings + if self.logger_proxy.errors() { + let msg = match self.logger_proxy.log_path() { + Some(path) => format!(" ERROR! See log at {} ", path), + None => " ERROR! See log in stderr ".into(), + }; + let color = Rgb { + r: 0xff, + g: 0x00, + b: 0x00, + }; + self.renderer.with_api(config, &size_info, visual_bell_intensity, |mut api| { + api.render_string(&msg, size_info.lines() - 1, glyph_cache, color); + }); + } else if self.logger_proxy.warnings() { + let msg = match self.logger_proxy.log_path() { + Some(path) => format!(" WARNING! See log at {} ", path), + None => " WARNING! See log in stderr ".into(), + }; + let color = Rgb { + r: 0xff, + g: 0xff, + b: 0x00, + }; + self.renderer.with_api(config, &size_info, visual_bell_intensity, |mut api| { + api.render_string(&msg, size_info.lines() - 1, glyph_cache, color); + }); } } |