aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorThomas2022-04-20 01:44:32 +0000
committerGitHub2022-04-20 01:44:32 +0000
commit5d5b6bab9ba5211c8c146fb38276f968892e7882 (patch)
treee28f9861eb09e95629a392cf9f1160c7922584ca /helix-term/src/ui
parent02426072cbe4b6272bf54d89f85598bb79a33729 (diff)
Add rulers option (#2060)
* Add color_column option * Rename to ruler Co-authored-by: DeviousStoat <devious@stoat.com>
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/editor.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 459a8c87..fc8b6470 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -126,6 +126,7 @@ impl EditorView {
Self::render_text_highlights(doc, view.offset, inner, surface, theme, highlights);
Self::render_gutter(editor, doc, view, view.area, surface, theme, is_focused);
+ Self::render_rulers(editor, doc, view, inner, surface, theme);
if is_focused {
Self::render_focused_view_elements(view, doc, inner, theme, surface);
@@ -152,6 +153,32 @@ impl EditorView {
self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
}
+ pub fn render_rulers(
+ editor: &Editor,
+ doc: &Document,
+ view: &View,
+ viewport: Rect,
+ surface: &mut Surface,
+ theme: &Theme,
+ ) {
+ let editor_rulers = &editor.config().rulers;
+ let ruler_theme = theme.get("ui.virtual.ruler");
+
+ let rulers = doc
+ .language_config()
+ .and_then(|config| config.rulers.as_ref())
+ .unwrap_or(editor_rulers);
+
+ rulers
+ .iter()
+ // View might be horizontally scrolled, convert from absolute distance
+ // from the 1st column to relative distance from left of viewport
+ .filter_map(|ruler| ruler.checked_sub(1 + view.offset.col as u16))
+ .filter(|ruler| ruler < &viewport.width)
+ .map(|ruler| viewport.clip_left(ruler).with_width(1))
+ .for_each(|area| surface.set_style(area, ruler_theme))
+ }
+
/// Get syntax highlights for a document in a view represented by the first line
/// and column (`offset`) and the last line. This is done instead of using a view
/// directly to enable rendering syntax highlighted docs anywhere (eg. picker preview)