Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Some major improvements and extended markdown support #56

Merged
merged 9 commits into from
Mar 12, 2024
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = [ "command-line-utilities", "gui", "text-processing" ]
[dependencies]
async-std = "1.12.0"
directories = "5.0.1"
chrono = "0.4.34"
chrono = "0.4.35"
dialoguer = "0.11.0"
crossterm = "0.27.0"
rusqlite = { version = "0.31.0", features = ["bundled"] }
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ You can help us in different ways.<br>
**Contributing guidelines** for these three roles coming soon!

## Installation
To install Notabena on **Windows**, simply run the file!
There are a few different ways of installing Notabena:
- **Recommended way:** through SourceForge: https://sourceforge.net/projects/notabena/. This requires no knowledge or programs, but if you want to run it with `notabena` you'll need to add it to `PATH` manually. Is your architecture not in there? Consider building for all the versions and [sending the binaries in our server](https://discord.gg/htNK4YcJB8).
- **Package manager:** currently, Notabena only supports *Homebrew* for **MacOS** and **Linux**. The formula is in `chiissu/macchiato`. More package managers will be added at stable.
- (Still unsure? `brew tap chiissu/macchiato && brew install notabena`)
- **The Rust way:** if you have Rust installed, we recommend installing it through `cargo` (`cargo install notabena`). It will automatically be added to your `PATH`.

When running Notabena on **Linux or macOS**, you might encounter an error like this when running the file:<br>
`bash: /home/Your-Username/Downloads/Your-Notabena-Installation: Permission denied`<br>
Expand All @@ -42,5 +46,4 @@ MacOS:
`chmod u+x /Users/Your-Username/Downloads/Your-Notabena-Installation` (filling in the blanks)<br>
The program should now run smoothly!<br>

These are currently the only known errors during the installation of Notabena.
If these solutions don't work or another error occurs, please open an issue so this section can be updated!
There are no issues known with Windows installation. If you get another error or similar bug, please open an issue.
37 changes: 25 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ mod return_to_main;
mod tests;
mod utilities;

use std::process::exit;

use crate::{
note::Note,
prompts::{multiselect::multiselect, select::select},
return_to_main::return_to_main,
utilities::{cursor_to_origin::cursor_to_origin, truncate_note::truncate_note},
utilities::{
cursor_to_origin::cursor_to_origin,
format_md::{inline, paragraph},
truncate_note::truncate_note,
},
};
use async_std::path::PathBuf;
use directories::BaseDirs;
use termimad::MadSkin;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let data_directory: PathBuf = BaseDirs::new().unwrap().config_dir().into();
Expand All @@ -37,23 +44,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2 => Note::edit(&db_file).expect("Editing the note failed"),
3 => Note::delete(&db_file).expect("Deleting the note failed"),
4 => display_about().expect("Viewing about failed"),
_ => {
cursor_to_origin()?;
return Ok(());
}
5 => exit(0),
_ => (),
}

/*if return_to_main().is_ok() {
main()?;
}*/
}
}

fn display_about() -> Result<(), Box<dyn std::error::Error>> {
let skin: MadSkin = MadSkin::default();

cursor_to_origin()?;
println!("Notabena is a FOSS note-taking CLI tool, written in Rust.");
println!("License: GPL v3\n");
println!("COPYRIGHT (c) 2024 NOTABENA ORGANISATION\nPROJECT LEADS @ThatFrogDev, @MrSerge01, GITHUB CONTRIBUTORS\n");
println!("{}", paragraph(&skin, &format!("# About Notabena")));
println!(
"{}",
inline(
&skin,
"**Notabena** is a FOSS note-taking CLI tool, written in Rust.\n"
)
);
println!(
"version: v{}, licensed under: GPL v3",
env!("CARGO_PKG_VERSION")
);
println!("COPYRIGHT (c) 2023-PRESENT NOTABENA ORGANISATION\nPROJECT LEADS @ThatFrogDev, @MrSerge01, GITHUB CONTRIBUTORS\n");

Ok(())
}
6 changes: 1 addition & 5 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ impl Note {
created: format!("{}", Local::now().format("%A %e %B, %H:%M")),
};

cursor_to_origin()?;
println!("This is the note you're about to create:");
display(&mut inputted_note)?;

Connection::open(db_file)?.execute(
"INSERT INTO saved_notes (id, name, content, created) VALUES (?1, ?2, ?3, ?4);",
params![
Expand Down Expand Up @@ -62,7 +58,7 @@ impl Note {
let mut selected_note = &saved_notes[selection];
cursor_to_origin()?;

display(&mut selected_note)?;
display(&mut selected_note);
Ok(())
}

Expand Down
23 changes: 15 additions & 8 deletions src/utilities/display.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use termimad::*;

use crate::note::Note;
use crate::utilities::format_md::format_md;
use crate::utilities::format_md::{inline, paragraph};
use std::io::{self, Write};
use termimad::*;

pub fn display(note: &Note) -> Result<(), Box<dyn std::error::Error>> {
let skin: MadSkin = MadSkin::default();
let formatted_note = format!(
"=======================\n\
{}\
{}\n\
{}\
=======================\n",
paragraph(&skin, &format!("# {}", inline(&skin, &note.name))),
paragraph(&skin, &note.content),
paragraph(&skin, &format!("*{}*", note.created))
);

println!("=======================");
println!("Name: {}", format_md(&skin, &note.name));
println!("Content: {}", format_md(&skin, &note.content));
println!("Created at: {}", note.created);
println!("=======================");
print!("{}", formatted_note);
io::stdout().flush()?;

Ok(())
}
6 changes: 5 additions & 1 deletion src/utilities/format_md.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use termimad::*;

pub fn format_md<'sk, 'st>(skin: &'sk MadSkin, string: &'st str) -> FmtInline<'sk, 'st> {
pub fn paragraph<'sk, 'st>(skin: &'sk MadSkin, string: &'st str) -> FmtText<'sk, 'st> {
return skin.text(string, None);
}

pub fn inline<'sk, 'st>(skin: &'sk MadSkin, string: &'st str) -> FmtInline<'sk, 'st> {
return skin.inline(string);
}