mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-26 18:14:18 +02:00
Add flag for specifying color preference
This commit is contained in:
parent
baffd1ea4d
commit
f757389df9
5 changed files with 31 additions and 3 deletions
|
|
@ -17,6 +17,10 @@ _tealdeer()
|
|||
COMPREPLY=( $(compgen -W 'linux osx sunos windows' -- "${cur}") )
|
||||
return
|
||||
;;
|
||||
--color)
|
||||
COMPREPLY=( $(compgen -W 'always auto never' -- "${cur}") )
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ complete -c tldr -s m -l markdown -d 'Display the raw markdown instead of ren
|
|||
complete -c tldr -s q -l quiet -d 'Suppress informational messages.' -f
|
||||
complete -c tldr -l config-path -d 'Show config file path.' -f
|
||||
complete -c tldr -l seed-config -d 'Create a basic config.' -f
|
||||
complete -c tldr -l color -d 'Controls when to use color.' -xa 'always auto never'
|
||||
|
||||
function __tealdeer_entries
|
||||
tldr --list | string replace -a -i -r "\,\s" "\n"
|
||||
|
|
|
|||
16
src/main.rs
16
src/main.rs
|
|
@ -41,7 +41,7 @@ use crate::config::{get_config_path, make_default_config, Config, MAX_CACHE_AGE}
|
|||
use crate::error::TealdeerError::{CacheError, ConfigError, UpdateError};
|
||||
use crate::formatter::print_lines;
|
||||
use crate::tokenizer::Tokenizer;
|
||||
use crate::types::OsType;
|
||||
use crate::types::{ColorOptions, OsType};
|
||||
|
||||
const NAME: &str = "tealdeer";
|
||||
const APP_INFO: AppInfo = AppInfo {
|
||||
|
|
@ -69,6 +69,7 @@ Options:
|
|||
-q --quiet Suppress informational messages
|
||||
--config-path Show config file path
|
||||
--seed-config Create a basic config
|
||||
--color <when> Control when to use color [always, auto, never] [default: auto]
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
@ -104,6 +105,7 @@ struct Args {
|
|||
flag_config_path: bool,
|
||||
flag_seed_config: bool,
|
||||
flag_markdown: bool,
|
||||
flag_color: ColorOptions,
|
||||
}
|
||||
|
||||
/// Print page by path
|
||||
|
|
@ -294,6 +296,8 @@ fn main() {
|
|||
.and_then(|d| d.deserialize())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
|
||||
println!("{:?}", args);
|
||||
|
||||
// Show version and exit
|
||||
if args.flag_version {
|
||||
let os = get_os();
|
||||
|
|
@ -313,9 +317,15 @@ fn main() {
|
|||
|
||||
// Determine the usage of styles
|
||||
#[cfg(target_os = "windows")]
|
||||
let enable_styles = ansi_term::enable_ansi_support().is_ok();
|
||||
let ansi_support = ansi_term::enable_ansi_support().is_ok();
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let enable_styles = true;
|
||||
let ansi_support = true;
|
||||
|
||||
let enable_styles = match args.flag_color {
|
||||
ColorOptions::Always => ansi_support,
|
||||
ColorOptions::Auto => ansi_support,
|
||||
ColorOptions::Never => false,
|
||||
};
|
||||
|
||||
// Look up config file, if none is found fall back to default config.
|
||||
let config = match Config::load(enable_styles) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,14 @@ impl fmt::Display for OsType {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ColorOptions {
|
||||
Always,
|
||||
Auto,
|
||||
Never,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum LineType {
|
||||
Empty,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ _tealdeer() {
|
|||
"($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]"
|
||||
"($I)--config-path[Show config file path]"
|
||||
"($I)--seed-config[Create a basic config]"
|
||||
"($I --color)"{--color}'[Controls when to use color]:when:((
|
||||
always
|
||||
auto
|
||||
never
|
||||
))'
|
||||
'(- *)'{-h,--help}'[Display help]'
|
||||
'(- *)'{-v,--version}'[Show version information]'
|
||||
'*:file:_files'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue