aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2021-10-08 23:00:53 -0600
committerJosh Rahm <rahm@google.com>2021-10-08 23:00:53 -0600
commit52f6fd90867881300aa64034dc2c698c3fda1f34 (patch)
tree9cbcc697284a46b2e25e4bc1a8c12d882ce04945
parent750d1e196875a7063da5aa38673d0792911e8ad3 (diff)
downloadr-alacritty-52f6fd90867881300aa64034dc2c698c3fda1f34.tar.gz
r-alacritty-52f6fd90867881300aa64034dc2c698c3fda1f34.tar.bz2
r-alacritty-52f6fd90867881300aa64034dc2c698c3fda1f34.zip
Add configurable crosshairs to Alacritty.
This allows the user to put semitransparent rectangles around the current cursor line and column, รก la Vim's cursor line/column, but for the whole terminal.
-rw-r--r--alacritty/src/display/content.rs23
-rw-r--r--alacritty/src/display/cursor.rs68
-rw-r--r--alacritty_terminal/src/config/mod.rs22
3 files changed, 72 insertions, 41 deletions
diff --git a/alacritty/src/display/content.rs b/alacritty/src/display/content.rs
index 297aefd6..cb249ecd 100644
--- a/alacritty/src/display/content.rs
+++ b/alacritty/src/display/content.rs
@@ -4,7 +4,7 @@ use std::mem;
use std::ops::{Deref, DerefMut, RangeInclusive};
use alacritty_terminal::ansi::{Color, CursorShape, NamedColor};
-use alacritty_terminal::config::Config;
+use alacritty_terminal::config::{Config, CursorCrosshairs};
use alacritty_terminal::event::EventListener;
use alacritty_terminal::graphics::GraphicCell;
use alacritty_terminal::grid::{Dimensions, Indexed};
@@ -36,6 +36,7 @@ pub struct RenderableContent<'a> {
config: &'a Config<UiConfig>,
colors: &'a List,
focused_match: Option<&'a Match>,
+ cursor_crosshairs: CursorCrosshairs,
}
impl<'a> RenderableContent<'a> {
@@ -64,6 +65,7 @@ impl<'a> RenderableContent<'a> {
// Convert terminal cursor point to viewport position.
let cursor_point = terminal_content.cursor.point;
let display_offset = terminal_content.display_offset;
+ let crosshairs = config.cursor.cursor_crosshairs;
let cursor_point = display::point_to_viewport(display_offset, cursor_point).unwrap();
let hint = if display.hint_state.active() {
@@ -76,6 +78,7 @@ impl<'a> RenderableContent<'a> {
Self {
colors: &display.colors,
cursor: None,
+ cursor_crosshairs: config.cursor.cursor_crosshairs,
terminal_content,
focused_match,
cursor_shape,
@@ -86,6 +89,10 @@ impl<'a> RenderableContent<'a> {
}
}
+ pub fn cursor_crosshairs(&self) -> CursorCrosshairs {
+ self.cursor_crosshairs
+ }
+
/// Viewport offset.
pub fn display_offset(&self) -> usize {
self.terminal_content.display_offset
@@ -108,9 +115,9 @@ impl<'a> RenderableContent<'a> {
///
/// This will return `None` when there is no cursor visible.
fn renderable_cursor(&mut self, cell: &RenderableCell) -> Option<RenderableCursor> {
- if self.cursor_shape == CursorShape::Hidden {
- return None;
- }
+ // if self.cursor_shape == CursorShape::Hidden {
+ // return None;
+ // }
// Cursor colors.
let color = if self.terminal_content.mode.contains(TermMode::VI) {
@@ -139,6 +146,7 @@ impl<'a> RenderableContent<'a> {
is_wide: cell.flags.contains(Flags::WIDE_CHAR),
shape: self.cursor_shape,
point: self.cursor_point,
+ cursor_crosshairs: self.cursor_crosshairs,
cursor_color,
text_color,
})
@@ -378,16 +386,21 @@ impl RenderableCell {
}
/// Cursor storing all information relevant for rendering.
-#[derive(Debug, Eq, PartialEq, Copy, Clone)]
+#[derive(Debug, PartialEq, Copy, Clone)]
pub struct RenderableCursor {
shape: CursorShape,
cursor_color: Rgb,
text_color: Rgb,
is_wide: bool,
point: Point<usize>,
+ cursor_crosshairs: CursorCrosshairs,
}
impl RenderableCursor {
+ pub fn cursor_crosshairs(&self) -> CursorCrosshairs {
+ self.cursor_crosshairs
+ }
+
pub fn color(&self) -> Rgb {
self.cursor_color
}
diff --git a/alacritty/src/display/cursor.rs b/alacritty/src/display/cursor.rs
index f3a782cc..6415f152 100644
--- a/alacritty/src/display/cursor.rs
+++ b/alacritty/src/display/cursor.rs
@@ -6,15 +6,16 @@ use alacritty_terminal::term::SizeInfo;
use crate::display::content::RenderableCursor;
use crate::renderer::rects::RenderRect;
+use std::vec::Vec;
/// Trait for conversion into the iterator.
pub trait IntoRects {
/// Consume the cursor for an iterator of rects.
- fn rects(self, size_info: &SizeInfo, thickness: f32) -> CursorRects;
+ fn rects(self, size_info: &SizeInfo, thickness: f32) -> Vec<RenderRect>;
}
impl IntoRects for RenderableCursor {
- fn rects(self, size_info: &SizeInfo, thickness: f32) -> CursorRects {
+ fn rects(self, size_info: &SizeInfo, thickness: f32) -> Vec<RenderRect> {
let point = self.point();
let x = point.column.0 as f32 * size_info.cell_width() + size_info.padding_x();
let y = point.line as f32 * size_info.cell_height() + size_info.padding_y();
@@ -28,51 +29,53 @@ impl IntoRects for RenderableCursor {
width *= 2.;
}
- match self.shape() {
+ let mut crosshairs = if self.cursor_crosshairs().enable {
+ crosshair(x, y, size_info, self.cursor_crosshairs().color, self.cursor_crosshairs().opacity.as_f32())
+ } else {
+ vec![]
+ };
+
+ let mut shape = match self.shape() {
CursorShape::Beam => beam(x, y, height, thickness, self.color()),
CursorShape::Underline => underline(x, y, width, height, thickness, self.color()),
CursorShape::HollowBlock => hollow(x, y, width, height, thickness, self.color()),
- _ => CursorRects::default(),
- }
- }
-}
+ CursorShape::Hidden => vec![],
+ _ => vec![],
+ };
-/// Cursor rect iterator.
-#[derive(Default)]
-pub struct CursorRects {
- rects: [Option<RenderRect>; 4],
- index: usize,
-}
-
-impl From<RenderRect> for CursorRects {
- fn from(rect: RenderRect) -> Self {
- Self { rects: [Some(rect), None, None, None], index: 0 }
+ shape.append(&mut crosshairs);
+ shape
}
}
-impl Iterator for CursorRects {
- type Item = RenderRect;
-
- fn next(&mut self) -> Option<Self::Item> {
- let rect = self.rects.get_mut(self.index)?;
- self.index += 1;
- rect.take()
- }
+fn crosshair(x: f32, y: f32, size_info: &SizeInfo, color: Rgb, opacity: f32) -> Vec<RenderRect> {
+ let width = size_info.cell_width();
+ let height = size_info.cell_height();
+ let yskip = 0.;
+ let xskip = 0.;
+
+ vec![
+ RenderRect::new(x, 0., width, y + size_info.cell_height(), color, opacity),
+ RenderRect::new(
+ x, y + size_info.cell_height() * (yskip + 1.), width, size_info.height(), color, opacity),
+ RenderRect::new(0., y, x - (size_info.cell_width() * xskip), height, color, opacity),
+ RenderRect::new(x + size_info.cell_width() * (xskip + 1.), y, size_info.width(), height, color, opacity)
+ ]
}
/// Create an iterator yielding a single beam rect.
-fn beam(x: f32, y: f32, height: f32, thickness: f32, color: Rgb) -> CursorRects {
- RenderRect::new(x, y, thickness, height, color, 1.).into()
+fn beam(x: f32, y: f32, height: f32, thickness: f32, color: Rgb) -> Vec<RenderRect> {
+ vec![RenderRect::new(x, y, thickness, height, color, 1.)]
}
/// Create an iterator yielding a single underline rect.
-fn underline(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -> CursorRects {
+fn underline(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -> Vec<RenderRect> {
let y = y + height - thickness;
- RenderRect::new(x, y, width, thickness, color, 1.).into()
+ vec![RenderRect::new(x, y, width, thickness, color, 1.)]
}
/// Create an iterator yielding a rect for each side of the hollow block cursor.
-fn hollow(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -> CursorRects {
+fn hollow(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -> Vec<RenderRect> {
let top_line = RenderRect::new(x, y, width, thickness, color, 1.);
let vertical_y = y + thickness;
@@ -85,8 +88,5 @@ fn hollow(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -
let right_x = x + width - thickness;
let right_line = RenderRect::new(right_x, vertical_y, thickness, vertical_height, color, 1.);
- CursorRects {
- rects: [Some(top_line), Some(bottom_line), Some(left_line), Some(right_line)],
- index: 0,
- }
+ vec![top_line, bottom_line, left_line, right_line]
}
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index 382314bd..3d7f73a3 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -5,6 +5,7 @@ use std::path::PathBuf;
use serde::Deserialize;
use alacritty_config_derive::ConfigDeserialize;
+use crate::term::color::{Rgb};
mod scrolling;
@@ -66,12 +67,29 @@ pub struct Cursor {
pub style: ConfigCursorStyle,
pub vi_mode_style: Option<ConfigCursorStyle>,
pub unfocused_hollow: bool,
- pub cursor_crosshairs: bool,
+ pub cursor_crosshairs: CursorCrosshairs,
thickness: Percentage,
blink_interval: u64,
}
+#[derive(ConfigDeserialize, Copy, Clone, Debug, PartialEq)]
+pub struct CursorCrosshairs {
+ pub enable: bool,
+ pub color: Rgb,
+ pub opacity: Percentage,
+}
+
+impl Default for CursorCrosshairs {
+ fn default() -> Self {
+ Self {
+ enable: false,
+ color: Rgb { r: 0x80, g: 0x80, b: 0x80 },
+ opacity: Percentage::new(0.1),
+ }
+ }
+}
+
impl Default for Cursor {
fn default() -> Self {
Self {
@@ -80,7 +98,7 @@ impl Default for Cursor {
blink_interval: 750,
style: Default::default(),
vi_mode_style: Default::default(),
- cursor_crosshairs: false,
+ cursor_crosshairs: Default::default(),
}
}
}