1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Add visual error/warning message

Whenever a warning or an error has been written to the log file/stdout,
a message is now displayed in Alacritty which indicates where the error
came from.

The message is cleared whenever the screen is cleared using either the
`clear` command or the `Ctrl+L` key binding.
This commit is contained in:
Christian Duerr 2018-11-07 00:22:22 +01:00
parent 5bd9b76b48
commit 26746b4421
No known key found for this signature in database
GPG key ID: 85CDAE3C164BA7B4
6 changed files with 93 additions and 29 deletions

14
Cargo.lock generated
View file

@ -2122,6 +2122,19 @@ dependencies = [
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempfile"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.0.4"
@ -2996,6 +3009,7 @@ dependencies = [
"checksum syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "55c1195ef8513f3273d55ff59fe5da6940287a0d7a98331254397f464833675b"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
"checksum terminfo 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8e51065bafd2abe106b6036483b69d1741f4a1ec56ce8a2378de341637de689e"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"

View file

@ -28,6 +28,7 @@ use renderer::{self, GlyphCache, QuadRenderer};
use term::{Term, SizeInfo, RenderableCell};
use sync::FairMutex;
use window::{self, Window};
use logging;
use Rgb;
#[derive(Debug)]
@ -396,10 +397,32 @@ 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 logging::errors() {
let msg = " ERROR: Full log at /tmp/alacritty-todo.log ";
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 logging::warnings() {
let msg = " WARNING: Full log at /tmp/alacritty-todo.log ";
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);
});
}
}

View file

@ -18,13 +18,43 @@
//! startup. All logging messages are written to stdout, given that their
//! log-level is sufficient for the level configured in `cli::Options`.
use cli;
use log;
use log::{self, Level};
use tempfile;
use std::fs::File;
use std::io::{self, LineWriter, Stdout, Write};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
static ERRORS: AtomicBool = AtomicBool::new(false);
static WARNINGS: AtomicBool = AtomicBool::new(false);
pub fn initialize(options: &cli::Options) -> Result<(), log::SetLoggerError> {
// Use env_logger if RUST_LOG environment variable is defined. Otherwise,
// use the alacritty-only logger.
if ::std::env::var("RUST_LOG").is_ok() {
::env_logger::try_init()
} else {
log::set_boxed_logger(Box::new(Logger::new(options.log_level)))
}
}
pub fn warnings() -> bool {
WARNINGS.load(Ordering::Relaxed)
}
pub fn errors() -> bool {
ERRORS.load(Ordering::Relaxed)
}
pub fn clear_errors() {
ERRORS.store(false, Ordering::Relaxed);
}
pub fn clear_warnings() {
WARNINGS.store(false, Ordering::Relaxed);
}
pub struct Logger {
level: log::LevelFilter,
logfile: Mutex<OnDemandTempFile>,
@ -63,6 +93,12 @@ impl log::Log for Logger {
if let Ok(ref mut stdout) = self.stdout.lock() {
let _ = stdout.write_all(format!("{}\n", record.args()).as_ref());
}
match record.level() {
Level::Error => ERRORS.store(true, Ordering::Relaxed),
Level::Warn => WARNINGS.store(true, Ordering::Relaxed),
_ => (),
}
}
}
@ -108,13 +144,3 @@ impl Write for OnDemandTempFile {
self.file()?.flush()
}
}
pub fn initialize(options: &cli::Options) -> Result<(), log::SetLoggerError> {
// Use env_logger if RUST_LOG environment variable is defined. Otherwise,
// use the alacritty-only logger.
if ::std::env::var("RUST_LOG").is_ok() {
::env_logger::try_init()
} else {
log::set_boxed_logger(Box::new(Logger::new(options.log_level)))
}
}

View file

@ -19,13 +19,3 @@ macro_rules! die {
::std::process::exit(1);
}}
}
#[macro_export]
macro_rules! maybe {
($option:expr) => {
match $option {
Some(value) => value,
None => return None,
}
}
}

View file

@ -819,10 +819,16 @@ impl<'a> RenderApi<'a> {
self.batch.clear();
}
/// Render a string in a predefined location. Used for printing render time for profiling and
/// optimization.
pub fn render_string(&mut self, string: &str, glyph_cache: &mut GlyphCache, color: Rgb) {
let line = Line(23);
/// Render a string in a variable location. Used for printing the render timer, warnings and
/// errors.
pub fn render_string(
&mut self,
string: &str,
line: Line,
glyph_cache: &mut GlyphCache,
color: Rgb
) {
let col = Column(0);
let cells = string

View file

@ -31,6 +31,7 @@ use config::{Config, VisualBellAnimation};
use {MouseCursor, Rgb};
use copypasta::{Clipboard, Load, Store};
use input::FONT_SIZE_STEP;
use logging;
pub mod cell;
pub mod color;
@ -1822,6 +1823,10 @@ impl ansi::Handler for Term {
}
},
ansi::ClearMode::All => {
// Clear errors and warnings
logging::clear_errors();
logging::clear_warnings();
self.grid.region_mut(..).each(|c| c.reset(&template));
},
ansi::ClearMode::Above => {