mirror of
https://github.com/denisidoro/navi
synced 2024-11-21 19:13:07 +00:00
Merge pull request #697 from carlfriedrich/make-width-configurable-for-snippet-column
Make width configurable for snippet column
This commit is contained in:
commit
77403ca0e5
3 changed files with 17 additions and 4 deletions
|
@ -128,6 +128,10 @@ impl Config {
|
||||||
self.yaml.style.comment.width_percentage
|
self.yaml.style.comment.width_percentage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snippet_width_percentage(&self) -> u16 {
|
||||||
|
self.yaml.style.snippet.width_percentage
|
||||||
|
}
|
||||||
|
|
||||||
pub fn tag_min_width(&self) -> u16 {
|
pub fn tag_min_width(&self) -> u16 {
|
||||||
self.yaml.style.tag.min_width
|
self.yaml.style.tag.min_width
|
||||||
}
|
}
|
||||||
|
@ -136,6 +140,10 @@ impl Config {
|
||||||
self.yaml.style.comment.min_width
|
self.yaml.style.comment.min_width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snippet_min_width(&self) -> u16 {
|
||||||
|
self.yaml.style.snippet.min_width
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "disable-command-execution")]
|
#[cfg(feature = "disable-command-execution")]
|
||||||
fn print(&self) -> bool {
|
fn print(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::terminal;
|
||||||
pub use crate::terminal::style::style;
|
pub use crate::terminal::style::style;
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
|
|
||||||
pub fn get_widths() -> (usize, usize) {
|
pub fn get_widths() -> (usize, usize, usize) {
|
||||||
let width = terminal::width();
|
let width = terminal::width();
|
||||||
let tag_width_percentage = max(
|
let tag_width_percentage = max(
|
||||||
CONFIG.tag_min_width(),
|
CONFIG.tag_min_width(),
|
||||||
|
@ -13,8 +13,13 @@ pub fn get_widths() -> (usize, usize) {
|
||||||
CONFIG.comment_min_width(),
|
CONFIG.comment_min_width(),
|
||||||
width * CONFIG.comment_width_percentage() / 100,
|
width * CONFIG.comment_width_percentage() / 100,
|
||||||
);
|
);
|
||||||
|
let snippet_width_percentage = max(
|
||||||
|
CONFIG.snippet_min_width(),
|
||||||
|
width * CONFIG.snippet_width_percentage() / 100,
|
||||||
|
);
|
||||||
(
|
(
|
||||||
usize::from(tag_width_percentage),
|
usize::from(tag_width_percentage),
|
||||||
usize::from(comment_width_percentage),
|
usize::from(comment_width_percentage),
|
||||||
|
usize::from(snippet_width_percentage),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub const DELIMITER: &str = r" ⠀";
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref NEWLINE_REGEX: Regex = Regex::new(r"\\\s+").expect("Invalid regex");
|
pub static ref NEWLINE_REGEX: Regex = Regex::new(r"\\\s+").expect("Invalid regex");
|
||||||
pub static ref VAR_REGEX: Regex = Regex::new(r"\\?<(\w[\w\d\-_]*)>").expect("Invalid regex");
|
pub static ref VAR_REGEX: Regex = Regex::new(r"\\?<(\w[\w\d\-_]*)>").expect("Invalid regex");
|
||||||
pub static ref COLUMN_WIDTHS: (usize, usize) = ui::get_widths();
|
pub static ref COLUMN_WIDTHS: (usize, usize, usize) = ui::get_widths();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_new_lines(txt: String) -> String {
|
pub fn with_new_lines(txt: String) -> String {
|
||||||
|
@ -37,12 +37,12 @@ fn limit_str(text: &str, length: usize) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(item: &Item) -> String {
|
pub fn write(item: &Item) -> String {
|
||||||
let (tag_width_percentage, comment_width_percentage) = *COLUMN_WIDTHS;
|
let (tag_width_percentage, comment_width_percentage, snippet_width_percentage) = *COLUMN_WIDTHS;
|
||||||
format!(
|
format!(
|
||||||
"{tags_short}{delimiter}{comment_short}{delimiter}{snippet_short}{delimiter}{tags}{delimiter}{comment}{delimiter}{snippet}{delimiter}{file_index}{delimiter}\n",
|
"{tags_short}{delimiter}{comment_short}{delimiter}{snippet_short}{delimiter}{tags}{delimiter}{comment}{delimiter}{snippet}{delimiter}{file_index}{delimiter}\n",
|
||||||
tags_short = ui::style(limit_str(&item.tags, tag_width_percentage)).with(CONFIG.tag_color()),
|
tags_short = ui::style(limit_str(&item.tags, tag_width_percentage)).with(CONFIG.tag_color()),
|
||||||
comment_short = ui::style(limit_str(&item.comment, comment_width_percentage)).with(CONFIG.comment_color()),
|
comment_short = ui::style(limit_str(&item.comment, comment_width_percentage)).with(CONFIG.comment_color()),
|
||||||
snippet_short = ui::style(fix_newlines(&item.snippet)).with(CONFIG.snippet_color()),
|
snippet_short = ui::style(limit_str(&fix_newlines(&item.snippet), snippet_width_percentage)).with(CONFIG.snippet_color()),
|
||||||
tags = item.tags,
|
tags = item.tags,
|
||||||
comment = item.comment,
|
comment = item.comment,
|
||||||
delimiter = DELIMITER,
|
delimiter = DELIMITER,
|
||||||
|
|
Loading…
Reference in a new issue