mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
[#954] Display multi-line description and multi-line code-blocks with multiple lines (only fzf supported)
This commit is contained in:
parent
853346748d
commit
6e069a939f
5 changed files with 38 additions and 15 deletions
|
|
@ -14,7 +14,7 @@ pub struct Input {
|
|||
}
|
||||
|
||||
fn extract_elements(argstr: &str) -> Result<(&str, &str, &str)> {
|
||||
let mut parts = argstr.split(deser::terminal::DELIMITER).skip(3);
|
||||
let mut parts = argstr.split(deser::terminal::DELIMITER).skip(1);
|
||||
let tags = parts.next().context("No `tags` element provided.")?;
|
||||
let comment = parts.next().context("No `comment` element provided.")?;
|
||||
let snippet = parts.next().context("No `snippet` element provided.")?;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub fn with_new_lines(txt: String) -> String {
|
|||
pub fn fix_newlines(txt: &str) -> String {
|
||||
if txt.contains(NEWLINE_ESCAPE_CHAR) {
|
||||
(*NEWLINE_REGEX)
|
||||
.replace_all(txt.replace(LINE_SEPARATOR, " ").as_str(), "")
|
||||
.replace_all(txt.replace(LINE_SEPARATOR, "\n").as_str(), "")
|
||||
.to_string()
|
||||
} else {
|
||||
txt.to_string()
|
||||
|
|
|
|||
|
|
@ -33,11 +33,28 @@ lazy_static! {
|
|||
|
||||
pub fn write(item: &Item) -> String {
|
||||
let (tag_width_percentage, comment_width_percentage, snippet_width_percentage) = *COLUMN_WIDTHS;
|
||||
|
||||
let separator_count = max(
|
||||
item.snippet.matches(LINE_SEPARATOR).count(),
|
||||
item.comment.matches(LINE_SEPARATOR).count(),
|
||||
);
|
||||
|
||||
let splitted_comment = item.comment.split(LINE_SEPARATOR).collect::<Vec<&str>>();
|
||||
let splitted_snippet = item.snippet.split(LINE_SEPARATOR).collect::<Vec<&str>>();
|
||||
|
||||
let printer_item = (0..=separator_count)
|
||||
.map(|i| {format!("{tags_short}{delimiter}{comment_line_i}{delimiter}{snippet_line_i}",
|
||||
tags_short = style(limit_str(if i == 0 { &item.tags } else { "" }, tag_width_percentage)).with(CONFIG.tag_color()),
|
||||
comment_line_i = style(limit_str(splitted_comment.get(i).unwrap_or(&""), comment_width_percentage)).with(CONFIG.comment_color()),
|
||||
snippet_line_i = style(limit_str(splitted_snippet.get(i).unwrap_or(&""), snippet_width_percentage)).with(CONFIG.snippet_color()),
|
||||
delimiter = " ",
|
||||
)})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
|
||||
format!(
|
||||
"{tags_short}{delimiter}{comment_short}{delimiter}{snippet_short}{delimiter}{tags}{delimiter}{comment}{delimiter}{snippet}{delimiter}{file_index}{delimiter}\n",
|
||||
tags_short = style(limit_str(&item.tags, tag_width_percentage)).with(CONFIG.tag_color()),
|
||||
comment_short = style(limit_str(&fix_newlines(&item.comment), comment_width_percentage)).with(CONFIG.comment_color()),
|
||||
snippet_short = style(limit_str(&fix_newlines(&item.snippet), snippet_width_percentage)).with(CONFIG.snippet_color()),
|
||||
"{printer_item}{delimiter}{tags}{delimiter}{comment}{delimiter}{snippet}{delimiter}{file_index}{delimiter}\0",
|
||||
printer_item = printer_item,
|
||||
tags = item.tags,
|
||||
comment = item.comment,
|
||||
delimiter = DELIMITER,
|
||||
|
|
@ -47,7 +64,7 @@ pub fn write(item: &Item) -> String {
|
|||
}
|
||||
|
||||
pub fn read(raw_snippet: &str, is_single: bool) -> Result<(&str, Item)> {
|
||||
let mut lines = raw_snippet.split('\n');
|
||||
let mut lines = raw_snippet.split('\0');
|
||||
let key = if is_single {
|
||||
"enter"
|
||||
} else {
|
||||
|
|
@ -60,7 +77,7 @@ pub fn read(raw_snippet: &str, is_single: bool) -> Result<(&str, Item)> {
|
|||
.next()
|
||||
.context("No more parts in `selections`")?
|
||||
.split(DELIMITER)
|
||||
.skip(3);
|
||||
.skip(1);
|
||||
|
||||
let tags = parts.next().unwrap_or("").into();
|
||||
let comment = parts.next().unwrap_or("").into();
|
||||
|
|
|
|||
|
|
@ -116,10 +116,12 @@ impl FinderChoice {
|
|||
"--bind",
|
||||
format!("ctrl-j:down,ctrl-k:up{bindings}").as_str(),
|
||||
"--exact",
|
||||
"--read0",
|
||||
"--print0",
|
||||
]);
|
||||
|
||||
if !opts.show_all_columns {
|
||||
command.args(["--with-nth", "1,2,3"]);
|
||||
command.args(["--with-nth", "1"]);
|
||||
}
|
||||
|
||||
if !opts.prevent_select1 {
|
||||
|
|
|
|||
|
|
@ -225,9 +225,13 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let write_fn = self.write_fn;
|
||||
|
||||
self.writer
|
||||
.write_all(write_fn(item).as_bytes())
|
||||
.context("Failed to write command to finder's stdin")
|
||||
let string = write_fn(item);
|
||||
//eprintln!("string as written by write_fn:\n{}", string);
|
||||
|
||||
return self
|
||||
.writer
|
||||
.write_all(string.as_bytes())
|
||||
.context("Failed to write command to finder's stdin");
|
||||
}
|
||||
|
||||
pub fn read_lines(
|
||||
|
|
@ -257,9 +261,9 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// blank
|
||||
if line.is_empty() {
|
||||
if !item.snippet.is_empty() {
|
||||
item.snippet.push_str(deser::LINE_SEPARATOR);
|
||||
}
|
||||
// if !item.snippet.is_empty() {
|
||||
// item.snippet.push_str(deser::LINE_SEPARATOR);
|
||||
// }
|
||||
}
|
||||
// tag
|
||||
else if line.starts_with('%') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue