aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.rs48
-rw-r--r--src/bibiman.rs23
-rw-r--r--src/tui/commands.rs4
-rw-r--r--src/tui/popup.rs12
-rw-r--r--src/tui/ui.rs41
5 files changed, 93 insertions, 35 deletions
diff --git a/src/app.rs b/src/app.rs
index c256542..81a5b55 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -70,10 +70,11 @@ impl App {
// Event::Mouse(_) => {}
Event::Key(key_event) => {
if let Some(PopupKind::Message) = self.bibiman.popup_area.popup_kind {
- self.bibiman.popup_area.popup_close_message()
- } else if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
- self.bibiman.go_back()
+ self.bibiman.close_popup()
}
+ // else if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
+ // self.bibiman.go_back()
+ // }
let command = if self.input_mode {
CmdAction::Input(InputCmdAction::parse(key_event, &self.input))
} else {
@@ -137,6 +138,13 @@ impl App {
CurrentArea::TagArea => {
self.bibiman.select_next_tag(amount);
}
+ CurrentArea::PopupArea => {
+ if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
+ // self.bibiman.popup_area.popup_scroll_pos =
+ // self.bibiman.popup_area.popup_scroll_pos + 1
+ self.bibiman.popup_area.popup_scroll_down();
+ }
+ }
_ => {}
},
CmdAction::SelectPrevRow(amount) => match self.bibiman.current_area {
@@ -147,6 +155,13 @@ impl App {
CurrentArea::TagArea => {
self.bibiman.select_previous_tag(amount);
}
+ CurrentArea::PopupArea => {
+ if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
+ // self.bibiman.popup_area.popup_scroll_pos =
+ // self.bibiman.popup_area.popup_scroll_pos - 1
+ self.bibiman.popup_area.popup_scroll_up();
+ }
+ }
_ => {}
},
CmdAction::SelectNextCol => {
@@ -187,14 +202,23 @@ impl App {
self.bibiman.toggle_area();
}
CmdAction::SearchList => {}
- CmdAction::ResetList => {
- self.bibiman.reset_current_list();
+ CmdAction::Reset => {
+ if let CurrentArea::PopupArea = self.bibiman.current_area {
+ if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
+ self.bibiman.popup_area.popup_scroll_pos = 0;
+ self.bibiman.close_popup()
+ }
+ } else {
+ self.bibiman.reset_current_list();
+ }
}
CmdAction::Confirm => {
if let CurrentArea::TagArea = self.bibiman.current_area {
self.bibiman.filter_for_tags();
} else if let CurrentArea::PopupArea = self.bibiman.current_area {
- self.bibiman.go_back();
+ if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
+ self.bibiman.close_popup();
+ }
}
}
CmdAction::SortList => {
@@ -203,11 +227,13 @@ impl App {
}
}
CmdAction::YankItem => {
- Bibiman::yank_text(&self.bibiman.get_selected_citekey());
- self.bibiman.popup_area.popup_message(
- "Yanked citekey to clipboard:",
- self.bibiman.get_selected_citekey().to_string(),
- );
+ if let CurrentArea::EntryArea = self.bibiman.current_area {
+ Bibiman::yank_text(&self.bibiman.get_selected_citekey());
+ self.bibiman.popup_area.popup_message(
+ "Yanked citekey to clipboard:",
+ self.bibiman.get_selected_citekey().to_string(),
+ );
+ }
}
CmdAction::EditFile => {
if let CurrentArea::EntryArea = self.bibiman.current_area {
diff --git a/src/bibiman.rs b/src/bibiman.rs
index f3d9272..ed6a66f 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -108,16 +108,19 @@ impl Bibiman {
self.popup_area.popup_kind = Some(PopupKind::Help);
}
- pub fn go_back(&mut self) {
- if let CurrentArea::PopupArea = self.current_area {
- self.popup_area.is_popup = false;
- self.popup_area.popup_kind = None;
- if let Some(FormerArea::EntryArea) = self.former_area {
- self.current_area = CurrentArea::EntryArea
- } else if let Some(FormerArea::TagArea) = self.former_area {
- self.current_area = CurrentArea::TagArea
- }
- };
+ pub fn close_popup(&mut self) {
+ // Reset all popup fields to default values
+ self.popup_area = PopupArea::default();
+
+ // Go back to previously selected area
+ if let Some(FormerArea::EntryArea) = self.former_area {
+ self.current_area = CurrentArea::EntryArea
+ } else if let Some(FormerArea::TagArea) = self.former_area {
+ self.current_area = CurrentArea::TagArea
+ }
+
+ // Clear former_area field
+ self.former_area = None;
}
pub fn update_lists(&mut self) {
diff --git a/src/tui/commands.rs b/src/tui/commands.rs
index 6a2ab13..a9566d0 100644
--- a/src/tui/commands.rs
+++ b/src/tui/commands.rs
@@ -52,7 +52,7 @@ pub enum CmdAction {
// Search list
SearchList,
// Reset lists
- ResetList,
+ Reset,
// Confirm search/selection
Confirm,
// Sort table/list
@@ -140,7 +140,7 @@ impl From<KeyEvent> for CmdAction {
// Confirm selection
KeyCode::Enter => Self::Confirm,
// Reset lists/tables
- KeyCode::Esc => Self::ResetList,
+ KeyCode::Esc => Self::Reset,
// Open linked ressource
KeyCode::Char('o') => Self::Open(OpenRessource::Pdf),
// KeyCode::Char('u') => Self::Open(OpenRessource::WebLink),
diff --git a/src/tui/popup.rs b/src/tui/popup.rs
index 20ff467..fe76956 100644
--- a/src/tui/popup.rs
+++ b/src/tui/popup.rs
@@ -35,6 +35,7 @@ pub struct PopupArea {
pub is_popup: bool,
pub popup_kind: Option<PopupKind>,
pub popup_message: String,
+ pub popup_scroll_pos: u16,
pub popup_list: Vec<String>,
pub popup_state: ListState,
}
@@ -45,6 +46,7 @@ impl Default for PopupArea {
is_popup: false,
popup_kind: None,
popup_message: String::new(),
+ popup_scroll_pos: 0,
popup_list: Vec::new(),
popup_state: ListState::default(),
}
@@ -146,9 +148,11 @@ impl PopupArea {
self.is_popup = true;
}
- pub fn popup_close_message(&mut self) {
- self.is_popup = false;
- self.popup_message.clear();
- self.popup_kind = None
+ pub fn popup_scroll_down(&mut self) {
+ self.popup_scroll_pos = self.popup_scroll_pos.saturating_add(1)
+ }
+
+ pub fn popup_scroll_up(&mut self) {
+ self.popup_scroll_pos = self.popup_scroll_pos.saturating_sub(1)
}
}
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 260f401..dd08291 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -37,7 +37,7 @@ use ratatui::{
ScrollbarOrientation, Table, Wrap,
},
};
-use tui_popup::Popup;
+use tui_popup::{Popup, SizedWrapper};
// Text colors
const TEXT_FG_COLOR: Color = Color::Indexed(TEXT_FG_COLOR_INDEX);
@@ -151,19 +151,44 @@ pub fn render_ui(app: &mut App, frame: &mut Frame) {
}
pub fn render_popup(app: &mut App, frame: &mut Frame) {
- let popup = if let Some(PopupKind::Help) = app.bibiman.popup_area.popup_kind {
- Popup::new(PopupArea::popup_help())
+ if let Some(PopupKind::Help) = app.bibiman.popup_area.popup_kind {
+ let text: Text = Text::from(PopupArea::popup_help());
+
+ // Calculate max scroll position depending on hight of terminal window
+ let scroll_pos = if app.bibiman.popup_area.popup_scroll_pos
+ > text.lines.len() as u16 - (frame.area().height / 2)
+ {
+ app.bibiman.popup_area.popup_scroll_pos =
+ text.lines.len() as u16 - (frame.area().height / 2);
+ app.bibiman.popup_area.popup_scroll_pos
+ } else {
+ app.bibiman.popup_area.popup_scroll_pos
+ };
+
+ let par = Paragraph::new(text).scroll((scroll_pos, 0));
+
+ // Needed to use scrollable Parapgraph as popup content
+ let sized_par = SizedWrapper {
+ inner: par,
+ width: (frame.area().width / 2) as usize,
+ height: (frame.area().height / 2) as usize,
+ };
+
+ let popup = Popup::new(sized_par)
.title(" Keybindings ".bold().into_centered_line())
.style(POPUP_HELP_BOX)
- .border_style(Style::new().fg(MAIN_BLUE))
+ .border_style(Style::new().fg(MAIN_BLUE));
+
+ frame.render_widget_ref(popup, frame.area())
} else if let Some(PopupKind::Message) = app.bibiman.popup_area.popup_kind {
- Popup::new(Text::from(app.bibiman.popup_area.popup_message.as_str()).fg(MAIN_GREEN))
- .title(" Message ".bold().into_centered_line().fg(MAIN_GREEN))
- .style(POPUP_HELP_BOX)
+ let popup =
+ Popup::new(Text::from(app.bibiman.popup_area.popup_message.as_str()).fg(MAIN_GREEN))
+ .title(" Message ".bold().into_centered_line().fg(MAIN_GREEN))
+ .style(POPUP_HELP_BOX);
+ frame.render_widget(&popup, frame.area())
} else {
panic!("No popup text detected")
};
- frame.render_widget(&popup, frame.area())
}
pub fn render_header(frame: &mut Frame, rect: Rect) {