Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ lto = true

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
toml = "0.8"
syntect = "5.1"
pulldown-cmark = { version = "0.11.0" }
pulldown-cmark-to-cmark = "15.0.1"
Expand All @@ -36,6 +38,7 @@ rand = "0.8.5"
once_cell = "1.19.0"
arboard = "3.4.1"
fuzzy-matcher = "0.3.7"
lazy_static = "1.5.0"

[[bin]]
name = "thoth"
Expand Down
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ The binary lives in `thoth/target/release/thoth`. You can add the binary to your
## Usage
This will show how to use the scratchpad via the CLI or the TUI.

### Theme
You can set the theme via the CLI or in the TUI.
```bash
# Set to light mode
thoth theme light

# Set to dark mode
thoth theme dark

# Check current theme
thoth get_theme
````
#### UI Shortcuts
Users can toggle between light and dark modes while using the application:
- Ctrl+L: Toggle between light and dark modes

#### Persistent Configuration
Theme preferences are stored in ~/.config/thoth/config.toml and persist between TUI sessions.

### TUI
To start the TUI, simply type `thoth`. Since it is a persistent buffer, thoth will save when you hit quit using `q`.

Expand Down Expand Up @@ -172,14 +191,16 @@ A terminal scratchpad akin to Heynote
Usage: thoth [COMMAND]

Commands:
add Add a new block to the scratchpad
list List all of the blocks within your thoth scratchpad
load_backup Load backup file as the main thoth markdown file
read_clipboard Read the contents of the clipboard backup file
delete Delete a block by name
view View (STDOUT) the contents of the block by name
copy Copy the contents of a block to the system clipboard
help Print this message or the help of the given subcommand(s)
add Add a new block to the scratchpad
list List all of the blocks within your thoth scratchpad
load_backup Load backup file as the main thoth markdown file
read_clipboard Read the contents of the clipboard backup file
delete Delete a block by name
view View (STDOUT) the contents of the block by name
copy Copy the contents of a block to the system clipboard
theme Set the theme to light or dark mode
get_theme Get the current theme
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
Expand Down Expand Up @@ -216,6 +237,6 @@ This ensures your content is always accessible, even when the system clipboard i
Contributions are always welcomed :) !!! Please take a look at this [doc](https://github.com/jooaf/thoth/blob/main/CONTRIBUTING.md) for more information.

## TODO
- Inlcude light mode
- Inlcude light mode: Done!
- Automatically saving backup `thoth_notes.md` files: Done!
- Add fuzzy finder for selecting blocks in TUI: Done!
45 changes: 44 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{get_save_backup_file_path, load_textareas, save_textareas, EditorClipboard};
use crate::{
get_save_backup_file_path, load_textareas, save_textareas, EditorClipboard, ThemeMode,
ThothConfig,
};
use anyhow::{bail, Result};
use std::{
fs::File,
Expand Down Expand Up @@ -48,6 +51,46 @@ pub enum Commands {
/// The name of the block to be used
name: String,
},
/// Set the theme to light or dark mode
Theme {
/// The theme to set: 'light' or 'dark'
mode: String,
},
/// Get the current theme
GetTheme,
}

pub fn set_theme(mode: &str) -> Result<()> {
let mode_lowercase = mode.to_lowercase();

let mut config = ThothConfig::load()?;

match mode_lowercase.as_str() {
"light" => {
config.set_theme(ThemeMode::Light)?;
println!("Theme set to light mode");
}
"dark" => {
config.set_theme(ThemeMode::Dark)?;
println!("Theme set to dark mode");
}
_ => {
bail!("Invalid theme mode. Use 'light' or 'dark'");
}
}

Ok(())
}

pub fn get_theme() -> Result<()> {
let config = ThothConfig::load()?;

match config.theme {
ThemeMode::Light => println!("Current theme: light"),
ThemeMode::Dark => println!("Current theme: dark"),
}

Ok(())
}

pub fn read_clipboard_backup() -> Result<()> {
Expand Down
73 changes: 73 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use anyhow::Result;
use dirs::home_dir;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;

use crate::ThemeColors;
use crate::DARK_MODE_COLORS;
use crate::LIGHT_MODE_COLORS;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub enum ThemeMode {
Light,
#[default]
Dark,
}

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct ThothConfig {
pub theme: ThemeMode,
}

impl ThothConfig {
pub fn load() -> Result<Self> {
let config_path = get_config_path();

if !config_path.exists() {
let default_config = Self::default();
default_config.save()?;
return Ok(default_config);
}

let config_str = fs::read_to_string(config_path)?;
let config: ThothConfig = toml::from_str(&config_str)?;
Ok(config)
}

pub fn save(&self) -> Result<()> {
let config_path = get_config_path();

// Create directory if it doesn't exist
if let Some(parent) = config_path.parent() {
if !parent.exists() {
fs::create_dir_all(parent)?;
}
}

let config_str = toml::to_string(self)?;
fs::write(config_path, config_str)?;
Ok(())
}

pub fn set_theme(&mut self, theme: ThemeMode) -> Result<()> {
self.theme = theme;
self.save()?;
Ok(())
}

pub fn get_theme_colors(&self) -> &'static ThemeColors {
match self.theme {
ThemeMode::Light => &LIGHT_MODE_COLORS,
ThemeMode::Dark => &DARK_MODE_COLORS,
}
}
}

pub fn get_config_path() -> PathBuf {
let mut path = home_dir().unwrap_or_default();
path.push(".config");
path.push("thoth");
path.push("config.toml");
path
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod cli;
pub mod clipboard;
pub mod config;
pub mod formatter;
pub mod markdown_renderer;
pub mod scrollable_textarea;
pub mod theme;
pub mod title_popup;
pub mod title_select_popup;
pub mod ui;
Expand All @@ -11,11 +13,13 @@ pub mod utils;

pub use clipboard::ClipboardTrait;
pub use clipboard::EditorClipboard;
pub use config::{ThemeMode, ThothConfig};
use dirs::home_dir;
pub use formatter::{format_json, format_markdown};
pub use markdown_renderer::MarkdownRenderer;
pub use scrollable_textarea::ScrollableTextArea;
use std::path::PathBuf;
pub use theme::{ThemeColors, DARK_MODE_COLORS, LIGHT_MODE_COLORS};
pub use title_popup::TitlePopup;
pub use title_select_popup::TitleSelectPopup;
pub use utils::{load_textareas, save_textareas};
Expand All @@ -30,6 +34,7 @@ pub fn get_clipboard_backup_file_path() -> PathBuf {
home_dir().unwrap_or_default().join("thoth_clipboard.txt")
}

// The ORANGE constant is kept for backward compatibility
pub const ORANGE: ratatui::style::Color = ratatui::style::Color::Rgb(255, 165, 0);
pub const DAEMONIZE_ARG: &str = "__thoth_copy_daemonize";
pub const MIN_TEXTAREA_HEIGHT: usize = 3;
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::{
};
use thoth_cli::{
cli::{
add_block, copy_block, delete_block, list_blocks, read_clipboard_backup,
replace_from_backup, view_block,
add_block, copy_block, delete_block, get_theme, list_blocks, read_clipboard_backup,
replace_from_backup, set_theme, view_block,
},
get_save_backup_file_path, EditorClipboard,
};
Expand Down Expand Up @@ -66,6 +66,12 @@ fn main() -> Result<()> {
Some(Commands::Copy { name }) => {
copy_block(name)?;
}
Some(Commands::Theme { mode }) => {
set_theme(mode)?;
}
Some(Commands::GetTheme) => {
get_theme()?;
}
None => {
run_ui()?;
}
Expand Down
Loading
Loading