chore(deps): bump clap to 3.0.0-beta.5

This commit is contained in:
graelo 2021-10-24 09:33:55 +02:00
parent 276d17ce8f
commit 077d16311e
9 changed files with 177 additions and 186 deletions

138
Cargo.lock generated
View file

@ -1,10 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.15"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
@ -28,15 +30,15 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bitflags"
version = "1.2.1"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "clap"
version = "3.0.0-beta.2"
version = "3.0.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63"
dependencies = [
"atty",
"bitflags",
@ -48,15 +50,14 @@ dependencies = [
"termcolor",
"terminal_size",
"textwrap",
"unicode-width",
"vec_map",
"unicase",
]
[[package]]
name = "clap_derive"
version = "3.0.0-beta.2"
version = "3.0.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3"
dependencies = [
"heck",
"proc-macro-error",
@ -74,6 +75,7 @@ dependencies = [
"regex",
"sequence_trie",
"termion",
"thiserror",
]
[[package]]
@ -90,33 +92,33 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.9.1"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "indexmap"
version = "1.6.2"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
@ -130,15 +132,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.91"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7"
checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013"
[[package]]
name = "memchr"
version = "2.3.4"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "numtoa"
@ -148,9 +150,9 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "once_cell"
version = "1.7.2"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]]
name = "os_pipe"
@ -164,9 +166,12 @@ dependencies = [
[[package]]
name = "os_str_bytes"
version = "2.4.0"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799"
dependencies = [
"memchr",
]
[[package]]
name = "proc-macro-error"
@ -194,27 +199,27 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.24"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.5"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
dependencies = [
"bitflags",
]
@ -230,9 +235,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.4.5"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
@ -241,9 +246,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.23"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "sequence_trie"
@ -269,9 +274,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.65"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663"
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [
"proc-macro2",
"quote",
@ -289,9 +294,9 @@ dependencies = [
[[package]]
name = "terminal_size"
version = "0.1.16"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
@ -311,37 +316,60 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.12.1"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [
"terminal_size",
"unicode-width",
]
[[package]]
name = "unicode-segmentation"
version = "1.7.1"
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-width"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "version_check"

View file

@ -2,16 +2,18 @@
name = "copyrat"
version = "0.4.1"
authors = ["graelo <graelo@graelo.cc>"]
edition = "2018"
edition = "2021"
description = "This is tmux-copycat on Rust steroids."
repository = "https://github.com/graelo/tmux-copyrat"
keywords = ["rust", "tmux", "tmux-plugin", "tmux-copycat"]
license = "MIT"
[dependencies]
thiserror = "1"
termion = "1.5"
regex = "1.4"
clap = { version = "3.0.0-beta.2", features = ["suggestions", "color", "wrap_help"]}
regex = "1.5"
clap = { version = "3.0.0-beta.5", features = ["wrap_help"]}
sequence_trie = "0.3.6"
duct = "0.13"

View file

@ -1,9 +1,10 @@
#!/usr/bin/env zsh
# This scripts provides a default configuration for tmux-copyrat options and key bindings.
# It is run only once at tmux launch.
# This scripts provides a default configuration for tmux-copyrat options and
# key bindings. It is run only once at tmux launch.
#
# Each option and binding can be overridden in your `tmux.conf` by defining options like
# Each option and binding can be overridden in your `tmux.conf` by defining
# options like
#
# set -g @copyrat-keytable "foobar"
# set -g @copyrat-keyswitch "z"
@ -50,8 +51,9 @@ setup_option "window-name" "[copyrat]"
# Get that window name as a local variable for use in pattern bindings below.
window_name=$(tmux show-option -gqv @copyrat-window-name)
# Sets the keytable for all bindings, providing a default if @copyrat-keytable was not defined.
# Keytables open a new shortcut space: if 't' is the switcher (see below), prefix + t + <your-shortcut>
# Sets the keytable for all bindings, providing a default if @copyrat-keytable
# was not defined. Keytables open a new shortcut space: if 't' is the switcher
# (see below), prefix + t + <your-shortcut>
setup_option "keytable" "cpyrt"
# Sets the key to access the keytable: prefix + <key> + <your-shortcut>

View file

@ -1,4 +1,4 @@
use clap::Clap;
use clap::Parser;
use std::io::{self, Read};
use copyrat::{config::basic, run, ui::Selection};

View file

@ -1,14 +1,13 @@
use clap::Clap;
use std::str::FromStr;
use clap::{ArgEnum, Parser};
use crate::{
error,
error::ParseError,
textbuf::{alphabet, regexes},
ui,
};
/// Main configuration, parsed from command line.
#[derive(Clap, Debug)]
#[derive(Parser, Debug)]
#[clap(author, about, version)]
pub struct Config {
/// Alphabet to draw hints from.
@ -59,7 +58,7 @@ pub struct Config {
///
/// Underline or surround the hint for increased visibility.
/// If not provided, only the hint colors will be used.
#[clap(short = 's', long, arg_enum)]
#[clap(short = 's', long, arg_enum, rename_all = "lowercase")]
pub hint_style: Option<HintStyleArg>,
/// Chars surrounding each hint, used with `Surround` style.
@ -69,8 +68,8 @@ pub struct Config {
}
/// Type introduced due to parsing limitation,
/// as we cannot directly parse into ui::HintStyle.
#[derive(Debug, Clap)]
/// as we cannot directly parse tuples into ui::HintStyle.
#[derive(Debug, Clone, ArgEnum, Parser)]
pub enum HintStyleArg {
Bold,
Italic,
@ -78,26 +77,10 @@ pub enum HintStyleArg {
Surround,
}
impl FromStr for HintStyleArg {
type Err = error::ParseError;
fn from_str(s: &str) -> Result<Self, error::ParseError> {
match s {
"bold" => Ok(HintStyleArg::Bold),
"italic" => Ok(HintStyleArg::Italic),
"underline" => Ok(HintStyleArg::Underline),
"surrond" => Ok(HintStyleArg::Surround),
_ => Err(error::ParseError::ExpectedString(String::from(
"bold, italic, underline or surround",
))),
}
}
}
/// Try to parse a `&str` into a tuple of `char`s.
fn parse_chars(src: &str) -> Result<(char, char), error::ParseError> {
fn parse_chars(src: &str) -> Result<(char, char), ParseError> {
if src.chars().count() != 2 {
return Err(error::ParseError::ExpectedSurroundingPair);
return Err(ParseError::ExpectedSurroundingPair);
}
let chars: Vec<char> = src.chars().collect();

View file

@ -1,15 +1,15 @@
use clap::Clap;
use std::collections::HashMap;
use std::fmt;
use std::str::FromStr;
use clap::{ArgEnum, Parser};
use super::basic;
use crate::{error, textbuf::alphabet, tmux, ui};
use crate::{error::ParseError, textbuf::alphabet, tmux, ui};
/// Extended configuration for handling Tmux-specific configuration (options
/// and outputs). This is only used by `tmux-copyrat` and parsed from command
/// line..
#[derive(Clap, Debug)]
/// line.
#[derive(Parser, Debug)]
#[clap(author, about, version)]
pub struct ConfigExt {
/// Don't read options from Tmux.
@ -30,13 +30,19 @@ pub struct ConfigExt {
pub window_name: String,
/// Capture visible area or entire pane history.
#[clap(long, arg_enum, default_value = "visible-area")]
#[clap(
arg_enum,
long,
rename_all = "kebab-case",
default_value = "visible-area"
)]
pub capture_region: CaptureRegion,
/// Name of the copy-to-clipboard executable.
///
/// If during execution, the output destination is set to be clipboard,
/// then copyrat will pipe the selected text to this executable.
/// On macOS, this is `pbcopy`, on Linux, this is `xclip`.
#[clap(long, default_value = "pbcopy")]
pub clipboard_exe: String,
@ -46,46 +52,54 @@ pub struct ConfigExt {
}
impl ConfigExt {
pub fn initialize() -> Result<ConfigExt, error::ParseError> {
pub fn initialize() -> Result<ConfigExt, ParseError> {
let mut config_ext = ConfigExt::parse();
if !config_ext.ignore_tmux_options {
let tmux_options: HashMap<String, String> = tmux::get_options("@copyrat-")?;
// Override default values with those coming from tmux.
let wrapped = &mut config_ext.basic_config;
let inner = &mut config_ext.basic_config;
for (name, value) in &tmux_options {
match name.as_ref() {
"@copyrat-capture-region" => {
config_ext.capture_region = CaptureRegion::from_str(&value)?
let case_insensitive = true;
config_ext.capture_region = CaptureRegion::from_str(value, case_insensitive)
.map_err(ParseError::ExpectedEnumVariant)?
}
"@copyrat-alphabet" => {
wrapped.alphabet = alphabet::parse_alphabet(value)?;
inner.alphabet = alphabet::parse_alphabet(value)?;
}
"@copyrat-reverse" => {
wrapped.reverse = value.parse::<bool>()?;
inner.reverse = value.parse::<bool>()?;
}
"@copyrat-unique-hint" => {
wrapped.unique_hint = value.parse::<bool>()?;
inner.unique_hint = value.parse::<bool>()?;
}
"@copyrat-span-fg" => wrapped.colors.span_fg = ui::colors::parse_color(value)?,
"@copyrat-span-bg" => wrapped.colors.span_bg = ui::colors::parse_color(value)?,
"@copyrat-span-fg" => inner.colors.span_fg = ui::colors::parse_color(value)?,
"@copyrat-span-bg" => inner.colors.span_bg = ui::colors::parse_color(value)?,
"@copyrat-focused-fg" => {
wrapped.colors.focused_fg = ui::colors::parse_color(value)?
inner.colors.focused_fg = ui::colors::parse_color(value)?
}
"@copyrat-focused-bg" => {
wrapped.colors.focused_bg = ui::colors::parse_color(value)?
inner.colors.focused_bg = ui::colors::parse_color(value)?
}
"@copyrat-hint-fg" => wrapped.colors.hint_fg = ui::colors::parse_color(value)?,
"@copyrat-hint-bg" => wrapped.colors.hint_bg = ui::colors::parse_color(value)?,
"@copyrat-hint-fg" => inner.colors.hint_fg = ui::colors::parse_color(value)?,
"@copyrat-hint-bg" => inner.colors.hint_bg = ui::colors::parse_color(value)?,
"@copyrat-hint-alignment" => {
wrapped.hint_alignment = ui::HintAlignment::from_str(&value)?
let case_insensitive = true;
inner.hint_alignment = ui::HintAlignment::from_str(value, case_insensitive)
.map_err(ParseError::ExpectedEnumVariant)?
}
"@copyrat-hint-style" => {
wrapped.hint_style = Some(basic::HintStyleArg::from_str(&value)?)
let case_insensitive = true;
inner.hint_style = Some(
basic::HintStyleArg::from_str(value, case_insensitive)
.map_err(ParseError::ExpectedEnumVariant)?,
)
}
// Ignore unknown options.
@ -98,11 +112,11 @@ impl ConfigExt {
}
}
#[derive(Clap, Debug)]
/// Specifies which region of the terminal buffer to capture.
#[derive(Debug, Clone, ArgEnum, Parser)]
pub enum CaptureRegion {
/// The entire history.
///
/// This will end up sending `-S - -E -` to `tmux capture-pane`.
// This will end up sending `-S - -E -` to `tmux capture-pane`.
EntireHistory,
/// The visible area.
VisibleArea,
@ -112,20 +126,6 @@ pub enum CaptureRegion {
//Region(i32, i32),
}
impl FromStr for CaptureRegion {
type Err = error::ParseError;
fn from_str(s: &str) -> Result<Self, error::ParseError> {
match s {
"entire-history" => Ok(CaptureRegion::EntireHistory),
"visible-area" => Ok(CaptureRegion::VisibleArea),
_ => Err(error::ParseError::ExpectedString(String::from(
"entire-history or visible-area",
))),
}
}
}
/// Describes the type of buffer the selected should be copied to: either a
/// tmux buffer or the system clipboard.
#[derive(Clone)]

View file

@ -1,50 +1,43 @@
use std::fmt;
// use std::fmt;
#[derive(Debug)]
#[derive(thiserror::Error, Debug)]
pub enum ParseError {
#[error("Expected 2 chars")]
ExpectedSurroundingPair,
#[error("Unknown alphabet")]
UnknownAlphabet,
#[error("Unknown ANSI color name: allowed values are magenta, cyan, black, ...")]
UnknownColor,
#[error("Unknown pattern name")]
UnknownPatternName,
#[error("Expected a pane id marker")]
ExpectedPaneIdMarker,
ExpectedInt(std::num::ParseIntError),
ExpectedBool(std::str::ParseBoolError),
#[error("Failed parsing integer")]
ExpectedInt {
#[from]
source: std::num::ParseIntError,
},
#[error("Failed to parse bool")]
ExpectedBool {
#[from]
source: std::str::ParseBoolError,
},
#[error("Expected the string `{0}`")]
ExpectedString(String),
ProcessFailure(String),
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::ExpectedSurroundingPair => write!(f, "Expected 2 chars"),
ParseError::UnknownAlphabet => write!(f, "Expected a known alphabet"),
ParseError::UnknownColor => {
write!(f, "Expected ANSI color name (magenta, cyan, black, ...)")
}
ParseError::UnknownPatternName => write!(f, "Expected a known pattern name"),
ParseError::ExpectedPaneIdMarker => write!(f, "Expected pane id marker"),
ParseError::ExpectedInt(msg) => write!(f, "Expected an int: {}", msg),
ParseError::ExpectedBool(msg) => write!(f, "Expected a bool: {}", msg),
ParseError::ExpectedString(msg) => write!(f, "Expected {}", msg),
ParseError::ProcessFailure(msg) => write!(f, "{}", msg),
}
}
}
#[error("Expected the value to be within `{0}`")]
ExpectedEnumVariant(String),
impl From<std::num::ParseIntError> for ParseError {
fn from(error: std::num::ParseIntError) -> Self {
ParseError::ExpectedInt(error)
}
}
impl From<std::str::ParseBoolError> for ParseError {
fn from(error: std::str::ParseBoolError) -> Self {
ParseError::ExpectedBool(error)
}
}
impl From<std::io::Error> for ParseError {
fn from(error: std::io::Error) -> Self {
ParseError::ProcessFailure(error.to_string())
}
#[error("IOError: `{source}`")]
Io {
#[from]
source: std::io::Error,
},
}

View file

@ -1,5 +1,5 @@
use crate::error;
use clap::Clap;
use clap::Parser;
use termion::color;
pub fn parse_color(src: &str) -> Result<Box<dyn color::Color>, error::ParseError> {
@ -52,7 +52,7 @@ mod tests {
/// - `focus_*` colors are used to render the currently focused text span.
/// - `normal_*` colors are used to render other text spans.
/// - `hint_*` colors are used to render the hints.
#[derive(Clap, Debug)]
#[derive(Parser, Debug)]
#[clap(about)] // Needed to avoid this doc comment to be used as overall `about`.
pub struct UiColors {
/// Foreground color for base text.

View file

@ -1,26 +1,9 @@
use clap::Clap;
use std::str::FromStr;
use crate::error::ParseError;
use clap::{ArgEnum, Parser};
/// Describes if, during rendering, a hint should aligned to the leading edge of
/// the matched text, or to its trailing edge.
#[derive(Debug, Clap)]
#[derive(Debug, Clone, ArgEnum, Parser)]
pub enum HintAlignment {
Leading,
Trailing,
}
impl FromStr for HintAlignment {
type Err = ParseError;
fn from_str(s: &str) -> Result<HintAlignment, ParseError> {
match s {
"leading" => Ok(HintAlignment::Leading),
"trailing" => Ok(HintAlignment::Trailing),
_ => Err(ParseError::ExpectedString(String::from(
"leading or trailing",
))),
}
}
}