diff options
| author | lukeflo | 2024-09-23 23:55:04 +0200 |
|---|---|---|
| committer | lukeflo | 2024-09-23 23:55:04 +0200 |
| commit | 166bc53ac78be6219a63870447920c920734f640 (patch) | |
| tree | 5102bf131261f48c1fd311674da7ba94a792a06a | |
| parent | 979b260f3e3b969e4da64c7e9bd9a4caaad24f9b (diff) | |
| download | bibiman-166bc53ac78be6219a63870447920c920734f640.tar.gz bibiman-166bc53ac78be6219a63870447920c920734f640.zip | |
add license informations
| -rw-r--r-- | src/backend.rs | 17 | ||||
| -rw-r--r-- | src/backend/bib.rs | 85 | ||||
| -rw-r--r-- | src/backend/cliargs.rs | 17 | ||||
| -rw-r--r-- | src/frontend.rs | 21 | ||||
| -rw-r--r-- | src/frontend/app.rs | 93 | ||||
| -rw-r--r-- | src/frontend/event.rs | 17 | ||||
| -rw-r--r-- | src/frontend/handler.rs | 17 | ||||
| -rw-r--r-- | src/frontend/tui.rs | 17 | ||||
| -rw-r--r-- | src/frontend/ui.rs | 77 | ||||
| -rw-r--r-- | src/main.rs | 17 |
10 files changed, 298 insertions, 80 deletions
diff --git a/src/backend.rs b/src/backend.rs index 7907145..586496b 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -1,2 +1,19 @@ +// 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 <https://www.gnu.org/licenses/>. +///// + pub mod bib; pub mod cliargs; diff --git a/src/backend/bib.rs b/src/backend/bib.rs index aa7272f..6e913fd 100644 --- a/src/backend/bib.rs +++ b/src/backend/bib.rs @@ -1,51 +1,60 @@ +// 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 <https://www.gnu.org/licenses/>. +///// + use biblatex::Bibliography; -use regex::Regex; -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::{fs, path::PathBuf}; -use super::cliargs::{CLIArgs, PosArgs}; +use super::cliargs::PosArgs; // Set necessary fields // TODO: can surely be made more efficient/simpler -pub struct Bibi { - pub citekeys: Vec<String>, - // pub bibliography: Bibliography, -} - -pub fn get_bibfile(filename: impl AsRef<Path>) -> String { - let bibfile = fs::read_to_string(&filename).unwrap(); - bibfile -} - -pub fn get_citekeys(bibstring: &Bibliography) -> Vec<String> { - // let bib = Bibliography::parse(&get_bibfile(CLIArgs::parse_cli_args().bibfilearg)).unwrap(); - // // Define Regex to match citekeys - // let re = Regex::new(r"(?m)^\@[a-zA-Z]*\{(.*)\,").unwrap(); - // // Declare empty vector to fill with captured keys - // // Has to be Vec<&str> because of captures_iter method - // let mut keys = vec![]; - // for (_, [key]) in re.captures_iter(&bibfilestring).map(|c| c.extract()) { - // keys.push(key); - // } - // // Transform Vec<&str> to Vec<String> which is needed by the struct Bibi - // let mut citekeys: Vec<String> = keys.into_iter().map(String::from).collect(); - // // Sort vector items case-insensitive - // citekeys.sort_by_key(|name| name.to_lowercase()); - // citekeys - let mut citekeys: Vec<String> = bibstring.iter().map(|entry| entry.to_owned().key).collect(); - citekeys.sort_by_key(|name| name.to_lowercase()); - citekeys +pub struct BibiMain { + pub bibfile: PathBuf, // path to bibfile + pub bibfilestring: String, // content of bibfile as string + pub bibliography: Bibliography, // parsed bibliography + pub citekeys: Vec<String>, // list of all citekeys } -impl Bibi { +impl BibiMain { pub fn new() -> Self { // TODO: Needs check for config file path as soon as config file is impl - let bib = Bibliography::parse(&get_bibfile(PosArgs::parse_pos_args().bibfilearg)).unwrap(); + let bibfile = PosArgs::parse_pos_args().bibfilearg; + let bibfilestring = fs::read_to_string(&bibfile).unwrap(); + let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap(); + let citekeys = Self::get_citekeys(&bibliography); Self { - citekeys: get_citekeys(&bib), - // bibliography: biblatex::Bibliography::parse(&bibfilestring).unwrap(), + bibfile, + bibfilestring, + bibliography, + citekeys, } } + + // get list of citekeys from the given bibfile + // this list is the base for further operations on the bibentries + // since it is the entry point of the biblatex crate. + pub fn get_citekeys(bibstring: &Bibliography) -> Vec<String> { + let mut citekeys: Vec<String> = + bibstring.iter().map(|entry| entry.to_owned().key).collect(); + citekeys.sort_by_key(|name| name.to_lowercase()); + citekeys + } +} + +pub struct BibiData { + pub citekey: Vec<String>, } diff --git a/src/backend/cliargs.rs b/src/backend/cliargs.rs index b820b6a..f3e9fcf 100644 --- a/src/backend/cliargs.rs +++ b/src/backend/cliargs.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 <https://www.gnu.org/licenses/>. +///// + use core::panic; use std::path::{Path, PathBuf}; diff --git a/src/frontend.rs b/src/frontend.rs index 6ec15f2..9ee632a 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -1,5 +1,22 @@ +// 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 <https://www.gnu.org/licenses/>. +///// + pub mod app; pub mod event; -pub mod ui; -pub mod tui; pub mod handler; +pub mod tui; +pub mod ui; diff --git a/src/frontend/app.rs b/src/frontend/app.rs index ca2c824..0bee743 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.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 <https://www.gnu.org/licenses/>. +///// + use crate::backend::bib::*; use std::error; @@ -74,13 +91,17 @@ impl FromIterator<String> for TagList { } } -impl FromIterator<(String, String)> for EntryTable { - fn from_iter<T: IntoIterator<Item = (String, String)>>(iter: T) -> Self { +// Iterate over vector fields with entries data to create TableItems +// Number of Strings has to match number of fields +impl FromIterator<[String; 5]> for EntryTable { + fn from_iter<T: IntoIterator<Item = [String; 5]>>(iter: T) -> Self { // Has to be Vev<EntryTableItem> let entry_table_items = iter .into_iter() - // .map(|(authors, title)| EntryTableItem::new(&authors, &title)) - .map(|(authors, title)| EntryTableItem::new(&authors, &title)) + // fields in map must not be named specific + .map(|[authors, title, year, pubtype, citekey]| { + EntryTableItem::new(&authors, &title, &year, &pubtype, &citekey) + }) .sorted_by(|a, b| a.authors.cmp(&b.authors)) .collect(); let entry_table_state = TableState::default().with_selected(0); @@ -103,19 +124,27 @@ pub struct EntryTable { pub struct EntryTableItem { pub authors: String, pub title: String, + pub year: String, + pub pubtype: String, + pub citekey: String, // pub year: u16, } impl EntryTableItem { - pub fn new(authors: &str, title: &str) -> Self { + pub fn new(authors: &str, title: &str, year: &str, pubtype: &str, citekey: &str) -> Self { Self { authors: authors.to_string(), title: title.to_string(), + year: year.to_string(), + pubtype: pubtype.to_string(), + citekey: citekey.to_string(), } } + // This functions decides which fields are rendered in the entry table + // Fields which should be usable but not visible can be left out pub fn ref_vec(&self) -> Vec<&String> { - vec![&self.authors, &self.title] + vec![&self.authors, &self.title, &self.year, &self.pubtype] } pub fn authors(&self) -> &str { @@ -125,24 +154,60 @@ impl EntryTableItem { pub fn title(&self) -> &str { &self.title } + + pub fn year(&self) -> &str { + &self.year + } + + pub fn pubtype(&self) -> &str { + &self.pubtype + } + + pub fn citekey(&self) -> &str { + &self.citekey + } } impl Default for App { fn default() -> Self { // TEST: read file - let lines = Bibi::new().citekeys; + let lines = BibiMain::new().citekeys; let iter = vec![ - ( + [ "Mrs. Doubtfire".to_string(), "A great book of great length".to_string(), - ), - ("Veye Tatah".to_string(), "Modern economy".to_string()), - ("Joseph Conrad".to_string(), "Heart of Darkness".to_string()), - ( + "2003".to_string(), + "book".to_string(), + "doubtfire_2003".to_string(), + ], + [ + "Veye Tatah".to_string(), + "Modern economy".to_string(), + 1995.to_string(), + "article".to_string(), + "tatah_1995".to_string(), + ], + [ + "Joseph Conrad".to_string(), + "Heart of Darkness".to_string(), + 1899.to_string(), + "book".to_string(), + "conrad_1899".to_string(), + ], + [ "Michelle-Rolpg Trouillot".to_string(), "Silencing the Past".to_string(), - ), - ("Zora Neale Hurston".to_string(), "Barracoon".to_string()), + "1995".to_string(), + "book".to_string(), + "trouillot_1995".to_string(), + ], + [ + "Zora Neale Hurston".to_string(), + "Barracoon".to_string(), + "1919".to_string(), + "book".to_string(), + "hurston_1919".to_string(), + ], ]; Self { running: true, diff --git a/src/frontend/event.rs b/src/frontend/event.rs index f83dfea..27dd059 100644 --- a/src/frontend/event.rs +++ b/src/frontend/event.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 <https://www.gnu.org/licenses/>. +///// + use std::time::Duration; use crossterm::event::{Event as CrosstermEvent, KeyEvent, MouseEvent}; diff --git a/src/frontend/handler.rs b/src/frontend/handler.rs index 2cc8bb5..cdf47e2 100644 --- a/src/frontend/handler.rs +++ b/src/frontend/handler.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 <https://www.gnu.org/licenses/>. +///// + use crate::frontend::app::{App, AppResult}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; diff --git a/src/frontend/tui.rs b/src/frontend/tui.rs index 94db9ea..477052f 100644 --- a/src/frontend/tui.rs +++ b/src/frontend/tui.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 <https://www.gnu.org/licenses/>. +///// + use crate::frontend::app::{App, AppResult}; use crate::frontend::event::EventHandler; use crossterm::event::{DisableMouseCapture, EnableMouseCapture}; diff --git a/src/frontend/ui.rs b/src/frontend/ui.rs index 9bb3c4c..7b13f4b 100644 --- a/src/frontend/ui.rs +++ b/src/frontend/ui.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 <https://www.gnu.org/licenses/>. +///// + use ratatui::{ buffer::Buffer, layout::{Constraint, Layout, Rect}, @@ -49,17 +66,10 @@ impl From<&TagListItem> for ListItem<'_> { } } -impl From<&EntryTableItem> for ListItem<'_> { - fn from(value: &EntryTableItem) -> Self { - let line = Line::styled(format!("{}, {}", value.authors, value.title), TEXT_FG_COLOR); - ListItem::new(line) - } -} - impl Widget for &mut App { fn render(self, area: Rect, buf: &mut Buffer) { let [header_area, main_area, footer_area] = Layout::vertical([ - Constraint::Length(2), + Constraint::Length(1), Constraint::Fill(1), Constraint::Length(1), ]) @@ -76,7 +86,7 @@ impl Widget for &mut App { App::render_footer(footer_area, buf); // Render list area where entry gets selected // self.render_entry_table(list_area, buf); - self.render_table(list_area, buf); + self.render_entrytable(list_area, buf); // Render infos related to selected entry // TODO: only placeholder at the moment, has to be impl. self.render_taglist(tag_area, buf); @@ -86,8 +96,9 @@ impl Widget for &mut App { impl App { pub fn render_header(area: Rect, buf: &mut Buffer) { - Paragraph::new("Ratatui List Example") + Paragraph::new("BIBIMAN – BibLaTeX manager TUI") .bold() + .fg(MAIN_BLUE_COLOR) .centered() .render(area, buf); } @@ -98,26 +109,32 @@ impl App { .render(area, buf); } - pub fn render_table(&mut self, area: Rect, buf: &mut Buffer) { - let block = Block::bordered() + pub fn render_entrytable(&mut self, area: Rect, buf: &mut Buffer) { + let block = Block::bordered() // can also be Block::new .title( Line::raw(" Selection List ") .centered() .fg(Color::Indexed(39)), ) - // .borders(Borders::TOP) + // .borders(Borders::TOP) // set borders for Block::new .border_set(symbols::border::ROUNDED) .border_style(BOX_BORDER_STYLE_MAIN) .bg(Color::Black); // .bg(NORMAL_ROW_BG); let header_style = Style::default().bold(); let selected_style = Style::default().add_modifier(Modifier::REVERSED); - let header = ["Authors".underlined(), "Title".underlined()] - .into_iter() - .map(Cell::from) - .collect::<Row>() - .style(header_style) - .height(1); + let header = [ + "Authors".underlined(), + "Title".underlined(), + "Year".underlined(), + "Type".underlined(), + ] + .into_iter() + .map(Cell::from) + .collect::<Row>() + .style(header_style) + .height(1); + // Iterate over vector storing each entries data fields let rows = self .entry_table .entry_table_items @@ -131,13 +148,21 @@ impl App { .style(Style::new().fg(Color::White).bg(alternate_colors(i))) .height(1) }); - let entry_table = Table::new(rows, [Constraint::Percentage(20), Constraint::Fill(1)]) - .block(block) - .header(header) - .column_spacing(2) - .highlight_style(selected_style) - .bg(Color::Black) - .highlight_spacing(HighlightSpacing::Always); + let entry_table = Table::new( + rows, + [ + Constraint::Percentage(20), + Constraint::Fill(1), + Constraint::Length(4), + Constraint::Percentage(10), + ], + ) + .block(block) + .header(header) + .column_spacing(2) + .highlight_style(selected_style) + .bg(Color::Black) + .highlight_spacing(HighlightSpacing::Always); StatefulWidget::render( entry_table, area, diff --git a/src/main.rs b/src/main.rs index 1b598be..a9011f6 100644 --- a/src/main.rs +++ b/src/main.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 <https://www.gnu.org/licenses/>. +///// + use std::io; use backend::cliargs::{self, CLIArgs}; |
