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
3 changes: 3 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rust-version = "1.89.0"
exclude = ["/.github", "/docs", "/img", "/scripts", "/tools"]

[dependencies]
anstyle-parse = "1.0.0"
clap = { version = "4.6.7", features = ["derive"] }
open = "5.4.5"
ratatui = "0.30.2"
Expand All @@ -25,6 +26,10 @@ toml = "1.2.0"
tui-input = { version = "0.15.5", default-features = false }
umbra = "0.6.0"

[target.'cfg(target_os = "macos")'.dependencies]
# Use the polling backend for keyboard input after reading piped stdin.
crossterm = { version = "0.29.0", default-features = false, features = ["use-dev-tty"] }

[dev-dependencies]
insta = "1.49.0"
rstest = "0.28.0"
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Terminal Color Theme Explorer 🫏

Asinus is a TUI application for exploring, previewing, and comparing terminal color themes.

- Preview themes with built-in terminal samples and compare them side by side.
- Preview themes with built-in samples or your own text, and compare them side by side.
- Search by name, appearance, background color, brightness, and text contrast.
- Inspect color values and credits, mark favorites, and save search conditions.

Expand All @@ -37,6 +37,8 @@ Run Asinus in a True Color terminal with at least 60 columns and 22 rows:
asinus
```

Run `asinus --preview sample.txt` to preview your own text. See [Custom Samples](https://lusingander.github.io/asinus/features/explore-compare.html#custom-samples) for piped input and supported formats.

In Explore / Compare:

| Keys | Action |
Expand All @@ -48,7 +50,7 @@ In Explore / Compare:
| `F1` | Open contextual help |
| `Ctrl-C` | Quit from any screen |

See [Explore & Compare](https://lusingander.github.io/asinus/features/explore-compare.html) for previews and [Keybindings](https://lusingander.github.io/asinus/reference/keybindings.html) for all controls.
See [Keybindings](https://lusingander.github.io/asinus/reference/keybindings.html) for all controls.

To customize UI colors and text styles, see [Configuration](https://lusingander.github.io/asinus/reference/configuration.html).

Expand Down
25 changes: 21 additions & 4 deletions docs/src/features/explore-compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The pin stays available when you change search conditions. You can hide the them

## Preview Samples

Compare shows the same portion of the selected sample for both themes. Content extending beyond the preview is clipped.

Previews show theme colors within Asinus. Use [Theme Details](theme-details.md) to inspect colors and find source links.

### Built-in Samples

| Sample | Content |
| --- | --- |
| Palette | Foreground, background, ANSI colors, and text attributes |
Expand All @@ -17,11 +23,22 @@ The pin stays available when you change search conditions. You can hide the them
| TUI | Lists, tables, selections, and bars |
| Code | A Rust syntax sample |

All samples are built in. They show how the theme's colors work together; actual applications may use different color assignments.
These samples show how the theme's colors work together. Applications may use different color assignments.

The preview selector offers Auto, Small, Medium, and Large content sizes. Auto chooses a size for the available area. Fixed sizes keep the same content when resizing.

### Custom Samples

Use `-p, --preview <FILE>` to load a file as the **Custom** sample for the current run. Use `-` as the file argument to read from stdin.

```sh
asinus --preview sample.txt
git diff --color=always | asinus -p -
```

The preview selector offers Auto, Small, Medium, and Large content sizes. Auto chooses a size for the available area. Fixed sizes keep the same content when resizing. Content extending beyond the preview is clipped. Compare uses the same content size for both themes.
Input must be nonempty UTF-8 text, up to 1 MiB. When reading from stdin, Asinus waits for EOF before opening the TUI. The TUI requires an interactive terminal.

Previewing does not apply a theme to your terminal. Use [Theme Details](theme-details.md) to inspect colors and find source links.
The preview supports ANSI colors and text attributes such as bold and underline. Color indices 0–15 use the selected theme's palette. Indices 16–255 and explicit RGB colors retain their specified values.

## Operations

Expand All @@ -41,7 +58,7 @@ In the preview selector:

| Keys | Action |
| --- | --- |
| `Tab` | Switch between Sample and Content |
| `Tab` | Switch between Sample and Content for built-in samples |
| `←` / `→` | Change the selected value |
| `Enter` | Apply the preview settings |

Expand Down
4 changes: 3 additions & 1 deletion docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ asinus
3. Use `[` / `]` to switch preview samples, or `/` to search.
4. Press `F1` for help and `Ctrl-C` to quit.

Continue with [Explore & Compare](features/explore-compare.md), or see [Keybindings](reference/keybindings.md) for all controls. Run `asinus --help` for command line help and `asinus --version` to check the installed version.
Continue with [Explore & Compare](features/explore-compare.md) or try [your own preview sample](features/explore-compare.md#custom-samples). See [Keybindings](reference/keybindings.md) for all controls.

Run `asinus --help` for command line help and `asinus --version` to check the installed version.
2 changes: 1 addition & 1 deletion docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Asinus is a TUI application for exploring, previewing, and comparing terminal co

## Key Features

- Preview themes with built-in terminal samples and compare them side by side.
- Preview themes with built-in samples or your own text, and compare them side by side.
- Search by name, appearance, background color, brightness, and text contrast.
- Inspect color values and credits, mark favorites, and save search conditions.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/data-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Asinus saves application data in two TOML files. For the settings file you edit,
| File | Contents | Path override |
| --- | --- | --- |
| `marks.toml` | Favorites and ignored themes | `ASINUS_STATE_PATH` |
| `workspace.toml` | Saved filters, last applied conditions, preview sample and content size, comparison direction | `ASINUS_WORKSPACE_PATH` |
| `workspace.toml` | Saved filters, last applied conditions, built-in preview sample and content size, comparison direction | `ASINUS_WORKSPACE_PATH` |

## Locations

Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Modified keys depend on terminal settings. See [Compatibility](compatibility.md#

| Keys | Action |
| --- | --- |
| `Tab` / `Shift-Tab` | Switch between Sample and Content |
| `Tab` / `Shift-Tab` | Switch between Sample and Content for built-in samples |
| `←` / `h`, `→` / `l` | Change the selected value |
| `Enter` | Apply the settings |

Expand Down
24 changes: 12 additions & 12 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
saved::{FilterDialog, SavedScreen},
},
marks::{MarkChange, Marks},
preview::{ContentSize, Preset},
preview::{ContentSize, Preset, Sample, custom::CustomPreview},
search::Filter,
theme::{self, Theme},
workspace::{Session, Workspace, WorkspaceAction},
Expand Down Expand Up @@ -72,7 +72,7 @@ pub struct App {
pub browser_action: Option<String>,
pub copy_selection: Option<CopySelection>,
pub copy_action: Option<CopyRequest>,
pub preset_selection: Option<crate::app::preview::PreviewSelection>,
pub preview_selection: Option<crate::app::preview::PreviewSelection>,
pub help: Option<HelpScreen>,
pub saved: Option<SavedScreen>,
pub dialog: Option<FilterDialog>,
Expand All @@ -89,7 +89,8 @@ pub struct App {
pub filter: Filter,
pub editor: Option<Editor>,
pub theme_list: ListState,
pub preset: Preset,
pub preview_sample: Sample,
pub custom_preview: Option<CustomPreview>,
pub preview_content: ContentSize,
pub mode: Mode,
pub compare_direction: Direction,
Expand All @@ -110,7 +111,7 @@ impl Default for App {
browser_action: None,
copy_selection: None,
copy_action: None,
preset_selection: None,
preview_selection: None,
help: None,
saved: None,
dialog: None,
Expand All @@ -127,7 +128,8 @@ impl Default for App {
filter: Filter::default(),
editor: None,
theme_list: ListState::default().with_selected(Some(0)),
preset: Preset::Palette,
preview_sample: Sample::BuiltIn(Preset::default()),
custom_preview: None,
preview_content: ContentSize::Auto,
mode: Mode::Explore,
compare_direction: Direction::Horizontal,
Expand Down Expand Up @@ -260,7 +262,7 @@ impl App {
}
return;
}
if self.preset_selection.is_some() {
if self.preview_selection.is_some() {
self.update_preview(action);
return;
}
Expand Down Expand Up @@ -319,12 +321,10 @@ impl App {
*visible = !*visible;
}
Action::PresetPrevious | Action::PresetNext => {
self.preset = if action == Action::PresetNext {
self.preset.next()
} else {
self.preset.previous()
};
self.record_session(false);
let sample = self
.preview_sample
.adjacent(action == Action::PresetNext, self.custom_preview.is_some());
self.select_sample(sample, self.preview_content);
}
Action::ToggleFavorite | Action::ToggleIgnore => {
self.update_marks(action);
Expand Down
2 changes: 1 addition & 1 deletion src/app/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl App {
if self.copy_selection.is_some() {
return InputContext::Copy;
}
if self.preset_selection.is_some() {
if self.preview_selection.is_some() {
return InputContext::Preset;
}
if let Some(dialog) = &self.dialog {
Expand Down
4 changes: 2 additions & 2 deletions src/app/persistence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
app::{App, Notice},
marks::Marks,
preview::Sample,
search::Filter,
workspace::{Workspace, WorkspaceAction, WorkspaceChange},
};
Expand All @@ -11,7 +12,7 @@ impl App {
self.notice = read_error.map(|reason| Notice::Warning(format!("Read-only: {reason}")));
self.marks = marks;
self.session = workspace.session.clone();
self.preset = self.session.preset;
self.preview_sample = Sample::BuiltIn(self.session.preset);
self.preview_content = self.session.preview_content;
self.compare_direction = self.session.layout.into();
let query = self.session.query.as_deref().unwrap_or("ignore:false");
Expand All @@ -28,7 +29,6 @@ impl App {
if condition && (self.session.query.is_some() || !self.filter.is_default()) {
self.session.query = Some(self.filter.query());
}
self.session.preset = self.preset;
self.session.preview_content = self.preview_content;
self.session.layout = self.compare_direction.into();
if self.session != self.workspace.session {
Expand Down
48 changes: 31 additions & 17 deletions src/app/preview.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
app::{Action, App},
preview::{ContentSize, Preset},
preview::{ContentSize, Sample, custom::CustomPreview},
};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand All @@ -11,39 +11,53 @@ pub enum PreviewField {

#[derive(Debug, Clone, Copy)]
pub struct PreviewSelection {
pub preset: Preset,
pub sample: Sample,
pub content: ContentSize,
pub field: PreviewField,
}

impl App {
pub fn use_custom_preview(&mut self, preview: CustomPreview) {
self.custom_preview = Some(preview);
self.preview_sample = Sample::Custom;
}

pub fn select_sample(&mut self, sample: Sample, content: ContentSize) {
self.preview_sample = sample;
if let Sample::BuiltIn(preset) = sample {
self.preview_content = content;
if !self.read_only {
self.session.preset = preset;
}
self.record_session(false);
}
}

pub fn open_preview(&mut self) {
self.preset_selection = Some(PreviewSelection {
preset: self.preset,
self.preview_selection = Some(PreviewSelection {
sample: self.preview_sample,
content: self.preview_content,
field: PreviewField::Sample,
});
}

pub fn update_preview(&mut self, action: Action) {
let selection = self
.preset_selection
.preview_selection
.as_mut()
.expect("preview selector is open");
match action {
Action::FieldNext | Action::FieldPrevious => {
Action::FieldNext | Action::FieldPrevious if selection.sample != Sample::Custom => {
selection.field = match selection.field {
PreviewField::Sample => PreviewField::Content,
PreviewField::Content => PreviewField::Sample,
};
}
Action::ValueNext | Action::ValuePrevious => match selection.field {
PreviewField::Sample => {
selection.preset = if action == Action::ValueNext {
selection.preset.next()
} else {
selection.preset.previous()
};
selection.sample = selection
.sample
.adjacent(action == Action::ValueNext, self.custom_preview.is_some());
}
PreviewField::Content => {
let index = ContentSize::ALL
Expand All @@ -60,14 +74,14 @@ impl App {
}
},
Action::Confirm => {
let selection = self.preset_selection.take().unwrap();
if self.preset != selection.preset || self.preview_content != selection.content {
self.preset = selection.preset;
self.preview_content = selection.content;
self.record_session(false);
let selection = self.preview_selection.take().unwrap();
if self.preview_sample != selection.sample
|| self.preview_content != selection.content
{
self.select_sample(selection.sample, selection.content);
}
}
Action::Cancel => self.preset_selection = None,
Action::Cancel => self.preview_selection = None,
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ fn help_blocks_background_actions(#[case] context: InputContext) {
assert_eq!(app.pinned_theme().unwrap().name, "3024 Day");
assert_eq!(app.mode, mode);
assert_eq!(app.theme_list_visible(), list_visible);
assert_eq!(app.preset, Preset::Palette);
assert_eq!(app.preview_sample, Sample::BuiltIn(Preset::Palette));
assert!(app.marks.is_empty());
assert!(app.workspace_action.is_none());
assert!(app.storage_action.is_none());
Expand Down
Loading
Loading