summaryrefslogtreecommitdiff
path: root/src/term
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-02-07 22:36:45 +0000
committerGitHub <noreply@github.com>2019-02-07 22:36:45 +0000
commit35efb4619c4b7a77b3c30de763856bc4441e236e (patch)
tree99aa70b58f97bd57c2a654e3177eae0ea0b572fa /src/term
parente561ae373393e919cf3dbbf123a98e0aad215dbc (diff)
downloadalacritty-35efb4619c4b7a77b3c30de763856bc4441e236e.tar.gz
alacritty-35efb4619c4b7a77b3c30de763856bc4441e236e.zip
Dynamically resize terminal for errors/warnings
The warning and error messages now don't overwrite other terminal content anymore but instead resize the terminal to make sure that text can always be read. Instead of just showing that there is a new error and pointing to the log, errors will now be displayed fully in multiple lines of text, assuming that there is enough space left in the terminal. Explicit mouse click handling has also been added to the message bar, which made it possible to add a simple `close` button in the form of `[X]`. Alacritty's log file location is now stored in the `$ALACRITTY_LOG` environment variable which the shell inherits automatically. Previously there were some issues with the log file only being deleted when certain methods for closing Alacritty were used (like typing `exit`). This has been reworked and now Ctrl+D, exit and signals should all work properly. Before the config is reloaded, all current messages are now dropped. This should help with multiple terminals all getting clogged up at the same time when the config is broken. When one message is removed, all other duplicate messages are automatically removed too.
Diffstat (limited to 'src/term')
-rw-r--r--src/term/color.rs31
-rw-r--r--src/term/mod.rs92
2 files changed, 83 insertions, 40 deletions
diff --git a/src/term/color.rs b/src/term/color.rs
index 638cbd76..abd7527a 100644
--- a/src/term/color.rs
+++ b/src/term/color.rs
@@ -1,11 +1,38 @@
-use std::ops::{Index, IndexMut};
+use std::ops::{Index, IndexMut, Mul};
use std::fmt;
-use crate::{Rgb, ansi};
+use crate::ansi;
use crate::config::Colors;
pub const COUNT: usize = 270;
+pub const RED: Rgb = Rgb { r: 0xff, g: 0x0, b: 0x0 };
+pub const YELLOW: Rgb = Rgb { r: 0xff, g: 0xff, b: 0x0 };
+
+#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Serialize, Deserialize)]
+pub struct Rgb {
+ pub r: u8,
+ pub g: u8,
+ pub b: u8,
+}
+
+// a multiply function for Rgb, as the default dim is just *2/3
+impl Mul<f32> for Rgb {
+ type Output = Rgb;
+
+ fn mul(self, rhs: f32) -> Rgb {
+ let result = Rgb {
+ r: (f32::from(self.r) * rhs).max(0.0).min(255.0) as u8,
+ g: (f32::from(self.g) * rhs).max(0.0).min(255.0) as u8,
+ b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8
+ };
+
+ trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result);
+
+ result
+ }
+}
+
/// List of indexed colors
///
/// The first 16 entries are the standard ansi named colors. Items 16..232 are
diff --git a/src/term/mod.rs b/src/term/mod.rs
index c49ecbcc..76ac9c25 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -27,16 +27,17 @@ use crate::grid::{BidirectionalIterator, Grid, Indexed, IndexRegion, DisplayIter
use crate::index::{self, Point, Column, Line, IndexRange, Contains, RangeInclusive, Linear};
use crate::selection::{self, Selection, Locations};
use crate::config::{Config, VisualBellAnimation};
-use crate::{MouseCursor, Rgb};
+use crate::MouseCursor;
use copypasta::{Clipboard, Load, Store};
use crate::input::FONT_SIZE_STEP;
-use crate::logging::LoggerProxy;
use crate::url::UrlParser;
+use crate::message_bar::MessageBuffer;
+use crate::term::color::Rgb;
+use crate::term::cell::{LineLength, Cell};
+use crate::tty;
pub mod cell;
pub mod color;
-pub use self::cell::Cell;
-use self::cell::LineLength;
/// A type that can expand a given point to a region
///
@@ -793,8 +794,11 @@ pub struct Term {
/// Automatically scroll to bottom when new lines are added
auto_scroll: bool,
- /// Proxy object for clearing displayed errors and warnings
- logger_proxy: Option<LoggerProxy>,
+ /// Buffer to store messages for the message bar
+ message_buffer: MessageBuffer,
+
+ /// Hint that Alacritty should be closed
+ should_exit: bool,
}
/// Terminal size info
@@ -835,10 +839,10 @@ impl SizeInfo {
}
pub fn contains_point(&self, x: usize, y:usize) -> bool {
- x <= (self.width - self.padding_x) as usize &&
- x >= self.padding_x as usize &&
- y <= (self.height - self.padding_y) as usize &&
- y >= self.padding_y as usize
+ x < (self.width - self.padding_x) as usize
+ && x >= self.padding_x as usize
+ && y < (self.height - self.padding_y) as usize
+ && y >= self.padding_y as usize
}
pub fn pixels_to_coords(&self, x: usize, y: usize) -> Point {
@@ -858,14 +862,6 @@ impl Term {
&self.grid.selection
}
- /// Clear displayed errors and warnings.
- pub fn clear_log(&mut self) {
- if let Some(ref mut logger_proxy) = self.logger_proxy {
- logger_proxy.clear();
- }
- }
-
-
pub fn selection_mut(&mut self) -> &mut Option<Selection> {
&mut self.grid.selection
}
@@ -885,7 +881,7 @@ impl Term {
self.next_mouse_cursor.take()
}
- pub fn new(config: &Config, size: SizeInfo) -> Term {
+ pub fn new(config: &Config, size: SizeInfo, message_buffer: MessageBuffer) -> Term {
let num_cols = size.cols();
let num_lines = size.lines();
@@ -929,14 +925,11 @@ impl Term {
dynamic_title: config.dynamic_title(),
tabspaces,
auto_scroll: config.scrolling().auto_scroll,
- logger_proxy: None,
+ message_buffer,
+ should_exit: false,
}
}
- pub fn set_logger_proxy(&mut self, logger_proxy: LoggerProxy) {
- self.logger_proxy = Some(logger_proxy);
- }
-
pub fn change_font_size(&mut self, delta: f32) {
// Saturating addition with minimum font size FONT_SIZE_STEP
let new_size = self.font_size + Size::new(delta);
@@ -1169,7 +1162,7 @@ impl Term {
}
/// Resize terminal to new dimensions
- pub fn resize(&mut self, size : &SizeInfo) {
+ pub fn resize(&mut self, size: &SizeInfo) {
debug!("Resizing terminal");
// Bounds check; lots of math assumes width and height are > 0
@@ -1184,6 +1177,10 @@ impl Term {
let mut num_cols = size.cols();
let mut num_lines = size.lines();
+ if let Some(message) = self.message_buffer.message() {
+ num_lines -= message.text(size).len();
+ }
+
self.size_info = *size;
if old_cols == num_cols && old_lines == num_lines {
@@ -1315,6 +1312,26 @@ impl Term {
pub fn background_color(&self) -> Rgb {
self.colors[NamedColor::Background]
}
+
+ #[inline]
+ pub fn message_buffer_mut(&mut self) -> &mut MessageBuffer {
+ &mut self.message_buffer
+ }
+
+ #[inline]
+ pub fn message_buffer(&self) -> &MessageBuffer {
+ &self.message_buffer
+ }
+
+ #[inline]
+ pub fn exit(&mut self) {
+ self.should_exit = true;
+ }
+
+ #[inline]
+ pub fn should_exit(&self) -> bool {
+ tty::process_should_exit() || self.should_exit
+ }
}
impl ansi::TermInfo for Term {
@@ -1859,10 +1876,7 @@ impl ansi::Handler for Term {
.each(|cell| cell.reset(&template));
}
},
- ansi::ClearMode::All => {
- self.clear_log();
- self.grid.region_mut(..).each(|c| c.reset(&template));
- },
+ ansi::ClearMode::All => self.grid.region_mut(..).each(|c| c.reset(&template)),
ansi::ClearMode::Above => {
// If clearing more than one line
if self.cursor.point.line > Line(1) {
@@ -2129,6 +2143,7 @@ mod tests {
use crate::input::FONT_SIZE_STEP;
use font::Size;
use crate::config::Config;
+ use crate::message_bar::MessageBuffer;
#[test]
fn semantic_selection_works() {
@@ -2141,7 +2156,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&Default::default(), size);
+ let mut term = Term::new(&Default::default(), size, MessageBuffer::new());
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(5), 0, Cell::default());
for i in 0..5 {
for j in 0..2 {
@@ -2185,7 +2200,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&Default::default(), size);
+ let mut term = Term::new(&Default::default(), size, MessageBuffer::new());
let mut grid: Grid<Cell> = Grid::new(Line(1), Column(5), 0, Cell::default());
for i in 0..5 {
grid[Line(0)][Column(i)].c = 'a';
@@ -2211,7 +2226,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&Default::default(), size);
+ let mut term = Term::new(&Default::default(), size, MessageBuffer::new());
let mut grid: Grid<Cell> = Grid::new(Line(3), Column(3), 0, Cell::default());
for l in 0..3 {
if l != 1 {
@@ -2256,7 +2271,7 @@ mod tests {
padding_y: 0.0,
dpr: 1.0,
};
- let mut term = Term::new(&Default::default(), size);
+ let mut term = Term::new(&Default::default(), size, MessageBuffer::new());
let cursor = Point::new(Line(0), Column(0));
term.configure_charset(CharsetIndex::G0,
StandardCharset::SpecialCharacterAndLineDrawing);
@@ -2276,7 +2291,7 @@ mod tests {
dpr: 1.0,
};
let config: Config = Default::default();
- let mut term: Term = Term::new(&config, size);
+ let mut term: Term = Term::new(&config, size, MessageBuffer::new());
term.change_font_size(font_size);
let expected_font_size: Size = config.font().size() + Size::new(font_size);
@@ -2305,7 +2320,7 @@ mod tests {
dpr: 1.0,
};
let config: Config = Default::default();
- let mut term: Term = Term::new(&config, size);
+ let mut term: Term = Term::new(&config, size, MessageBuffer::new());
term.change_font_size(-100.0);
@@ -2325,7 +2340,7 @@ mod tests {
dpr: 1.0,
};
let config: Config = Default::default();
- let mut term: Term = Term::new(&config, size);
+ let mut term: Term = Term::new(&config, size, MessageBuffer::new());
term.change_font_size(10.0);
term.reset_font_size();
@@ -2346,7 +2361,7 @@ mod tests {
dpr: 1.0
};
let config: Config = Default::default();
- let mut term: Term = Term::new(&config, size);
+ let mut term: Term = Term::new(&config, size, MessageBuffer::new());
// Add one line of scrollback
term.grid.scroll_up(&(Line(0)..Line(1)), Line(1), &Cell::default());
@@ -2373,6 +2388,7 @@ mod benches {
use crate::grid::Grid;
use crate::config::Config;
+ use crate::message_bar::MessageBuffer;
use super::{SizeInfo, Term};
use super::cell::Cell;
@@ -2411,7 +2427,7 @@ mod benches {
let config = Config::default();
- let mut terminal = Term::new(&config, size);
+ let mut terminal = Term::new(&config, size, MessageBuffer::new());
mem::swap(&mut terminal.grid, &mut grid);
b.iter(|| {