aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-02-24 08:23:07 -0800
committerJoe Wilm <jwilm@users.noreply.github.com>2017-02-25 07:55:35 -0800
commit31ed5160a0b71f37c723d78b539003bc5227f184 (patch)
treec6581fb136ae531e5f917a2c1b6cab1e7628e969 /src/util.rs
parentfef965c121d30463adb1c88e91644b24751461da (diff)
downloadalacritty-31ed5160a0b71f37c723d78b539003bc5227f184.tar.gz
alacritty-31ed5160a0b71f37c723d78b539003bc5227f184.zip
Change cursor colors config to use text and cursor
This changes the cursor color config to use the `text` and `cursor` properties instead of the current `foreground` and `background` properties. The latter names stop making sense when dealing with cursors like a vertical bar or underscore. In the new system, the block, underscore, or vertical bar would always take the color of `cursor`, and the text would take the color of `text` when using a block, or keep its normal color when using the underscore or vertical bar. A warning is now emitted on startup when the old form of cursor color config is used. This will be a hard error in the future.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/util.rs b/src/util.rs
index ccb22cc9..3452e5b2 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -49,19 +49,33 @@ pub fn limit<T: Ord>(value: T, min: T, max: T) -> T {
pub mod fmt {
use std::fmt;
- /// Write a `Display` or `Debug` escaped with Red
- pub struct Red<T>(pub T);
+ macro_rules! define_colors {
+ ($($(#[$attrs:meta])* pub struct $s:ident => $color:expr;)*) => {
+ $(
+ $(#[$attrs])*
+ pub struct $s<T>(pub T);
- impl<T: fmt::Display> fmt::Display for Red<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "\x1b[31m{}\x1b[0m", self.0)
+ impl<T: fmt::Display> fmt::Display for $s<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "\x1b[{}m{}\x1b[0m", $color, self.0)
+ }
+ }
+
+ impl<T: fmt::Debug> fmt::Debug for $s<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "\x1b[{}m{:?}\x1b[0m", $color, self.0)
+ }
+ }
+ )*
}
}
- impl<T: fmt::Debug> fmt::Debug for Red<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "\x1b[31m{:?}\x1b[0m", self.0)
- }
+ define_colors! {
+ /// Write a `Display` or `Debug` escaped with Red
+ pub struct Red => "31";
+
+ /// Write a `Display` or `Debug` escaped with Yellow
+ pub struct Yellow => "33";
}
}