Skip to content

Commit

Permalink
new: added support for theme preview with fzf
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Apr 30, 2024
1 parent 39b53b8 commit cff4259
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <mr.pavel.ivanov@gmail.com>"]
version = "0.28.1-alpha.7"
version = "0.28.1-alpha.8"
edition = "2021"
license = "MIT"

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ See other [screenshots](https://github.com/pamburus/hl-extra/tree/90be58af2fb91d
* Using environment variable, i.e. `HL_THEME=classic`, overrides the value specified in configuration file.
* Using command-line argument, i.e. `--theme classic`, overrides all other values.

#### Selecting themes with preview
To select themes with preview [fzf](https://github.com/junegunn/fzf) tool can be used like this:
```bash
hl --list-themes | fzf --preview-window="top,80%" --preview="head -n 100 example.log | hl --theme={} -c"
```

#### Custom themes
- Custom themes are automatically loaded when found in a predefined platform-specific location.

Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ fn run() -> Result<()> {
ThemeOrigin::Stock => "stock",
ThemeOrigin::Custom => "custom",
};
println!("{}:", origin);
if stdout().is_terminal() {
println!("{}:", origin);
}
for (name, _) in group {
println!(" {}", name);
if stdout().is_terminal() {
println!(" - {}", name);
} else {
println!("{}", name);
}
}
}
return Ok(());
Expand Down
13 changes: 11 additions & 2 deletions src/themecfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@ impl Theme {
result.insert(name, ThemeOrigin::Stock.into());
}

for name in Self::custom_names(app_dirs)? {
result.insert(name?, ThemeOrigin::Custom.into());
if let Ok(names) = Self::custom_names(app_dirs) {
for name in names {
match name {
Ok(name) => {
result.insert(name, ThemeOrigin::Custom.into());
}
Err(e) => {
eprintln!("failed to list custom theme: {}", e);
}
}
}
}

Ok(result)
Expand Down

0 comments on commit cff4259

Please sign in to comment.