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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ body:
value: |
```json
{
"$schema": "https://raw.githubusercontent.com/MuntasirSZN/getquotes/refs/heads/main/config.schema.json",
"$schema": "https://raw.githubusercontent.com/MuntasirSZN/getquotes/refs/heads/main/config/config.schema.json",
"authors": [
"Mahatma Gandhi",
"Albert Einstein",
Expand Down
76 changes: 75 additions & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ clap = { version = "4.6.1", features = [
] }
clap_complete = "4.6.5"
clap_complete_nushell = "4.6.0"
colored = "3.1.1"
git_rev = "0.1.0"
jiff = "0.2.24"
log = "0.4.29"
Expand All @@ -42,6 +41,10 @@ tokio = { version = "1", features = ["full"] }
toml = "1.1.2"
urlencoding = "2.1.3"
env_logger = "0.11.10"
cssparser = "0.37.0"
cssparser-color = "0.5.0"
anstyle = "1.0.14"
schemars = "1.2.1"

[dev-dependencies]
lazy_static = "1.5.0"
Expand Down
51 changes: 42 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

- **Fetch Quotes**: Get random quotes from Wikiquote. 📜
- **Custom Authors**: Specify authors to fetch quotes from. 🖋️
- **Rainbow Mode**: Display quotes in random colors. 🌈
- **Rainbow Mode**: Display quotes with a real rainbow gradient. 🌈
- **Offline Mode**: Use cached quotes when offline. 📴
- **Configurable**: Customize theme color, log file, and more via a TOML configuration file. 🛠️
- **Configurable**: Customize colors, gradients, text styles, layout, log file, and more via a TOML configuration file. 🛠️
- **Lightweight**: Fast and efficient, written in Rust. ⚡

---
Expand Down Expand Up @@ -87,7 +87,13 @@ Get-Help getquotes

## 🧭 Configuration

getquotes can be configured using a TOML configuration file. The configuration file should adhere to the schema defined in `config.schema.toml`, which can be validated using [Taplo](https://taplo.tamasfe.dev/). Here's an example of a configuration file:
getquotes can be configured using a TOML configuration file. The configuration file schema is generated from Rust types with `schemars` and written to `config/config.schema.json`. You can use this schema in editors powered by [Taplo](https://taplo.tamasfe.dev/) or [Tombi](https://tombi-toml.github.io/tombi/). Add this at the top of your config file:

```toml
#:schema https://raw.githubusercontent.com/MuntasirSZN/getquotes/refs/heads/main/config/config.schema.json
```

Here's an example of a configuration file:

```toml
# List of authors to fetch quotes from
Expand All @@ -96,25 +102,46 @@ authors = [
"Isaac Newton"
]

# Theme color in hex format
theme_color = "#FF5733"
# Theme color supports hex, rgb/rgba, hsl, or CSS-inspired gradients
theme_color = "conic-gradient(from 90deg, #FF5733, hsl(45, 100%, 50%), rgb(0, 170, 255))"

# Extra styling for the quote text
quote_style = "bold"

# Styling for the author line
author_style = "italic,green"

# Optional styling for nested quotes inside the quote text
nested_quote_style = "underline"

# Maximum number of attempts to fetch a quote
max_tries = 50

# Log file path
log_file = "custom_getquotes.log"

# Enable rainbow mode for random colors
# Enable rainbow mode for a true rainbow gradient
rainbow_mode = false

# Output layout: "default" or "box"
layout = "default"

# Box corner style when layout = "box": "pointy" or "rounded"
box_corners = "pointy"
```

### Properties

- **authors**: An array of author names to fetch quotes from. At least one author must be specified.
- **theme_color**: A hex color code (with or without a leading #) for theming the output.
- **theme_color**: The base quote color. Supports hex, `rgb(...)`, `rgba(...)`, `hsl(...)`, and CSS-inspired gradient functions such as `linear-gradient(...)`, `radial-gradient(...)`, `conic-gradient(...)`, and repeating variants.
- **quote_style**: Comma-separated quote styling tokens such as `bold`, `italic`, `underline`, `strikethrough`, colors, or gradients.
- **author_style**: Comma-separated styling tokens for the author line.
- **nested_quote_style**: Optional styling applied to quotes found inside the main quote text.
- **max_tries**: The maximum number of attempts to find a quote (between 1 and 100, default is 30).
- **log_file**: The path to the log file (default is "getquotes.log").
- **rainbow_mode**: Overrides the quote color with a rainbow gradient.
- **layout**: `default` keeps the current layout, while `box` renders the quote and author inside a box.
- **box_corners**: Chooses `pointy` (`+`, `|`, `-`) or `rounded` (`╭`, `╮`, `╰`, `╯`, `│`, `─`) corners for box layout.

---

Expand All @@ -130,7 +157,8 @@ Options:
-t, --theme-color <THEME_COLOR> Set the theme color for the displayed quotes
-m, --max-tries <MAX_TRIES> Set the maximum number of tries to fetch a quote
-l, --log-file <LOG_FILE> Specify the log file path
-r, --rainbow-mode Enable rainbow mode for random quote colors
-r, --rainbow-mode [<RAINBOW_MODE>]
Enable rainbow mode for gradient rainbow quote colors
-i, --init-cache Initialize the quote cache for offline mode
-o, --offline Run in offline mode, using cached quotes
-v, --version Print version information
Expand All @@ -155,7 +183,12 @@ Please make sure to follow our [Code of Conduct](CODE_OF_CONDUCT.md) and [Contri

### Configuration Schema

The configuration schema is defined in `config.schema.toml`. Any contributions affecting the configuration should update this schema accordingly.
The configuration schema file is `config/config.schema.json`, generated from `Config` via `schemars`.
If you change configuration fields, run:

```bash
cargo run --bin generate_config_schema
```

---

Expand Down
4 changes: 2 additions & 2 deletions completions/_getquotes
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ _getquotes() {
'--max-tries=[Set the maximum number of tries to fetch a quote]:MAX_TRIES:_default' \
'-l+[Specify the log file path]:LOG_FILE:_default' \
'--log-file=[Specify the log file path]:LOG_FILE:_default' \
'-r+[Enable rainbow mode for gradient rainbow quote colors]::RAINBOW_MODE:(true false)' \
'--rainbow-mode=[Enable rainbow mode for gradient rainbow quote colors]::RAINBOW_MODE:(true false)' \
'-C+[Use a custom TOML configuration file]:CONFIG:_default' \
'--config=[Use a custom TOML configuration file]:CONFIG:_default' \
'-c+[Generate shell completion script]:COMPLETION:(bash elvish fish powershell zsh nushell)' \
'--completion=[Generate shell completion script]:COMPLETION:(bash elvish fish powershell zsh nushell)' \
'-r[Enable rainbow mode for random quote colors]' \
'--rainbow-mode[Enable rainbow mode for random quote colors]' \
'-i[Initialize the quote cache for offline mode]' \
'--init-cache[Initialize the quote cache for offline mode]' \
'-o[Run in offline mode, using cached quotes]' \
Expand Down
4 changes: 2 additions & 2 deletions completions/_getquotes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Register-ArgumentCompleter -Native -CommandName 'getquotes' -ScriptBlock {
[CompletionResult]::new('--max-tries', '--max-tries', [CompletionResultType]::ParameterName, 'Set the maximum number of tries to fetch a quote')
[CompletionResult]::new('-l', '-l', [CompletionResultType]::ParameterName, 'Specify the log file path')
[CompletionResult]::new('--log-file', '--log-file', [CompletionResultType]::ParameterName, 'Specify the log file path')
[CompletionResult]::new('-r', '-r', [CompletionResultType]::ParameterName, 'Enable rainbow mode for gradient rainbow quote colors')
[CompletionResult]::new('--rainbow-mode', '--rainbow-mode', [CompletionResultType]::ParameterName, 'Enable rainbow mode for gradient rainbow quote colors')
[CompletionResult]::new('-C', '-C ', [CompletionResultType]::ParameterName, 'Use a custom TOML configuration file')
[CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Use a custom TOML configuration file')
[CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Generate shell completion script')
[CompletionResult]::new('--completion', '--completion', [CompletionResultType]::ParameterName, 'Generate shell completion script')
[CompletionResult]::new('-r', '-r', [CompletionResultType]::ParameterName, 'Enable rainbow mode for random quote colors')
[CompletionResult]::new('--rainbow-mode', '--rainbow-mode', [CompletionResultType]::ParameterName, 'Enable rainbow mode for random quote colors')
[CompletionResult]::new('-i', '-i', [CompletionResultType]::ParameterName, 'Initialize the quote cache for offline mode')
[CompletionResult]::new('--init-cache', '--init-cache', [CompletionResultType]::ParameterName, 'Initialize the quote cache for offline mode')
[CompletionResult]::new('-o', '-o', [CompletionResultType]::ParameterName, 'Run in offline mode, using cached quotes')
Expand Down
8 changes: 8 additions & 0 deletions completions/getquotes.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ _getquotes() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--rainbow-mode)
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
return 0
;;
-r)
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
return 0
;;
--config)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down
4 changes: 2 additions & 2 deletions completions/getquotes.elv
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ set edit:completion:arg-completer[getquotes] = {|@words|
cand --max-tries 'Set the maximum number of tries to fetch a quote'
cand -l 'Specify the log file path'
cand --log-file 'Specify the log file path'
cand -r 'Enable rainbow mode for gradient rainbow quote colors'
cand --rainbow-mode 'Enable rainbow mode for gradient rainbow quote colors'
cand -C 'Use a custom TOML configuration file'
cand --config 'Use a custom TOML configuration file'
cand -c 'Generate shell completion script'
cand --completion 'Generate shell completion script'
cand -r 'Enable rainbow mode for random quote colors'
cand --rainbow-mode 'Enable rainbow mode for random quote colors'
cand -i 'Initialize the quote cache for offline mode'
cand --init-cache 'Initialize the quote cache for offline mode'
cand -o 'Run in offline mode, using cached quotes'
Expand Down
3 changes: 2 additions & 1 deletion completions/getquotes.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ complete -c getquotes -s a -l authors -d 'Specify a list of authors to fetch quo
complete -c getquotes -s t -l theme-color -d 'Set the theme color for the displayed quotes' -r
complete -c getquotes -s m -l max-tries -d 'Set the maximum number of tries to fetch a quote' -r
complete -c getquotes -s l -l log-file -d 'Specify the log file path' -r
complete -c getquotes -s r -l rainbow-mode -d 'Enable rainbow mode for gradient rainbow quote colors' -r -f -a "true\t''
false\t''"
complete -c getquotes -s C -l config -d 'Use a custom TOML configuration file' -r
complete -c getquotes -s c -l completion -d 'Generate shell completion script' -r -f -a "bash\t''
elvish\t''
fish\t''
powershell\t''
zsh\t''
nushell\t''"
complete -c getquotes -s r -l rainbow-mode -d 'Enable rainbow mode for random quote colors'
complete -c getquotes -s i -l init-cache -d 'Initialize the quote cache for offline mode'
complete -c getquotes -s o -l offline -d 'Run in offline mode, using cached quotes'
complete -c getquotes -s v -l version -d 'Print version information'
Expand Down
6 changes: 5 additions & 1 deletion completions/getquotes.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module completions {

def "nu-complete getquotes rainbow_mode" [] {
[ "true" "false" ]
}

def "nu-complete getquotes completion" [] {
[ "bash" "elvish" "fish" "powershell" "zsh" "nushell" ]
}
Expand All @@ -10,7 +14,7 @@ module completions {
--theme-color(-t): string # Set the theme color for the displayed quotes
--max-tries(-m): string # Set the maximum number of tries to fetch a quote
--log-file(-l): string # Specify the log file path
--rainbow-mode(-r) # Enable rainbow mode for random quote colors
--rainbow-mode(-r): string@"nu-complete getquotes rainbow_mode" # Enable rainbow mode for gradient rainbow quote colors
--init-cache(-i) # Initialize the quote cache for offline mode
--offline(-o) # Run in offline mode, using cached quotes
--version(-v) # Print version information
Expand Down
Loading
Loading