Skip to content

Commit

Permalink
Configurable highlight colors
Browse files Browse the repository at this point in the history
  • Loading branch information
thmshmm committed May 18, 2024
1 parent 55e6f25 commit 87001c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
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

0 comments on commit 87001c7

Please sign in to comment.