Skip to content

Commit

Permalink
feat(config): introduce initial config system providing basic customi…
Browse files Browse the repository at this point in the history
…sability (#10)

- Allow user to set colour scheme
- Allow user to choose prompt
- Allow user to choose default exec command
  • Loading branch information
robertpsoane authored Jun 28, 2024
2 parents 80ebc2b + 2664b30 commit 935e47c
Show file tree
Hide file tree
Showing 17 changed files with 500 additions and 67 deletions.
114 changes: 114 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ chrono = "0.4.38"
clap = { version = "4.5.6", features = ["derive"] }
color-eyre = "0.6.3"
crossterm = { version = "0.27", features = ["event-stream"] }
dirs-next = "2.0.0"
futures = "0.3.30"
itertools = "0.13.0"
ratatui = { version = "0.27.0", features = ["serde"] }
serde = "1.0.203"
serde_yml = "0.0.10"
tokio = { version = "1.38.0", features = [
"rt-multi-thread",
"macros",
Expand Down
6 changes: 4 additions & 2 deletions ISSUES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

# Images
- Handle deletion of a running image
- Run Image
- New Image
- Tag Image
- Show dangling images

# Exec
- Add modal to provide exec command when exec-ing into a container

# Logs
- Choose log time range
Expand All @@ -19,7 +22,6 @@
- Fix callbacks to use closures
- Add filter widget/component (similar to vim searching)
- General purpose modals for errors
- Some sort of config system
- Add tracing of some sort

# Not currently in scope
Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,41 @@ You can install `ducker` from the [AUR](https://aur.archlinux.org/packages/ducke
paru -S ducker
```

## Tmux
## Configuration

To fix in tmux:
add to tmux.conf
Ducker is configured via a yaml file found in the relevant config directory for host platform. On linux this is `~/.config/ducker/config.yaml`.

The following table summarises the available config values:

| Key | Default | Description |
|--------------|-------------|-----------------------------------------------------------------------------------------------------------------------------|
| prompt | 🦆 | The default prompt to display in the command pane |
| default_exec | `/bin/bash` | The default prompt to display in the command pane. NB - currently uses this for all exec's; it is planned to offer a choice |
| theme | [See below] | The colour theme configuration |

If a value is unset or if the config file is unfound, Ducker will use the default values. If a value is malformed, Ducker will fail to run.

To create a fully populated default config, run ducker with the `-e/--export-default-config` flag; this will write the default config to the default location, overwriting any existing config.

### Themes

By default, ducker uses the terminal emulator's preset colours. However, it is possible to set a custom colour theme in config. This is set in the `theme` section of the config file. The following table describes the theme options. The default theme provides the colours provided in the GIF in this README.

| Key | Default | Description |
|--------------------|-----------|------------------------------------------------------------------------------------------------------|
| use_theme | `false` | When `true` uses the colour scheme defined in config, when `false` uses the default terminal colours |
| title | `#96E072` | The colour used for the Ducker font in the header |
| help | `#EE5D43` | The colour used in the help prompts in the header |
| background | `#23262E` | The colour used in the background |
| footer | `#00E8C6` | The colour used for the text in the footer |
| success | `#96E072` | The colour used for a successful result |
| error | `#EE5D43` | The colour used for an error result |
| positive_highlight | `#96E072` | The colour used for highlighting in a happy state |
| negative_highlight | `#FF00AA` | The colour used for highlighting in a sad state |

### Tmux

Some characters in ducker use italics/boldface. This doesn't work by default when running in tmux. To fix this, add the following to your add to tmux.conf
```
set -g default-terminal "tmux-256color"
set -as terminal-overrides ',xterm*:sitm=\E[3m'
Expand Down
20 changes: 13 additions & 7 deletions src/components/footer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use itertools::Itertools;
use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
style::{Modifier, Style},
text::{Line, Span},
Frame,
};

use crate::traits::Component;
use crate::{config::Config, traits::Component};

#[derive(Default, Debug)]
pub struct Footer {}
#[derive(Debug)]
pub struct Footer {
config: Box<Config>,
}

impl Footer {}
impl Footer {
pub fn new(config: Box<Config>) -> Self {
Self { config }
}
}

impl Component for Footer {
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) {
Expand All @@ -27,13 +33,13 @@ impl Component for Footer {
let key = Span::styled(
format!(" <{key}> = "),
Style::default()
.fg(Color::Cyan)
.fg(self.config.theme.footer())
.add_modifier(Modifier::ITALIC),
);
let desc = Span::styled(
format!("{desc} "),
Style::default()
.fg(Color::Cyan)
.fg(self.config.theme.footer())
.add_modifier(Modifier::ITALIC),
);
[key, desc]
Expand Down
18 changes: 13 additions & 5 deletions src/components/header.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
use ratatui::{
layout::{self, Margin, Rect},
style::{Color, Style},
style::Style,
Frame,
};
use tui_big_text::{BigText, PixelSize};

use crate::traits::Component;
use crate::{config::Config, traits::Component};

#[derive(Default, Debug)]
pub struct Header {}
#[derive(Debug)]
pub struct Header {
config: Box<Config>,
}

impl Header {
pub fn new(config: Box<Config>) -> Self {
Self { config }
}
}

impl Component for Header {
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) {
let big_text = match BigText::builder()
.pixel_size(PixelSize::HalfHeight)
.style(Style::default().fg(Color::Green))
.style(Style::default().fg(self.config.theme.title()))
.lines(vec!["Ducker".into()])
.alignment(layout::Alignment::Center)
.build()
Expand Down
12 changes: 8 additions & 4 deletions src/components/help.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
use itertools::Itertools;
use ratatui::{
layout::{Constraint, Layout},
style::{Color, Modifier, Style},
style::{Modifier, Style},
text::{Line, Span},
widgets::Paragraph,
};

use crate::traits::Component;
use crate::{config::Config, traits::Component};

#[derive(Debug, Clone)]
pub struct PageHelp {
name: String,
config: Box<Config>,
displays: Vec<String>,
width: usize,
}

#[derive(Debug, Clone)]
pub struct PageHelpBuilder {
name: String,
config: Box<Config>,
inputs: Vec<(String, String)>,
}

impl PageHelpBuilder {
pub fn new(name: String) -> Self {
pub fn new(name: String, config: Box<Config>) -> Self {
Self {
name,
config,
inputs: vec![],
}
}
Expand Down Expand Up @@ -54,6 +57,7 @@ impl PageHelpBuilder {

PageHelp {
name: self.name.clone(),
config: self.config.clone(),
displays,
width,
}
Expand Down Expand Up @@ -99,7 +103,7 @@ impl Component for PageHelp {
Span::from(format!("{v}\n")).style(
Style::default()
.add_modifier(Modifier::ITALIC)
.fg(Color::Red),
.fg(self.config.theme.help()),
),
)
.left_aligned()
Expand Down
Loading

0 comments on commit 935e47c

Please sign in to comment.