aboutsummaryrefslogtreecommitdiff
path: root/src/tui/ui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tui/ui.rs')
-rw-r--r--src/tui/ui.rs51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 921cbb1..2126135 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -24,6 +24,7 @@ use crate::cliargs::CLIArgs;
use crate::config::BibiConfig;
use crate::tui::popup::PopupKind;
use crate::App;
+use itertools::Itertools;
use ratatui::layout::{Direction, Position};
use ratatui::widgets::Clear;
use ratatui::Frame;
@@ -278,7 +279,14 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.popup_area
.popup_list
.iter()
- .map(|item| ListItem::from(item.to_owned()))
+ .map(
+ |(mes, obj)| {
+ ListItem::from(Line::from(vec![
+ Span::styled(mes, Style::new().bold()),
+ Span::raw(obj),
+ ]))
+ }, // ListItem::from(mes.to_owned() + obj)
+ )
.collect();
let title = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind {
@@ -310,7 +318,33 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.add_modifier(Modifier::REVERSED),
);
- let popup_width = frame.area().width / 2;
+ // To find the longest line, we need to collect the chars of every item
+ // and add.
+ let list_widths = app
+ .bibiman
+ .popup_area
+ .popup_list
+ .iter()
+ .max_by(|(mes, obj), (m, o)| {
+ let x = mes.chars().count() + obj.chars().count();
+ let y = m.chars().count() + o.chars().count();
+ x.cmp(&y)
+ })
+ .unwrap();
+ // .map(|(m, o)| m.chars().count() as u16 + o.chars().count() as u16)
+ // .collect();
+
+ // Now take the max number for the width of the popup
+ // let max_item = list_widths.iter().max().unwrap().to_owned();
+ let max_item =
+ list_widths.0.chars().count() as u16 + list_widths.1.chars().count() as u16;
+
+ // Check if the popup would exceed the terminal frame width
+ let popup_width = if max_item + 2 > frame.area().width - 2 {
+ frame.area().width - 2
+ } else {
+ max_item + 2
+ };
let popup_heigth = list.len() + 2;
let popup_area = popup_area(frame.area(), popup_width, popup_heigth as u16);
@@ -833,15 +867,24 @@ pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame,
),
]));
}
- if cur_entry.filepath.is_some() {
+ if let Some(p) = &cur_entry.filepath {
lines.push(Line::from(vec![
Span::styled("File: ", style_value),
Span::styled(
- cur_entry.filepath().to_string_lossy(),
+ p.iter().map(|f| f.to_str().unwrap()).join("; "),
Style::new().fg(cfg.colors.main_text_color),
),
]));
}
+ // if cur_entry.filepath.is_some() {
+ // lines.push(Line::from(vec![
+ // Span::styled("File: ", style_value),
+ // Span::styled(
+ // cur_entry.filepath().to_string_lossy(),
+ // Style::new().fg(cfg.colors.main_text_color),
+ // ),
+ // ]));
+ // }
lines.push(Line::from(""));
lines.push(Line::from(vec![Span::styled(
cur_entry.abstract_text.clone(),