mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-15 15:18:45 +00:00
Add and use --style=auto by default
This commit is contained in:
parent
6343535eb2
commit
7cff0f7e27
17
src/main.rs
17
src/main.rs
@ -69,6 +69,7 @@ use errors::*;
|
|||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||||
pub enum OutputComponent {
|
pub enum OutputComponent {
|
||||||
|
Auto,
|
||||||
Changes,
|
Changes,
|
||||||
Grid,
|
Grid,
|
||||||
Header,
|
Header,
|
||||||
@ -78,8 +79,13 @@ pub enum OutputComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl OutputComponent {
|
impl OutputComponent {
|
||||||
fn components(&self) -> &'static [OutputComponent] {
|
fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
|
||||||
match *self {
|
match *self {
|
||||||
|
OutputComponent::Auto => if interactive_terminal {
|
||||||
|
OutputComponent::Full.components(interactive_terminal)
|
||||||
|
} else {
|
||||||
|
OutputComponent::Plain.components(interactive_terminal)
|
||||||
|
},
|
||||||
OutputComponent::Changes => &[OutputComponent::Changes],
|
OutputComponent::Changes => &[OutputComponent::Changes],
|
||||||
OutputComponent::Grid => &[OutputComponent::Grid],
|
OutputComponent::Grid => &[OutputComponent::Grid],
|
||||||
OutputComponent::Header => &[OutputComponent::Header],
|
OutputComponent::Header => &[OutputComponent::Header],
|
||||||
@ -100,6 +106,7 @@ impl FromStr for OutputComponent {
|
|||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self> {
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
match s {
|
match s {
|
||||||
|
"auto" => Ok(OutputComponent::Auto),
|
||||||
"changes" => Ok(OutputComponent::Changes),
|
"changes" => Ok(OutputComponent::Changes),
|
||||||
"grid" => Ok(OutputComponent::Grid),
|
"grid" => Ok(OutputComponent::Grid),
|
||||||
"header" => Ok(OutputComponent::Header),
|
"header" => Ok(OutputComponent::Header),
|
||||||
@ -330,8 +337,10 @@ fn run() -> Result<()> {
|
|||||||
.long("style")
|
.long("style")
|
||||||
.use_delimiter(true)
|
.use_delimiter(true)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&["full", "plain", "changes", "header", "grid", "numbers"])
|
.possible_values(&[
|
||||||
.default_value("full")
|
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
||||||
|
])
|
||||||
|
.default_value("auto")
|
||||||
.help("Additional info to display along with content"),
|
.help("Additional info to display along with content"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@ -421,7 +430,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
let output_components = values_t!(app_matches.values_of("style"), OutputComponent)?
|
let output_components = values_t!(app_matches.values_of("style"), OutputComponent)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|style| style.components())
|
.map(|style| style.components(interactive_terminal))
|
||||||
.fold(HashSet::new(), |mut acc, components| {
|
.fold(HashSet::new(), |mut acc, components| {
|
||||||
acc.extend(components.iter().cloned());
|
acc.extend(components.iter().cloned());
|
||||||
acc
|
acc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user