diff options
author | Vinegret43 <67828321+Vinegret43@users.noreply.github.com> | 2021-12-05 20:32:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 15:32:07 -0500 |
commit | 5f7bd3889dfc054308c19f655aa951946cfb299c (patch) | |
tree | 433c697d73dc286d008631e8feb8e2c5032fafe3 /src/config | |
parent | ebda106855d360b0adc449adf6eed33af7fabcbe (diff) |
add line numbers (#109)
* add line numbers
add command to change line numbers displaying
* refactor line numbering code
* add navigating by line numbers
add NumberedExecute trait for Command
* fix line numbering margin bug
* add documentation for numbered commands
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/general/display_crude.rs | 13 | ||||
-rw-r--r-- | src/config/option/display_option.rs | 17 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/config/general/display_crude.rs b/src/config/general/display_crude.rs index ba3c307..26473ae 100644 --- a/src/config/general/display_crude.rs +++ b/src/config/general/display_crude.rs @@ -3,7 +3,7 @@ use std::convert::From; use serde_derive::Deserialize; use tui::layout::Constraint; -use crate::config::option::DisplayOption; +use crate::config::option::{DisplayOption, LineNumberStyle}; use super::sort_crude::SortOptionCrude; @@ -50,6 +50,9 @@ pub struct DisplayOptionCrude { #[serde(default, rename = "sort")] pub sort_options: SortOptionCrude, + + #[serde(default)] + pub line_number_style: String, } impl std::default::Default for DisplayOptionCrude { @@ -65,6 +68,7 @@ impl std::default::Default for DisplayOptionCrude { show_preview: true, sort_options: SortOptionCrude::default(), tilde_in_titlebar: true, + line_number_style: "none".to_string(), } } } @@ -89,6 +93,12 @@ impl From<DisplayOptionCrude> for DisplayOption { Constraint::Ratio(0, total), ]; + let _line_nums = match crude.line_number_style.as_ref() { + "absolute" => LineNumberStyle::Absolute, + "relative" => LineNumberStyle::Relative, + _ => LineNumberStyle::None, + }; + Self { _automatically_count_files: crude.automatically_count_files, _collapse_preview: crude.collapse_preview, @@ -99,6 +109,7 @@ impl From<DisplayOptionCrude> for DisplayOption { _show_preview: crude.show_preview, _sort_options: crude.sort_options.into(), _tilde_in_titlebar: crude.tilde_in_titlebar, + _line_nums, column_ratio, default_layout, diff --git a/src/config/option/display_option.rs b/src/config/option/display_option.rs index 304ddf7..6454a1b 100644 --- a/src/config/option/display_option.rs +++ b/src/config/option/display_option.rs @@ -19,11 +19,19 @@ pub struct DisplayOption { pub _show_preview: bool, pub _sort_options: SortOption, pub _tilde_in_titlebar: bool, + pub _line_nums: LineNumberStyle, pub column_ratio: (usize, usize, usize), pub default_layout: [Constraint; 3], pub no_preview_layout: [Constraint; 3], } +#[derive(Clone, Copy, Debug)] +pub enum LineNumberStyle { + None, + Relative, + Absolute, +} + impl DisplayOption { pub fn automatically_count_files(&self) -> bool { self._automatically_count_files @@ -69,6 +77,14 @@ impl DisplayOption { self._tilde_in_titlebar } + pub fn line_nums(&self) -> LineNumberStyle { + self._line_nums + } + + pub fn set_line_nums(&mut self, style: LineNumberStyle) { + self._line_nums = style; + } + pub fn filter_func(&self) -> fn(&Result<fs::DirEntry, std::io::Error>) -> bool { if self.show_hidden() { no_filter @@ -105,6 +121,7 @@ impl std::default::Default for DisplayOption { _show_preview: true, _sort_options: SortOption::default(), _tilde_in_titlebar: true, + _line_nums: LineNumberStyle::None, default_layout, no_preview_layout, } |