Skip to content

Commit

Permalink
Add rulers option (#2060)
Browse files Browse the repository at this point in the history
* Add color_column option

* Rename to ruler

Co-authored-by: DeviousStoat <[email protected]>
  • Loading branch information
DeviousStoat and DeviousStoat authored Apr 20, 2022
1 parent 0242607 commit 5d5b6ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hidden = false
| `completion-trigger-len` | The min-length of word under cursor to trigger autocompletion | `2` |
| `auto-info` | Whether to display infoboxes | `true` |
| `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. | `false` |
| `rulers` | List of column positions at which to display the rulers. Can be overidden by language specific `rulers` in `languages.toml` file. | `[]` |

### `[editor.lsp]` Section

Expand Down
2 changes: 2 additions & 0 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub struct LanguageConfiguration {
/// global setting.
#[serde(default, skip_serializing, deserialize_with = "deserialize_auto_pairs")]
pub auto_pairs: Option<AutoPairs>,

pub rulers: Option<Vec<u16>>, // if set, override editor's rulers
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
27 changes: 27 additions & 0 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub struct Config {
#[serde(default)]
pub search: SearchConfig,
pub lsp: LspConfig,
/// Column numbers at which to draw the rulers. Default to `[]`, meaning no rulers.
pub rulers: Vec<u16>,
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -285,6 +287,7 @@ impl Default for Config {
true_color: false,
search: SearchConfig::default(),
lsp: LspConfig::default(),
rulers: Vec::new(),
}
}
}
Expand Down

0 comments on commit 5d5b6ba

Please sign in to comment.