From 23ee04fffe4bdf4b8c34603e4b191d7cc308051b Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 25 Oct 2024 12:48:19 +0200 Subject: Inegrate new command-action driven structure - Map keys to actions to commands - allows for easily adding config file support - restructure folders/files - implement own input mode - rewrite UI rendering to make it better editable --- Cargo.lock | 31 +--- Cargo.toml | 2 +- build.rs | 7 + src/app.rs | 6 +- src/bibiman.rs | 376 +++++++++++++++++++++++++++++++++++++++++++++++- src/bibiman/keywords.rs | 2 + src/bibiman/search.rs | 17 +++ src/cliargs.rs | 11 +- src/tui.rs | 6 +- src/tui/command.rs | 374 ----------------------------------------------- src/tui/commandnew.rs | 191 ------------------------ src/tui/commands.rs | 195 +++++++++++++++++++++++++ src/tui/ui.rs | 44 +++--- 13 files changed, 635 insertions(+), 627 deletions(-) create mode 100644 build.rs delete mode 100644 src/tui/command.rs delete mode 100644 src/tui/commandnew.rs create mode 100644 src/tui/commands.rs diff --git a/Cargo.lock b/Cargo.lock index 496ba45..226ee17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,7 +82,7 @@ dependencies = [ "hayagriva", "itertools", "nucleo-matcher", - "ratatui 0.29.0", + "ratatui", "sarge", "signal-hook", "tokio", @@ -1132,27 +1132,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "ratatui" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d" -dependencies = [ - "bitflags 2.6.0", - "cassowary", - "compact_str", - "crossterm", - "instability", - "itertools", - "lru", - "paste", - "strum", - "strum_macros", - "unicode-segmentation", - "unicode-truncate", - "unicode-width 0.1.14", -] - [[package]] name = "ratatui" version = "0.29.0" @@ -1563,12 +1542,12 @@ dependencies = [ [[package]] name = "tui-input" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd137780d743c103a391e06fe952487f914b299a4fe2c3626677f6a6339a7c6b" +checksum = "ffde6d8fcffe86b617018ca9b2171d673b41def44ebf802de203d2f2c598d3de" dependencies = [ - "ratatui 0.28.1", - "unicode-width 0.1.14", + "ratatui", + "unicode-width 0.2.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 194aeda..d2f06e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ sarge = "7.2.5" signal-hook = "0.3.17" tokio = { version = "1.39.3", features = ["full"] } tokio-util = "0.7.12" -tui-input = "0.10.1" +tui-input = "0.11.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ea31c78 --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +// Make target-triple used for build accessable in binary +fn main() { + println!( + "cargo:rustc-env=TARGET={}", + std::env::var("TARGET").unwrap() + ); +} diff --git a/src/app.rs b/src/app.rs index 13892af..fe47882 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,9 +18,9 @@ use crate::bibiman::CurrentArea; // use super::Event; use crate::cliargs::CLIArgs; -use crate::tui::commandnew::{InputCmdAction, OpenRessource}; +use crate::tui::commands::{InputCmdAction, OpenRessource}; use crate::tui::{self, Tui}; -use crate::{bibiman::Bibiman, tui::commandnew::CmdAction}; +use crate::{bibiman::Bibiman, tui::commands::CmdAction}; use color_eyre::eyre::{Ok, Result}; use tui::Event; use tui_input::backend::crossterm::EventHandler; @@ -101,6 +101,7 @@ impl App { pub fn run_command(&mut self, cmd: CmdAction, tui: &mut Tui) -> Result<()> { match cmd { CmdAction::Input(cmd) => match cmd { + InputCmdAction::Nothing => {} InputCmdAction::Handle(event) => { self.input.handle_event(&event); self.bibiman.search_list_by_pattern(&self.input); @@ -111,6 +112,7 @@ impl App { self.bibiman.enter_search_area(); } InputCmdAction::Confirm => { + self.input = Input::default(); self.input_mode = false; // Logic for TABS to be added self.bibiman.confirm_search(); diff --git a/src/bibiman.rs b/src/bibiman.rs index 5d8dbf2..4f66c9c 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -15,12 +15,18 @@ // along with this program. If not, see . ///// +use crate::bibiman::entries::EntryTableColumn; use crate::bibiman::{bibisetup::*, search::BibiSearch}; use crate::cliargs::CLIArgs; +use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; -use color_eyre::eyre::{Ok, Result}; +use color_eyre::eyre::{Context, Ok, Result}; +use core::panic; +use editor_command::EditorBuilder; +use ratatui::widgets::ScrollbarState; use std::path::PathBuf; +use std::process::{Command, Stdio}; use tui_input::Input; pub mod bibisetup; @@ -147,7 +153,360 @@ impl Bibiman { .entry_info_scroll_state .position(self.entry_table.entry_info_scroll.into()); } +} + +impl Bibiman { + // Entry Table commands + + /// Select next entry in Table holding the bibliographic entries. + /// + /// Takes u16 value as argument to specify number of entries which + /// should be scrolled + pub fn select_next_entry(&mut self, entries: u16) { + self.entry_table.entry_info_scroll = 0; + self.entry_table.entry_info_scroll_state = + self.entry_table.entry_info_scroll_state.position(0); + self.entry_table.entry_table_state.scroll_down_by(entries); + self.entry_table.entry_scroll_state = self + .entry_table + .entry_scroll_state + .position(self.entry_table.entry_table_state.selected().unwrap()); + } + + /// Select previous entry in Table holding the bib entries. + /// + /// Takes u16 value as argument to specify number of entries which + /// should be scrolled + pub fn select_previous_entry(&mut self, entries: u16) { + self.entry_table.entry_info_scroll = 0; + self.entry_table.entry_info_scroll_state = + self.entry_table.entry_info_scroll_state.position(0); + self.entry_table.entry_table_state.scroll_up_by(entries); + self.entry_table.entry_scroll_state = self + .entry_table + .entry_scroll_state + .position(self.entry_table.entry_table_state.selected().unwrap()); + } + + /// Select first entry in bib list + pub fn select_first_entry(&mut self) { + self.entry_table.entry_info_scroll = 0; + self.entry_table.entry_info_scroll_state = + self.entry_table.entry_info_scroll_state.position(0); + self.entry_table.entry_table_state.select_first(); + self.entry_table.entry_scroll_state = self.entry_table.entry_scroll_state.position(0); + } + + /// Select last entry in bib list + pub fn select_last_entry(&mut self) { + self.entry_table.entry_info_scroll = 0; + self.entry_table.entry_info_scroll_state = + self.entry_table.entry_info_scroll_state.position(0); + // self.entry_table.entry_table_state.select_last(); // Does not work properly after upgrading to ratatui 0.29.0 + self.entry_table + .entry_table_state + .select(Some(self.entry_table.entry_table_items.len() - 1)); + self.entry_table.entry_scroll_state = self + .entry_table + .entry_scroll_state + .position(self.entry_table.entry_table_items.len()); + } + + /// Select next (right) column of entry table + pub fn select_next_column(&mut self) { + match self.entry_table.entry_table_selected_column { + EntryTableColumn::Authors => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Title; + } + EntryTableColumn::Title => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Year; + } + EntryTableColumn::Year => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Pubtype; + } + EntryTableColumn::Pubtype => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Authors; + } + } + } + + /// Select previous (left) column of entry table + pub fn select_prev_column(&mut self) { + match self.entry_table.entry_table_selected_column { + EntryTableColumn::Authors => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Pubtype; + } + EntryTableColumn::Title => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Authors; + } + EntryTableColumn::Year => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Title; + } + EntryTableColumn::Pubtype => { + self.entry_table.entry_table_selected_column = EntryTableColumn::Year; + } + } + } + + // Get the citekey of the selected entry + pub fn get_selected_citekey(&self) -> &str { + let idx = self.entry_table.entry_table_state.selected().unwrap(); + let citekey = &self.entry_table.entry_table_items[idx].citekey; + citekey + } + + pub fn run_editor(&mut self, tui: &mut Tui) -> Result<()> { + // get filecontent and citekey for calculating line number + let citekey = self.get_selected_citekey(); + // create independent copy of citekey for finding entry after updating list + let saved_key = citekey.to_owned(); + let filepath = self.main_biblio.bibfile.display().to_string(); + let filecontent = self.main_biblio.bibfilestring.clone(); + let mut line_count = 0; + + for line in filecontent.lines() { + line_count = line_count + 1; + // if reaching the citekey break the loop + // if reaching end of lines without match, reset to 0 + if line.contains(&citekey) { + break; + } else if line_count == filecontent.len() { + eprintln!( + "Citekey {} not found, opening file {} at line 1", + &citekey, &filepath + ); + line_count = 0; + break; + } + } + + // Exit TUI to enter editor + tui.exit()?; + // Use VISUAL or EDITOR. Set "vi" as last fallback + let mut cmd: Command = EditorBuilder::new() + .environment() + .source(Some("vi")) + .build() + .unwrap(); + // Prepare arguments to open file at specific line + let args: Vec = vec![format!("+{}", line_count), filepath]; + let status = cmd.args(&args).status()?; + if !status.success() { + eprintln!("Spawning editor failed with status {}", status); + } + + // Enter TUI again + tui.enter()?; + tui.terminal.clear()?; + + // Update the database and the lists to show changes + self.update_lists(); + + // Search for entry, selected before editing, by matching citekeys + // Use earlier saved copy of citekey to match + let mut idx_count = 0; + loop { + if self.entry_table.entry_table_items[idx_count] + .citekey + .contains(&saved_key) + { + break; + } + idx_count = idx_count + 1 + } + + // Set selected entry to vec-index of match + self.entry_table.entry_table_state.select(Some(idx_count)); + + Ok(()) + } + + // Search entry list + pub fn search_entries(&mut self) { + // Use snapshot of entry list saved when starting the search + // so deleting a char, will show former entries too + let orig_list = self.entry_table.entry_table_at_search_start.clone(); + let filtered_list = + BibiSearch::search_entry_list(&mut self.search_struct.search_string, orig_list.clone()); + self.entry_table.entry_table_items = filtered_list; + if self.entry_table.entry_table_reversed_sort { + self.entry_table.sort_entry_table(false); + } + self.entry_table.entry_scroll_state = ScrollbarState::content_length( + self.entry_table.entry_scroll_state, + self.entry_table.entry_table_items.len(), + ); + } + // Open file connected with entry through 'file' or 'pdf' field + pub fn open_connected_file(&mut self) -> Result<()> { + let idx = self.entry_table.entry_table_state.selected().unwrap(); + let filepath = &self.entry_table.entry_table_items[idx].filepath.clone(); + + // Build command to execute pdf-reader. 'xdg-open' is Linux standard + let cmd = { + match std::env::consts::OS { + "linux" => String::from("xdg-open"), + "macos" => String::from("open"), + "windows" => String::from("start"), + _ => panic!("Couldn't detect OS for setting correct opener"), + } + }; + + // Pass filepath as argument, pipe stdout and stderr to /dev/null + // to keep the TUI clean (where is it piped on Windows???) + let _ = Command::new(&cmd) + .arg(&filepath) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .wrap_err("Opening file not possible"); + + Ok(()) + } + + pub fn open_doi_url(&mut self) -> Result<()> { + let idx = self.entry_table.entry_table_state.selected().unwrap(); + let web_adress = self.entry_table.entry_table_items[idx].doi_url.clone(); + + // Resolve strings using the resolving function of dx.doi.org, so the + // terminal is not blocked by the resolving process + let url = if web_adress.starts_with("10.") { + let prefix = "https://doi.org/".to_string(); + prefix + &web_adress + } else if web_adress.starts_with("www.") { + let prefix = "https://".to_string(); + prefix + &web_adress + } else { + web_adress + }; + + // Build command to execute browser. 'xdg-open' is Linux standard + let cmd = { + match std::env::consts::OS { + "linux" => String::from("xdg-open"), + "macos" => String::from("open"), + "windows" => String::from("start"), + _ => panic!("Couldn't detect OS for setting correct opener"), + } + }; + + // Pass filepath as argument, pipe stdout and stderr to /dev/null + // to keep the TUI clean (where is it piped on Windows???) + let _ = Command::new(&cmd) + .arg(url) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .wrap_err("Opening file not possible"); + + Ok(()) + } +} + +impl Bibiman { + // Tag List commands + + // Movement + pub fn select_next_tag(&mut self, keywords: u16) { + self.tag_list.tag_list_state.scroll_down_by(keywords); + self.tag_list.tag_scroll_state = self + .tag_list + .tag_scroll_state + .position(self.tag_list.tag_list_state.selected().unwrap()); + } + + pub fn select_previous_tag(&mut self, keywords: u16) { + self.tag_list.tag_list_state.scroll_up_by(keywords); + self.tag_list.tag_scroll_state = self + .tag_list + .tag_scroll_state + .position(self.tag_list.tag_list_state.selected().unwrap()); + } + + pub fn select_first_tag(&mut self) { + self.tag_list.tag_list_state.select_first(); + self.tag_list.tag_scroll_state = self.tag_list.tag_scroll_state.position(0); + } + + pub fn select_last_tag(&mut self) { + self.tag_list.tag_list_state.select_last(); + self.tag_list.tag_scroll_state = self + .tag_list + .tag_scroll_state + .position(self.tag_list.tag_list_items.len()); + } + + pub fn get_selected_tag(&self) -> &str { + let idx = self.tag_list.tag_list_state.selected().unwrap(); + let keyword = &self.tag_list.tag_list_items[idx]; + // let keyword = &self.tag_list.tag_list_items[idx].keyword; + keyword + } + + pub fn search_tags(&mut self) { + let orig_list = &self.tag_list.tag_list_at_search_start; + let filtered_list = + BibiSearch::search_tag_list(&self.search_struct.search_string, orig_list.clone()); + self.tag_list.tag_list_items = filtered_list; + // Update scrollbar length after filtering list + self.tag_list.tag_scroll_state = ScrollbarState::content_length( + self.tag_list.tag_scroll_state, + self.tag_list.tag_list_items.len(), + ); + } + + pub fn filter_tags_by_entries(&mut self) { + let mut filtered_keywords: Vec = Vec::new(); + + let orig_list = &self.entry_table.entry_table_items; + + for e in orig_list { + if !e.keywords.is_empty() { + let mut key_vec: Vec = e + .keywords + .split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect(); + filtered_keywords.append(&mut key_vec); + } + } + + filtered_keywords.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase())); + filtered_keywords.dedup(); + + self.search_struct.filtered_tag_list = filtered_keywords.clone(); + self.tag_list.tag_list_items = filtered_keywords; + self.tag_list.tag_scroll_state = ScrollbarState::content_length( + self.tag_list.tag_scroll_state, + self.tag_list.tag_list_items.len(), + ); + } + + // Filter the entry list by tags when hitting enter + // If already inside a filtered tag or entry list, apply the filtering + // to the already filtered list only + pub fn filter_for_tags(&mut self) { + let orig_list = &self.entry_table.entry_table_items; + let keyword = self.get_selected_tag(); + let filtered_list = BibiSearch::filter_entries_by_tag(&keyword, &orig_list); + // self.tag_list.selected_keyword = keyword.to_string(); + self.tag_list.selected_keywords.push(keyword.to_string()); + self.entry_table.entry_table_items = filtered_list; + // Update scrollbar state with new lenght of itemlist + self.entry_table.entry_scroll_state = ScrollbarState::content_length( + self.entry_table.entry_scroll_state, + self.entry_table.entry_table_items.len(), + ); + self.filter_tags_by_entries(); + self.toggle_area(); + self.entry_table.entry_table_state.select(Some(0)); + self.former_area = Some(FormerArea::TagArea); + } +} + +impl Bibiman { // Search Area // Enter the search area @@ -160,6 +519,7 @@ impl Bibiman { self.entry_table.entry_table_items.clone(); self.former_area = Some(FormerArea::EntryArea) } else if let CurrentArea::TagArea = self.current_area { + self.tag_list.tag_list_at_search_start = self.tag_list.tag_list_items.clone(); self.former_area = Some(FormerArea::TagArea) } self.current_area = CurrentArea::SearchArea @@ -169,24 +529,27 @@ impl Bibiman { pub fn confirm_search(&mut self) { if let Some(FormerArea::EntryArea) = self.former_area { self.current_area = CurrentArea::EntryArea; - self.entry_table.entry_table_state.select(Some(0)) + self.entry_table.entry_table_state.select(Some(0)); + self.entry_table.entry_table_at_search_start.clear(); } else if let Some(FormerArea::TagArea) = self.former_area { self.current_area = CurrentArea::TagArea; - self.tag_list.tag_list_state.select(Some(0)) + self.tag_list.tag_list_state.select(Some(0)); + self.tag_list.tag_list_at_search_start.clear(); } self.former_area = Some(FormerArea::SearchArea); self.search_struct.search_string.clear(); - self.entry_table.entry_table_at_search_start.clear(); } // Break search: leave search area without filtering list pub fn break_search(&mut self) { if let Some(FormerArea::EntryArea) = self.former_area { self.current_area = CurrentArea::EntryArea; - self.entry_table.entry_table_state.select(Some(0)) + self.entry_table.entry_table_state.select(Some(0)); + self.entry_table.entry_table_at_search_start.clear(); } else if let Some(FormerArea::TagArea) = self.former_area { self.current_area = CurrentArea::TagArea; - self.tag_list.tag_list_state.select(Some(0)) + self.tag_list.tag_list_state.select(Some(0)); + self.tag_list.tag_list_at_search_start.clear(); } // But keep filtering by tag if applied before entering search area if !self.search_struct.inner_search { @@ -195,7 +558,6 @@ impl Bibiman { self.former_area = None; // If search is canceled, reset default status of struct self.search_struct.search_string.clear(); - self.entry_table.entry_table_at_search_start.clear(); } // Remove last char from search pattern and filter list immidiately diff --git a/src/bibiman/keywords.rs b/src/bibiman/keywords.rs index 2668323..9f1d7d3 100644 --- a/src/bibiman/keywords.rs +++ b/src/bibiman/keywords.rs @@ -20,6 +20,7 @@ use ratatui::widgets::{ListState, ScrollbarState}; #[derive(Debug)] pub struct TagList { pub tag_list_items: Vec, + pub tag_list_at_search_start: Vec, pub tag_list_state: ListState, pub tag_scroll_state: ScrollbarState, pub selected_keywords: Vec, @@ -47,6 +48,7 @@ impl TagList { let tag_scroll_state = ScrollbarState::new(tag_list_items.len()); Self { tag_list_items, + tag_list_at_search_start: Vec::new(), tag_list_state, tag_scroll_state, selected_keywords: Vec::new(), diff --git a/src/bibiman/search.rs b/src/bibiman/search.rs index f6e8d14..3da5392 100644 --- a/src/bibiman/search.rs +++ b/src/bibiman/search.rs @@ -1,3 +1,20 @@ +// bibiman - a TUI for managing BibLaTeX databases +// Copyright (C) 2024 lukeflo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///// + use super::entries::EntryTableItem; use nucleo_matcher::{ pattern::{CaseMatching, Normalization, Pattern}, diff --git a/src/cliargs.rs b/src/cliargs.rs index d3a4652..9de2e7f 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -15,9 +15,9 @@ // along with this program. If not, see . ///// -use std::path::PathBuf; - use sarge::prelude::*; +use std::env; +use std::path::PathBuf; sarge! { // Name of the struct @@ -79,11 +79,14 @@ pub fn version_func() -> String { "\ {} {} {} -{}", +{} + +Target Triple: {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"), - env!("CARGO_PKG_LICENSE") + env!("CARGO_PKG_LICENSE"), + env!("TARGET") ); version } diff --git a/src/tui.rs b/src/tui.rs index a14a0ab..963abf9 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -15,9 +15,9 @@ // along with this program. If not, see . ///// -pub mod command; -pub mod commandnew; -pub mod handler; +// pub mod command; +pub mod commands; +// pub mod handler; pub mod ui; use crate::App; diff --git a/src/tui/command.rs b/src/tui/command.rs deleted file mode 100644 index 823a1dc..0000000 --- a/src/tui/command.rs +++ /dev/null @@ -1,374 +0,0 @@ -// bibiman - a TUI for managing BibLaTeX databases -// Copyright (C) 2024 lukeflo -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -///// - -use crate::bibiman::entries::EntryTableColumn; -use crate::bibiman::search::BibiSearch; -use crate::bibiman::{Bibiman, FormerArea}; -use crate::tui::Tui; -use color_eyre::eyre::{Context, Ok, Result}; -use core::panic; -use editor_command::EditorBuilder; -use ratatui::widgets::ScrollbarState; -use std::process::{Command, Stdio}; - -impl Bibiman { - // Entry Table commands - - /// Select next entry in Table holding the bibliographic entries. - /// - /// Takes u16 value as argument to specify number of entries which - /// should be scrolled - pub fn select_next_entry(&mut self, entries: u16) { - self.entry_table.entry_info_scroll = 0; - self.entry_table.entry_info_scroll_state = - self.entry_table.entry_info_scroll_state.position(0); - self.entry_table.entry_table_state.scroll_down_by(entries); - self.entry_table.entry_scroll_state = self - .entry_table - .entry_scroll_state - .position(self.entry_table.entry_table_state.selected().unwrap()); - } - - /// Select previous entry in Table holding the bib entries. - /// - /// Takes u16 value as argument to specify number of entries which - /// should be scrolled - pub fn select_previous_entry(&mut self, entries: u16) { - self.entry_table.entry_info_scroll = 0; - self.entry_table.entry_info_scroll_state = - self.entry_table.entry_info_scroll_state.position(0); - self.entry_table.entry_table_state.scroll_up_by(entries); - self.entry_table.entry_scroll_state = self - .entry_table - .entry_scroll_state - .position(self.entry_table.entry_table_state.selected().unwrap()); - } - - /// Select first entry in bib list - pub fn select_first_entry(&mut self) { - self.entry_table.entry_info_scroll = 0; - self.entry_table.entry_info_scroll_state = - self.entry_table.entry_info_scroll_state.position(0); - self.entry_table.entry_table_state.select_first(); - self.entry_table.entry_scroll_state = self.entry_table.entry_scroll_state.position(0); - } - - /// Select last entry in bib list - pub fn select_last_entry(&mut self) { - self.entry_table.entry_info_scroll = 0; - self.entry_table.entry_info_scroll_state = - self.entry_table.entry_info_scroll_state.position(0); - self.entry_table.entry_table_state.select_last(); - self.entry_table.entry_scroll_state = self - .entry_table - .entry_scroll_state - .position(self.entry_table.entry_table_items.len()); - } - - /// Select next (right) column of entry table - pub fn select_next_column(&mut self) { - match self.entry_table.entry_table_selected_column { - EntryTableColumn::Authors => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Title; - } - EntryTableColumn::Title => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Year; - } - EntryTableColumn::Year => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Pubtype; - } - EntryTableColumn::Pubtype => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Authors; - } - } - } - - /// Select previous (left) column of entry table - pub fn select_prev_column(&mut self) { - match self.entry_table.entry_table_selected_column { - EntryTableColumn::Authors => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Pubtype; - } - EntryTableColumn::Title => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Authors; - } - EntryTableColumn::Year => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Title; - } - EntryTableColumn::Pubtype => { - self.entry_table.entry_table_selected_column = EntryTableColumn::Year; - } - } - } - - // Get the citekey of the selected entry - pub fn get_selected_citekey(&self) -> &str { - let idx = self.entry_table.entry_table_state.selected().unwrap(); - let citekey = &self.entry_table.entry_table_items[idx].citekey; - citekey - } - - pub fn run_editor(&mut self, tui: &mut Tui) -> Result<()> { - // get filecontent and citekey for calculating line number - let citekey = self.get_selected_citekey(); - // create independent copy of citekey for finding entry after updating list - let saved_key = citekey.to_owned(); - let filepath = self.main_biblio.bibfile.display().to_string(); - let filecontent = self.main_biblio.bibfilestring.clone(); - let mut line_count = 0; - - for line in filecontent.lines() { - line_count = line_count + 1; - // if reaching the citekey break the loop - // if reaching end of lines without match, reset to 0 - if line.contains(&citekey) { - break; - } else if line_count == filecontent.len() { - eprintln!( - "Citekey {} not found, opening file {} at line 1", - &citekey, &filepath - ); - line_count = 0; - break; - } - } - - // Exit TUI to enter editor - tui.exit()?; - // Use VISUAL or EDITOR. Set "vi" as last fallback - let mut cmd: Command = EditorBuilder::new() - .environment() - .source(Some("vi")) - .build() - .unwrap(); - // Prepare arguments to open file at specific line - let args: Vec = vec![format!("+{}", line_count), filepath]; - let status = cmd.args(&args).status()?; - if !status.success() { - eprintln!("Spawning editor failed with status {}", status); - } - - // Enter TUI again - tui.enter()?; - tui.terminal.clear()?; - - // Update the database and the lists to show changes - self.update_lists(); - - // Search for entry, selected before editing, by matching citekeys - // Use earlier saved copy of citekey to match - let mut idx_count = 0; - loop { - if self.entry_table.entry_table_items[idx_count] - .citekey - .contains(&saved_key) - { - break; - } - idx_count = idx_count + 1 - } - - // Set selected entry to vec-index of match - self.entry_table.entry_table_state.select(Some(idx_count)); - - Ok(()) - } - - // Search entry list - pub fn search_entries(&mut self) { - // Use snapshot of entry list saved when starting the search - // so deleting a char, will show former entries too - let orig_list = self.entry_table.entry_table_at_search_start.clone(); - let filtered_list = - BibiSearch::search_entry_list(&mut self.search_struct.search_string, orig_list.clone()); - self.entry_table.entry_table_items = filtered_list; - if self.entry_table.entry_table_reversed_sort { - self.entry_table.sort_entry_table(false); - } - self.entry_table.entry_scroll_state = ScrollbarState::content_length( - self.entry_table.entry_scroll_state, - self.entry_table.entry_table_items.len(), - ); - } - - // Open file connected with entry through 'file' or 'pdf' field - pub fn open_connected_file(&mut self) -> Result<()> { - let idx = self.entry_table.entry_table_state.selected().unwrap(); - let filepath = &self.entry_table.entry_table_items[idx].filepath.clone(); - - // Build command to execute pdf-reader. 'xdg-open' is Linux standard - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } - }; - - // Pass filepath as argument, pipe stdout and stderr to /dev/null - // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) - .arg(&filepath) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn() - .wrap_err("Opening file not possible"); - - Ok(()) - } - - pub fn open_doi_url(&mut self) -> Result<()> { - let idx = self.entry_table.entry_table_state.selected().unwrap(); - let web_adress = self.entry_table.entry_table_items[idx].doi_url.clone(); - - // Resolve strings using the resolving function of dx.doi.org, so the - // terminal is not blocked by the resolving process - let url = if web_adress.starts_with("10.") { - let prefix = "https://doi.org/".to_string(); - prefix + &web_adress - } else if web_adress.starts_with("www.") { - let prefix = "https://".to_string(); - prefix + &web_adress - } else { - web_adress - }; - - // Build command to execute browser. 'xdg-open' is Linux standard - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } - }; - - // Pass filepath as argument, pipe stdout and stderr to /dev/null - // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) - .arg(url) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn() - .wrap_err("Opening file not possible"); - - Ok(()) - } -} - -impl Bibiman { - // Tag List commands - - // Movement - pub fn select_next_tag(&mut self, keywords: u16) { - self.tag_list.tag_list_state.scroll_down_by(keywords); - self.tag_list.tag_scroll_state = self - .tag_list - .tag_scroll_state - .position(self.tag_list.tag_list_state.selected().unwrap()); - } - - pub fn select_previous_tag(&mut self, keywords: u16) { - self.tag_list.tag_list_state.scroll_up_by(keywords); - self.tag_list.tag_scroll_state = self - .tag_list - .tag_scroll_state - .position(self.tag_list.tag_list_state.selected().unwrap()); - } - - pub fn select_first_tag(&mut self) { - self.tag_list.tag_list_state.select_first(); - self.tag_list.tag_scroll_state = self.tag_list.tag_scroll_state.position(0); - } - - pub fn select_last_tag(&mut self) { - self.tag_list.tag_list_state.select_last(); - self.tag_list.tag_scroll_state = self - .tag_list - .tag_scroll_state - .position(self.tag_list.tag_list_items.len()); - } - - pub fn get_selected_tag(&self) -> &str { - let idx = self.tag_list.tag_list_state.selected().unwrap(); - let keyword = &self.tag_list.tag_list_items[idx]; - // let keyword = &self.tag_list.tag_list_items[idx].keyword; - keyword - } - - pub fn search_tags(&mut self) { - let orig_list = &self.main_biblio.keyword_list; - let filtered_list = - BibiSearch::search_tag_list(&self.search_struct.search_string, orig_list.clone()); - self.tag_list.tag_list_items = filtered_list; - // Update scrollbar length after filtering list - self.tag_list.tag_scroll_state = ScrollbarState::content_length( - self.tag_list.tag_scroll_state, - self.tag_list.tag_list_items.len(), - ); - } - - pub fn filter_tags_by_entries(&mut self) { - let mut filtered_keywords: Vec = Vec::new(); - - let orig_list = &self.entry_table.entry_table_items; - - for e in orig_list { - if !e.keywords.is_empty() { - let mut key_vec: Vec = e - .keywords - .split(',') - .map(|s| s.trim().to_string()) - .filter(|s| !s.is_empty()) - .collect(); - filtered_keywords.append(&mut key_vec); - } - } - - filtered_keywords.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase())); - filtered_keywords.dedup(); - - self.search_struct.filtered_tag_list = filtered_keywords.clone(); - self.tag_list.tag_list_items = filtered_keywords; - self.tag_list.tag_scroll_state = ScrollbarState::content_length( - self.tag_list.tag_scroll_state, - self.tag_list.tag_list_items.len(), - ); - } - - // Filter the entry list by tags when hitting enter - // If already inside a filtered tag or entry list, apply the filtering - // to the already filtered list only - pub fn filter_for_tags(&mut self) { - let orig_list = &self.entry_table.entry_table_items; - let keyword = self.get_selected_tag(); - let filtered_list = BibiSearch::filter_entries_by_tag(&keyword, &orig_list); - // self.tag_list.selected_keyword = keyword.to_string(); - self.tag_list.selected_keywords.push(keyword.to_string()); - self.entry_table.entry_table_items = filtered_list; - // Update scrollbar state with new lenght of itemlist - self.entry_table.entry_scroll_state = ScrollbarState::content_length( - self.entry_table.entry_scroll_state, - self.entry_table.entry_table_items.len(), - ); - self.filter_tags_by_entries(); - self.toggle_area(); - self.entry_table.entry_table_state.select(Some(0)); - self.former_area = Some(FormerArea::TagArea); - } -} diff --git a/src/tui/commandnew.rs b/src/tui/commandnew.rs deleted file mode 100644 index 1f70264..0000000 --- a/src/tui/commandnew.rs +++ /dev/null @@ -1,191 +0,0 @@ -// bibiman - a TUI for managing BibLaTeX databases -// Copyright (C) 2024 lukeflo -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -///// - -use ratatui::crossterm::event::{ - Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind, -}; -use tui_input::Input; - -// Possible ressources to open -#[derive(Debug, PartialEq, Eq)] -pub enum OpenRessource { - Pdf, - WebLink, - Note, -} - -/// Application command. -#[derive(Debug, PartialEq, Eq)] -pub enum CmdAction { - // Toggle area - ToggleArea, - // Scroll list/table down - SelectNextRow(u16), - // Scroll list/table up. - SelectPrevRow(u16), - // Select nex table col. - SelectNextCol, - // Select previous table col. - SelectPrevCol, - // Scroll info/preview area down - ScrollInfoDown, - // Scroll info/preview area up - ScrollInfoUp, - // Go to top. - Top, - // Go to bottom. - Bottom, - // Search list - SearchList, - // Reset lists - ResetList, - // Confirm search/selection - Confirm, - // Sort table/list - SortList, - // Yank selected item - YankItem, - // Edit file - EditFile, - // Open linked ressource - Open(OpenRessource), - // Input command. - Input(InputCmdAction), - // Hexdump command. - Exit, - // Do nothing. - Nothing, -} - -impl From for CmdAction { - fn from(key_event: KeyEvent) -> Self { - match key_event.code { - // Go to first/last entry of selected list/table - KeyCode::Char('g') | KeyCode::Home => Self::Top, - KeyCode::Char('G') | KeyCode::End => Self::Bottom, - // Scroll columns of EntryTable - KeyCode::Right | KeyCode::Char('l') => Self::SelectNextCol, - KeyCode::Left | KeyCode::Char('h') => Self::SelectPrevCol, - // Scroll table/list vertically by 1 - KeyCode::Down | KeyCode::Char('j') => { - if key_event.modifiers == KeyModifiers::ALT { - Self::ScrollInfoDown - } else { - Self::SelectNextRow(1) - } - } - KeyCode::Up | KeyCode::Char('k') => { - if key_event.modifiers == KeyModifiers::ALT { - Self::ScrollInfoUp - } else { - Self::SelectPrevRow(1) - } - } - // Scroll table/list vertically by 5 - KeyCode::Char('d') => { - if key_event.modifiers == KeyModifiers::CONTROL { - Self::SelectNextRow(5) - } else { - Self::Nothing - } - } - KeyCode::Char('u') => { - if key_event.modifiers == KeyModifiers::CONTROL { - Self::SelectPrevRow(5) - } else { - Self::Open(OpenRessource::WebLink) - } - } - // Scroll info/preview area - KeyCode::PageDown => Self::ScrollInfoDown, - KeyCode::PageUp => Self::ScrollInfoUp, - // Exit App - KeyCode::Char('q') => Self::Exit, - KeyCode::Char('c') | KeyCode::Char('C') => { - if key_event.modifiers == KeyModifiers::CONTROL { - Self::Exit - } else { - Self::Nothing - } - } - // Switch selected area - KeyCode::Tab => Self::ToggleArea, - KeyCode::BackTab => Self::ToggleArea, - // Enter search mode - KeyCode::Char('/') => Self::Input(InputCmdAction::Enter), - KeyCode::Char('f') => { - if key_event.modifiers == KeyModifiers::CONTROL { - Self::Input(InputCmdAction::Enter) - } else { - Self::Nothing - } - } - // KeyCode::Backspace => Self::Input(InputCommand::Resume(Event::Key(key_event))), - // Confirm selection - KeyCode::Enter => Self::Confirm, - // Reset lists/tables - KeyCode::Esc => Self::ResetList, - // Open linked ressource - KeyCode::Char('o') => Self::Open(OpenRessource::Pdf), - // KeyCode::Char('u') => Self::Open(OpenRessource::WebLink), - // Edit currently selected entry - KeyCode::Char('e') => Self::EditFile, - // Yank selected item/value - KeyCode::Char('y') => Self::YankItem, - // Else do nothing - _ => Self::Nothing, - } - } -} - -impl From for CmdAction { - fn from(mouse_event: MouseEvent) -> Self { - match mouse_event.kind { - MouseEventKind::ScrollDown => Self::SelectNextRow(1), - MouseEventKind::ScrollUp => Self::SelectPrevRow(1), - _ => Self::Nothing, - } - } -} - -/// Input mode command. -#[derive(Debug, PartialEq, Eq)] -pub enum InputCmdAction { - // Handle input. - Handle(Event), - // Enter input mode. - Enter, - // Confirm input. - Confirm, - // Exit input mode - Exit, -} - -impl InputCmdAction { - /// Parses the event. - pub fn parse(key_event: KeyEvent, input: &Input) -> Self { - if key_event.code == KeyCode::Esc - || (key_event.code == KeyCode::Backspace && input.value().is_empty()) - { - Self::Exit - } else if key_event.code == KeyCode::Enter { - Self::Confirm - } else { - Self::Handle(Event::Key(key_event)) - } - } -} diff --git a/src/tui/commands.rs b/src/tui/commands.rs new file mode 100644 index 0000000..dc6b2c8 --- /dev/null +++ b/src/tui/commands.rs @@ -0,0 +1,195 @@ +// bibiman - a TUI for managing BibLaTeX databases +// Copyright (C) 2024 lukeflo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///// + +use ratatui::crossterm::event::{ + Event, KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind, +}; +use tui_input::Input; + +// Possible ressources to open +#[derive(Debug, PartialEq, Eq)] +pub enum OpenRessource { + Pdf, + WebLink, + Note, +} + +/// Application command. +#[derive(Debug, PartialEq, Eq)] +pub enum CmdAction { + // Toggle area + ToggleArea, + // Scroll list/table down + SelectNextRow(u16), + // Scroll list/table up. + SelectPrevRow(u16), + // Select nex table col. + SelectNextCol, + // Select previous table col. + SelectPrevCol, + // Scroll info/preview area down + ScrollInfoDown, + // Scroll info/preview area up + ScrollInfoUp, + // Go to top. + Top, + // Go to bottom. + Bottom, + // Search list + SearchList, + // Reset lists + ResetList, + // Confirm search/selection + Confirm, + // Sort table/list + SortList, + // Yank selected item + YankItem, + // Edit file + EditFile, + // Open linked ressource + Open(OpenRessource), + // Input command. + Input(InputCmdAction), + // Hexdump command. + Exit, + // Do nothing. + Nothing, +} + +impl From for CmdAction { + fn from(key_event: KeyEvent) -> Self { + match key_event.code { + // Go to first/last entry of selected list/table + KeyCode::Char('g') | KeyCode::Home => Self::Top, + KeyCode::Char('G') | KeyCode::End => Self::Bottom, + // Scroll columns of EntryTable + KeyCode::Right | KeyCode::Char('l') => Self::SelectNextCol, + KeyCode::Left | KeyCode::Char('h') => Self::SelectPrevCol, + // Scroll table/list vertically by 1 + KeyCode::Down | KeyCode::Char('j') => { + if key_event.modifiers == KeyModifiers::ALT { + Self::ScrollInfoDown + } else { + Self::SelectNextRow(1) + } + } + KeyCode::Up | KeyCode::Char('k') => { + if key_event.modifiers == KeyModifiers::ALT { + Self::ScrollInfoUp + } else { + Self::SelectPrevRow(1) + } + } + // Scroll table/list vertically by 5 + KeyCode::Char('d') => { + if key_event.modifiers == KeyModifiers::CONTROL { + Self::SelectNextRow(5) + } else { + Self::Nothing + } + } + KeyCode::Char('u') => { + if key_event.modifiers == KeyModifiers::CONTROL { + Self::SelectPrevRow(5) + } else { + Self::Open(OpenRessource::WebLink) + } + } + // Scroll info/preview area + KeyCode::PageDown => Self::ScrollInfoDown, + KeyCode::PageUp => Self::ScrollInfoUp, + // Exit App + KeyCode::Char('q') => Self::Exit, + KeyCode::Char('c') | KeyCode::Char('C') => { + if key_event.modifiers == KeyModifiers::CONTROL { + Self::Exit + } else { + Self::Nothing + } + } + // Switch selected area + KeyCode::Tab => Self::ToggleArea, + KeyCode::BackTab => Self::ToggleArea, + // Enter search mode + KeyCode::Char('/') => Self::Input(InputCmdAction::Enter), + KeyCode::Char('f') => { + if key_event.modifiers == KeyModifiers::CONTROL { + Self::Input(InputCmdAction::Enter) + } else { + Self::Nothing + } + } + // KeyCode::Backspace => Self::Input(InputCommand::Resume(Event::Key(key_event))), + // Confirm selection + KeyCode::Enter => Self::Confirm, + // Reset lists/tables + KeyCode::Esc => Self::ResetList, + // Open linked ressource + KeyCode::Char('o') => Self::Open(OpenRessource::Pdf), + // KeyCode::Char('u') => Self::Open(OpenRessource::WebLink), + // Edit currently selected entry + KeyCode::Char('e') => Self::EditFile, + // Yank selected item/value + KeyCode::Char('y') => Self::YankItem, + // Sort entry table by selected col + KeyCode::Char('s') => Self::SortList, + // Else do nothing + _ => Self::Nothing, + } + } +} + +impl From for CmdAction { + fn from(mouse_event: MouseEvent) -> Self { + match mouse_event.kind { + MouseEventKind::ScrollDown => Self::SelectNextRow(1), + MouseEventKind::ScrollUp => Self::SelectPrevRow(1), + _ => Self::Nothing, + } + } +} + +/// Input mode command. +#[derive(Debug, PartialEq, Eq)] +pub enum InputCmdAction { + // Handle input. + Handle(Event), + // Enter input mode. + Enter, + // Confirm input. + Confirm, + // Exit input mode + Exit, + // Do nothing + Nothing, +} + +impl InputCmdAction { + /// Parses the event. + pub fn parse(key_event: KeyEvent, input: &Input) -> Self { + if key_event.code == KeyCode::Backspace && input.value().is_empty() { + Self::Nothing + } else if key_event.code == KeyCode::Esc { + Self::Exit + } else if key_event.code == KeyCode::Enter { + Self::Confirm + } else { + Self::Handle(Event::Key(key_event)) + } + } +} diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 9e561c3..507177b 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -32,7 +32,6 @@ use ratatui::{ ScrollbarOrientation, Table, Wrap, }, }; -use tui_input::Input; const MAIN_BLUE_COLOR: Color = Color::Indexed(39); // const MAIN_PURPLE_COLOR: Color = Color::Indexed(129); @@ -99,14 +98,6 @@ pub fn render_ui(app: &mut App, frame: &mut Frame) { render_entrytable(app, frame, entry_area); render_selected_item(app, frame, info_area); render_taglist(app, frame, tag_area); - // Bibiman::render_header(header_area, buf); - // self.bibiman.render_footer(footer_area, buf); - // Render list area where entry gets selected - // self.bibiman.render_entrytable(entry_area, buf); - // self.bibiman.render_file_info(entry_info_area, buf); - // Render infos related to selected entry - // self.bibiman.render_taglist(tag_area, buf); - // self.bibiman.render_selected_item(info_area, buf); } pub fn render_header(frame: &mut Frame, rect: Rect) { @@ -141,11 +132,13 @@ pub fn render_footer(app: &mut App, frame: &mut Frame, rect: Rect) { .title(Line::styled(search_title, BOX_SELECTED_TITLE_STYLE)) .border_style(BOX_SELECTED_BOX_STYLE) .border_set(symbols::border::THICK); + render_cursor(app, frame, rect); frame.render_widget( - Paragraph::new(app.bibiman.search_struct.search_string.clone()).block(block), + Paragraph::new(app.bibiman.search_struct.search_string.clone()) + .block(block) + .fg(TEXT_FG_COLOR), rect, ); - render_cursor(app, frame, rect); } _ => { let style_emph = Style::new().bold().fg(TEXT_FG_COLOR); @@ -244,13 +237,28 @@ pub fn render_file_info(app: &mut App, frame: &mut Frame, rect: Rect) { { vec![ Span::raw( - (app.bibiman + // Because method scroll_down_by() of TableState lets numbers + // printed overflow for short moment, we have to check manually + // that we do not print a number higher than len() of table + if app + .bibiman .entry_table .entry_table_state .selected() .unwrap() - + 1) - .to_string(), + + 1 + > app.bibiman.entry_table.entry_table_items.len() + { + app.bibiman.entry_table.entry_table_items.len().to_string() + } else { + (app.bibiman + .entry_table + .entry_table_state + .selected() + .unwrap() + + 1) + .to_string() + }, ) .bold(), Span::raw("/"), @@ -671,6 +679,7 @@ pub fn render_taglist(app: &mut App, frame: &mut Frame, rect: Rect) { let list = List::new(items) .block(block) .highlight_style(SELECTED_STYLE) + .fg(TEXT_FG_COLOR) // .highlight_symbol("> ") .highlight_spacing(HighlightSpacing::Always); @@ -705,13 +714,10 @@ pub fn render_taglist(app: &mut App, frame: &mut Frame, rect: Rect) { /// Render the cursor when in InputMode fn render_cursor(app: &mut App, frame: &mut Frame, area: Rect) { + let scroll = app.input.visual_scroll(area.width as usize); if app.input_mode { let (x, y) = ( - area.x - + Input::default() - .with_value(app.input.value().to_string()) - .visual_cursor() as u16 - + 1, + area.x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + 1, area.bottom().saturating_sub(2), ); frame.render_widget( -- cgit v1.2.3