Skip to content
Myr

Colored output, closes #8

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent b1baa5c · Browse files · 3 files+27 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+27 added−7 removed

  • other:+27 added−7 removed

3 files+27 added−7 removed

modified:src/main.rs+19 added-7 removed
1extern crate walkdir;2extern crate regex;3extern crate getopts;4extern crate ansi_term;56use std::env;7use std::path::Path;8use std::io::Write;
2 unmodified lines
1112use walkdir::{WalkDir, DirEntry, WalkDirIterator};13use regex::{Regex, RegexBuilder};14use getopts::Options;15use ansi_term::Colour;1617/// Print a search result to the console.18fn print_entry(entry: &DirEntry, path_str: &str) {19 let style = match entry {20 e if e.path_is_symbolic_link() => Colour::Purple,21 e if e.path().is_dir() => Colour::Cyan,22 _ => Colour::White23 };24 println!("{}", style.paint(path_str));25}2627/// Check if filename of entry starts with a dot.28fn is_hidden(entry: &DirEntry) -> bool {29 entry.file_name()30 .to_str()
10 unmodified lines
41 if entry.path() == root {42 continue;43 }4433 let path_str_r = entry34 .path()35 .strip_prefix(root) // create relative path36 .ok()37 .and_then(Path::to_str);45 let path_relative =46 match entry.path().strip_prefix(root) {47 Ok(r) => r,48 Err(_) => continue49 };5039 let path_str = match path_str_r {51 let path_str = match path_relative.to_str() {52 Some(p) => p,53 None => continue54 };5556 pattern.find(path_str)45 .map(|_| println!("{}", path_str));57 .map(|_| print_entry(&entry, path_str));58 }59}6061/// Print error message to stderr and exit with status `1`.
41 unmodified lines
modified:Cargo.lock+7 added
1[root]2name = "fd"3version = "0.1.0"4dependencies = [5 "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",6 "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",7 "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",8 "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",9]
6 unmodified lines
16 "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",17]1819[[package]]20name = "ansi_term"21version = "0.9.0"22source = "registry+https://github.com/rust-lang/crates.io-index"2324[[package]]25name = "getopts"26version = "0.2.14"27source = "registry+https://github.com/rust-lang/crates.io-index"28
102 unmodified lines
131source = "registry+https://github.com/rust-lang/crates.io-index"132133[metadata]134"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"135"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"136"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"137"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"138"checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"139"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
11 unmodified lines
modified:Cargo.toml+1 added