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.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 9cbd075..a998bc7 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -279,7 +279,14 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.popup_area
.popup_list
.iter()
- .map(|(mes, obj)| ListItem::from(mes.to_owned() + obj))
+ .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 {
@@ -311,7 +318,25 @@ 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: Vec<u16> = app
+ .bibiman
+ .popup_area
+ .popup_list
+ .iter()
+ .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();
+
+ // 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);