Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable highlight colors #7

Merged
merged 1 commit into from
May 18, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Available configuration options are:
| Environment Variable | Description | Default |
|----------------------|-------------|---------|
| `TASKUI_LIST_INTERNAL` | Show internal tasks in the task list | `false` |
| `TASKUI_HIGHLIGHT_STYLE_BG` | Background color for highlighted task | `#ffffff` |
| `TASKUI_HIGHLIGHT_STYLE_FG` | Foreground/text color for highlighted task | `#4c4f69` |

## Installation

Expand Down
2 changes: 2 additions & 0 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::usize;
use super::Config;

pub struct App {
pub cfg: Config,
pub tasks: StatefulList,
pub search: String,
pub input_mode: InputMode,
Expand All @@ -20,6 +21,7 @@ impl App {
.collect();

App {
cfg,
tasks: StatefulList::with_items(tasks),
search: String::new(),
input_mode: InputMode::Select,
Expand Down
13 changes: 13 additions & 0 deletions src/app/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use std::env;

use ratatui::style::Color;
use std::str::FromStr;

const ENV_PREFIX: &str = "TASKUI_";

pub struct Config {
pub list_internal: bool,
pub highlight_style_bg: Color,
pub highlight_style_fg: Color,
}

impl Config {
Expand All @@ -13,6 +18,14 @@ impl Config {
.unwrap_or("false".to_string())
.parse()
.unwrap(),
highlight_style_bg: env::var(ENV_PREFIX.to_string() + "HIGHLIGHT_STYLE_BG")
.unwrap_or("".to_string())
.parse()
.unwrap_or(Color::from_str("#ffffff").unwrap()),
highlight_style_fg: env::var(ENV_PREFIX.to_string() + "HIGHLIGHT_STYLE_FG")
.unwrap_or("".to_string())
.parse()
.unwrap_or(Color::from_str("#4c4f69").unwrap()),
}
}
}
6 changes: 2 additions & 4 deletions src/app/ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use ratatui::{
prelude::*,
widgets::{ListItem, *},
Expand Down Expand Up @@ -32,8 +30,8 @@ pub fn render(f: &mut Frame, app: &mut App) {
.block(Block::default().borders(Borders::ALL).title("Tasks"))
.highlight_style(
Style::default()
.bg(Color::LightGreen)
.fg(Color::from_str("#0000ff").unwrap())
.bg(app.cfg.highlight_style_bg)
.fg(app.cfg.highlight_style_fg)
.add_modifier(Modifier::BOLD),
);

Expand Down