Skip to content

Commit

Permalink
new: added support for toml and json formats in theme configurations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus authored Jun 10, 2024
1 parent 1d71b44 commit f3bf36e
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 100 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Validate configs
- name: Validate YAML configs
uses: cardinalby/schema-validator-action@v3
with:
file: 'etc/defaults/config*.yaml'
schema: 'schema/json/config.schema.json'

- name: Validate themes
- name: Validate YAML themes
uses: cardinalby/schema-validator-action@v3
with:
file: 'etc/defaults/themes/*.yaml|src/testing/assets/themes/*.yaml'
file: 'etc/defaults/themes/*.yaml'
schema: 'schema/json/theme.schema.json'

- name: Setup taplo
uses: uncenter/setup-taplo@v1

- name: Validate TOML configs and themes
run: taplo check

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include = ["src/testing/assets/themes/test.toml"]
3 changes: 2 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 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.29.7-alpha.4"
version = "0.29.7-alpha.5"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -74,6 +74,7 @@ snap = "1"
strum = { version = "0", features = ["derive"] }
thiserror = "1"
titlecase = "3"
toml = "0"
wildflower = { git = "https://github.com/cassaundra/wildflower.git" }
winapi-util = { version = "0" }
wyhash = "0"
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ help:
.PHONY: help

## Run continuous integration tests
ci: check-fmt test build
ci: check-fmt check-schema test build
@cargo run -- --version
.PHONY: ci

## Run code formatting tests
check-fmt:
check-fmt: contrib-build
@cargo +nightly fmt --all -- --check
.PHONY: check-fmt

## Run schema validation tests
check-schema: contrib-build
@taplo check
.PHONY: check-schema

## Automatically format code
fmt:
@cargo +nightly fmt --all
Expand Down
8 changes: 8 additions & 0 deletions contrib/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,20 @@ setup_screenshot_tools() {
setup_alacritty
}

setup_taplo() {
setup_cargo
if [ ! -x "$(command -v taplo)" ]; then
cargo install taplo-cli --locked --features lsp
fi
}

# --- main ---

while [ $# -gt 0 ]; do
case $1 in
build)
setup_cargo
setup_taplo
;;
coverage)
setup_coverage_tools
Expand Down
9 changes: 9 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ pub enum Error {
UnrecognizedTime(String),
#[error("unknown theme {name:?}, use any of {known:?}")]
UnknownTheme { name: String, known: Vec<String> },
#[error("failed to load theme {}: {source}", HILITE.paint(.filename))]
FailedToLoadTheme {
name: String,
filename: String,
#[source]
source: Box<Error>,
},
#[error("failed to parse utf-8 string: {0}")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("failed to construct utf-8 string from bytes: {0}")]
FromUtf8Error(#[from] std::string::FromUtf8Error),
#[error("failed to parse yaml: {0}")]
YamlError(#[from] serde_yaml::Error),
#[error(transparent)]
TomlError(#[from] toml::de::Error),
#[error("failed to parse json: {0}")]
WrongFieldFilter(String),
#[error("wrong regular expression: {0}")]
Expand Down
1 change: 1 addition & 0 deletions src/testing/assets/themes/invalid-type.yaml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.gitignore
9 changes: 9 additions & 0 deletions src/testing/assets/themes/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"elements": {
"input": {
"modes": [
"invalid"
]
}
}
}
74 changes: 74 additions & 0 deletions src/testing/assets/themes/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#:schema ../../../../schema/json/theme.schema.json

[elements.input]
modes = ["faint"]

[elements.time]
modes = ["faint", "italic"]

[elements.logger]
modes = ["faint", "underline"]

[elements.caller]
modes = ["faint", "italic"]

[elements.level]
foreground = "cyan"

[elements.message]
foreground = "default"
modes = ["bold"]

[elements.field]
modes = ["faint"]

[elements.key]
foreground = "green"

[elements.ellipsis]
modes = ["faint"]

[elements.object]
foreground = "yellow"

[elements.array]
foreground = "bright-yellow"

[elements.string]
foreground = "default"

[elements.number]
foreground = "bright-blue"

[elements.boolean]
foreground = "bright-green"

[elements.null]
foreground = "bright-red"

[levels.debug.level-inner]
foreground = "bright-magenta"

[levels.info.level-inner]
foreground = "cyan"

[levels.warning.level]
foreground = "yellow"
modes = ["reverse"]

[levels.error.time]
foreground = "bright-red"

[levels.error.level]
foreground = "bright-red"
modes = ["reverse"]

[indicators.sync.synced]
text = " "

[indicators.sync.failed]
text = "!"

[indicators.sync.failed.inner.style]
foreground = "yellow"
modes = ["bold"]
62 changes: 0 additions & 62 deletions src/testing/assets/themes/test.yaml

This file was deleted.

Loading

0 comments on commit f3bf36e

Please sign in to comment.