aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.rs30
-rw-r--r--src/bibiman.rs17
-rw-r--r--src/tui/popup.rs16
-rw-r--r--src/tui/ui.rs16
4 files changed, 62 insertions, 17 deletions
diff --git a/src/app.rs b/src/app.rs
index f912614..d645dbe 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -19,7 +19,7 @@ use crate::bibiman::CurrentArea;
use crate::cliargs::CLIArgs;
use crate::config::BibiConfig;
use crate::tui::commands::InputCmdAction;
-use crate::tui::popup::PopupKind;
+use crate::tui::popup::{PopupItem, PopupKind};
use crate::tui::{self, Tui};
use crate::{bibiman::Bibiman, tui::commands::CmdAction};
use color_eyre::eyre::{Context, Ok, Result};
@@ -311,13 +311,25 @@ impl App {
.selected()
.unwrap();
let entry = self.bibiman.entry_table.entry_table_items[idx].clone();
- let mut items = vec![("Citekey: ".to_string(), entry.citekey.clone())];
+ let mut items = vec![(
+ "Citekey: ".to_string(),
+ entry.citekey.clone(),
+ PopupItem::Default,
+ )];
if entry.doi_url.is_some() {
- items.push(("Weblink: ".into(), entry.doi_url.unwrap().clone()))
+ items.push((
+ "Weblink: ".into(),
+ entry.doi_url.unwrap().clone(),
+ PopupItem::Link,
+ ))
}
if entry.filepath.is_some() {
entry.filepath.unwrap().iter().for_each(|p| {
- items.push(("Filepath: ".into(), p.clone().into_string().unwrap()))
+ items.push((
+ "Filepath: ".into(),
+ p.clone().into_string().unwrap(),
+ PopupItem::Entryfile,
+ ))
});
// items.push((
// "Filepath: ".into(),
@@ -348,13 +360,14 @@ impl App {
.selected()
.unwrap();
let entry = self.bibiman.entry_table.entry_table_items[idx].clone();
- let mut items: Vec<(String, String)> = vec![];
+ let mut items: Vec<(String, String, PopupItem)> = vec![];
if entry.filepath.is_some() || entry.doi_url.is_some() || entry.notes.is_some()
{
if entry.doi_url.is_some() {
items.push((
"Weblink (DOI/URL): ".into(),
entry.doi_url.unwrap().clone(),
+ PopupItem::Link,
))
}
if entry.filepath.is_some() {
@@ -374,12 +387,17 @@ impl App {
} else {
p.clone().into_string().unwrap()
},
+ PopupItem::Entryfile,
))
});
}
if entry.notes.is_some() {
entry.notes.unwrap().iter().for_each(|n| {
- items.push(("Note: ".into(), n.clone().into_string().unwrap()));
+ items.push((
+ "Note: ".into(),
+ n.clone().into_string().unwrap(),
+ PopupItem::Notefile,
+ ));
});
}
diff --git a/src/bibiman.rs b/src/bibiman.rs
index 200db96..fb72e93 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -20,7 +20,7 @@ use crate::bibiman::entries::EntryTableColumn;
use crate::bibiman::{bibisetup::*, search::BibiSearch};
use crate::cliargs::CLIArgs;
use crate::config::BibiConfig;
-use crate::tui::popup::{PopupArea, PopupKind};
+use crate::tui::popup::{PopupArea, PopupItem, PopupKind};
use crate::tui::Tui;
use crate::{app, cliargs};
use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList};
@@ -161,7 +161,7 @@ impl Bibiman {
popup_kind: PopupKind,
message: Option<&str>,
object: Option<&str>,
- items: Option<Vec<(String, String)>>,
+ items: Option<Vec<(String, String, PopupItem)>>,
) -> Result<()> {
if let CurrentArea::EntryArea = self.current_area {
self.former_area = Some(FormerArea::EntryArea);
@@ -631,10 +631,18 @@ impl Bibiman {
}
pub fn append_to_file(&mut self) {
- let mut items = vec![("Create new file".to_owned(), "".to_string())];
+ let mut items = vec![(
+ "Create new file".to_owned(),
+ "".to_string(),
+ PopupItem::Default,
+ )];
if self.main_bibfiles.len() > 1 {
for f in self.main_bibfiles.clone() {
- items.push(("File: ".into(), f.to_str().unwrap().to_owned()));
+ items.push((
+ "File: ".into(),
+ f.to_str().unwrap().to_owned(),
+ PopupItem::Bibfile,
+ ));
}
} else {
items.push((
@@ -645,6 +653,7 @@ impl Bibiman {
.to_str()
.unwrap()
.to_owned(),
+ PopupItem::Bibfile,
));
}
self.popup_area.popup_selection(items);
diff --git a/src/tui/popup.rs b/src/tui/popup.rs
index 93b01c3..da44744 100644
--- a/src/tui/popup.rs
+++ b/src/tui/popup.rs
@@ -40,13 +40,23 @@ pub enum PopupKind {
YankItem,
}
+#[derive(Debug)]
+pub enum PopupItem {
+ Bibfile,
+ Entryfile,
+ Notefile,
+ Link,
+ Default,
+ None,
+}
+
#[derive(Debug, Default)]
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, String)>,
+ pub popup_list: Vec<(String, String, PopupItem)>,
pub popup_state: ListState,
pub popup_sel_item: String,
// pub add_entry_input: String,
@@ -116,8 +126,8 @@ impl PopupArea {
/// Opens a popup with a selectable list
///
- /// The list items are passed as argument of the kind `Vec<(String, String)>`.
- pub fn popup_selection(&mut self, items: Vec<(String, String)>) {
+ /// The list items are passed as argument of the kind `Vec<(String, String, PopupItem)>`.
+ pub fn popup_selection(&mut self, items: Vec<(String, String, PopupItem)>) {
self.popup_list = items;
// self.popup_kind = Some(PopupKind::SelectRes);
self.is_popup = true;
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index be53f61..2c30154 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -17,7 +17,7 @@
use std::path::PathBuf;
-use super::popup::PopupArea;
+use super::popup::{PopupArea, PopupItem};
use crate::bibiman::entries::EntryTableColumn;
use crate::bibiman::{CurrentArea, FormerArea};
use crate::cliargs::CLIArgs;
@@ -280,9 +280,17 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.popup_list
.iter()
.map(
- |(mes, obj)| {
+ |(mes, obj, i)| {
+ let style = match i {
+ PopupItem::Bibfile => Style::new().fg(cfg.colors.entry_color),
+ PopupItem::Entryfile => Style::new().fg(cfg.colors.file_color),
+ PopupItem::Notefile => Style::new().fg(cfg.colors.note_color),
+ PopupItem::Link => Style::new().fg(cfg.colors.link_color),
+ PopupItem::Default => Style::new(),
+ PopupItem::None => Style::new(),
+ };
ListItem::from(Line::from(vec![
- Span::styled(mes, Style::new().bold()),
+ Span::styled(mes, style.bold()),
Span::raw(obj),
]))
}, // ListItem::from(mes.to_owned() + obj)
@@ -333,7 +341,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) {
.popup_area
.popup_list
.iter()
- .max_by(|(mes, obj), (m, o)| {
+ .max_by(|(mes, obj, _ik), (m, o, _i)| {
let x = mes.chars().count() + obj.chars().count();
let y = m.chars().count() + o.chars().count();
x.cmp(&y)