mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
ls: implement --color=auto behavior
The automatic behavior is to turn on colors only of connected to a terminal. Introduce new external crate isatty to handle this. Signed-off-by: Gabriel Ganne <gabriel.ganne@gmail.com>
This commit is contained in:
parent
edaf2d85cb
commit
64009b090f
2 changed files with 4 additions and 1 deletions
|
@ -10,6 +10,7 @@ path = "ls.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "0.2.18"
|
getopts = "0.2.18"
|
||||||
|
isatty = "0.1"
|
||||||
number_prefix = "0.2.8"
|
number_prefix = "0.2.8"
|
||||||
term_grid = "0.1.5"
|
term_grid = "0.1.5"
|
||||||
termsize = "0.1.6"
|
termsize = "0.1.6"
|
||||||
|
|
|
@ -14,6 +14,8 @@ extern crate termsize;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate unicode_width;
|
extern crate unicode_width;
|
||||||
extern crate number_prefix;
|
extern crate number_prefix;
|
||||||
|
extern crate isatty;
|
||||||
|
use isatty::stdout_isatty;
|
||||||
use number_prefix::{Standalone, Prefixed, decimal_prefix};
|
use number_prefix::{Standalone, Prefixed, decimal_prefix};
|
||||||
use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
|
use term_grid::{Cell, Direction, Filling, Grid, GridOptions};
|
||||||
use time::{strftime, Timespec};
|
use time::{strftime, Timespec};
|
||||||
|
@ -615,7 +617,7 @@ fn display_file_name(
|
||||||
None => true,
|
None => true,
|
||||||
Some(val) => match val.as_ref() {
|
Some(val) => match val.as_ref() {
|
||||||
"always" | "yes" | "force" => true,
|
"always" | "yes" | "force" => true,
|
||||||
"auto" | "tty" | "if-tty" => true, /* TODO */
|
"auto" | "tty" | "if-tty" => stdout_isatty(),
|
||||||
"never" | "no" | "none" | _ => false,
|
"never" | "no" | "none" | _ => false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue