aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-11-07 00:22:22 +0100
committerChristian Duerr <contact@christianduerr.com>2018-11-10 18:08:54 +0100
commit26746b4421bee93ebbed9d63d468e8105ede3f06 (patch)
tree80f7497e2e5ba729fecc8937cb1fe1da6c100d25
parent5bd9b76b480a0c54f0e6d2a5312dd2b0d68fe5ad (diff)
downloadalacritty-26746b4421bee93ebbed9d63d468e8105ede3f06.tar.gz
alacritty-26746b4421bee93ebbed9d63d468e8105ede3f06.zip
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.
-rw-r--r--Cargo.lock14
-rw-r--r--src/display.rs31
-rw-r--r--src/logging.rs48
-rw-r--r--src/macros.rs10
-rw-r--r--src/renderer/mod.rs14
-rw-r--r--src/term/mod.rs5
6 files changed, 93 insertions, 29 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b1aadb3c..1c48899d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2123,6 +2123,19 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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"
diff --git a/src/display.rs b/src/display.rs
index 6ab622f2..b185b6be 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;
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);
+ });
}
}
diff --git a/src/logging.rs b/src/logging.rs
index 3fb768e9..6b43c2a7 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -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)))
- }
-}
diff --git a/src/macros.rs b/src/macros.rs
index f3327083..519f8b6a 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -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,
- }
- }
-}
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index df219cf5..8c013e48 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -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
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 39213ee2..8663a073 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -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 => {