Skip to content
Myr

Code style udpates

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

authored by sharkdp · committed by sharkdp · parent 2403ac3 · Browse files · 3 files+80 added−53 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+80 added−53 removed

  • other:+80 added−53 removed

3 files+80 added−53 removed

modified:src/lscolors/mod.rs+3 added-3 removed
1/// A parser for the `LS_COLORS` environment variable.23use std::collections::HashMap;4use ansi_term::{Style, Colour};4use ansi_term::{Colour, Style};56/// Maps file extensions to ANSI colors / styles.7pub type ExtensionStyles = HashMap<String, Style>;8
32 unmodified lines
41 directory: Colour::Blue.bold(),42 symlink: Colour::Cyan.normal(),43 executable: Colour::Red.bold(),44 extensions: HashMap::new(),45 filenames: HashMap::new()45 filenames: HashMap::new(),46 }47 }48}49
4 unmodified lines
54 "0" | "00" => Some(Colour::normal),55 "1" | "01" => Some(Colour::bold),56 "3" | "03" => Some(Colour::italic),57 "4" | "04" => Some(Colour::underline),58 _ => None58 _ => None,59 }60 }6162 /// Parse ANSI escape sequences like `38;5;10;1`.
157 unmodified lines
modified:src/app.rs+65 added-37 removed
1use clap::{App, AppSettings, Arg};23pub fn build_app() -> App<'static, 'static> {4 App::new("fd")5 .version(crate_version!())6 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")7 .setting(AppSettings::ColoredHelp)8 .setting(AppSettings::DeriveDisplayOrder)9 .arg(Arg::with_name("hidden")5 .version(crate_version!())6 .usage("fd [FLAGS/OPTIONS] [<pattern>] [<path>]")7 .setting(AppSettings::ColoredHelp)8 .setting(AppSettings::DeriveDisplayOrder)9 .arg(10 Arg::with_name("hidden")11 .long("hidden")12 .short("H")12 .help("Search hidden files and directories"))13 .arg(Arg::with_name("no-ignore")13 .help("Search hidden files and directories"),14 )15 .arg(16 Arg::with_name("no-ignore")17 .long("no-ignore")18 .short("I")16 .help("Do not respect .(git)ignore files"))17 .arg(Arg::with_name("case-sensitive")19 .help("Do not respect .(git)ignore files"),20 )21 .arg(22 Arg::with_name("case-sensitive")23 .long("case-sensitive")24 .short("s")20 .help("Case-sensitive search (default: smart case)"))21 .arg(Arg::with_name("absolute-path")25 .help("Case-sensitive search (default: smart case)"),26 )27 .arg(28 Arg::with_name("absolute-path")29 .long("absolute-path")30 .short("a")24 .help("Show absolute instead of relative paths"))25 .arg(Arg::with_name("follow")31 .help("Show absolute instead of relative paths"),32 )33 .arg(34 Arg::with_name("follow")35 .long("follow")36 .short("L")37 .alias("dereference")29 .help("Follow symbolic links"))30 .arg(Arg::with_name("full-path")38 .help("Follow symbolic links"),39 )40 .arg(41 Arg::with_name("full-path")42 .long("full-path")43 .short("p")33 .help("Search full path (default: file-/dirname only)"))34 .arg(Arg::with_name("null_separator")44 .help("Search full path (default: file-/dirname only)"),45 )46 .arg(47 Arg::with_name("null_separator")48 .long("print0")49 .short("0")37 .help("Separate results by the null character"))38 .arg(Arg::with_name("depth")50 .help("Separate results by the null character"),51 )52 .arg(53 Arg::with_name("depth")54 .long("max-depth")55 .short("d")56 .takes_value(true)42 .help("Set maximum search depth (default: none)"))43 .arg(Arg::with_name("file-type")57 .help("Set maximum search depth (default: none)"),58 )59 .arg(60 Arg::with_name("file-type")61 .long("type")62 .short("t")63 .takes_value(true)64 .possible_values(&["f", "file", "d", "directory", "s", "symlink"])65 .hide_possible_values(true)49 .help("Filter by type: f(ile), d(irectory), s(ymlink)"))50 .arg(Arg::with_name("extension")66 .help("Filter by type: f(ile), d(irectory), s(ymlink)"),67 )68 .arg(69 Arg::with_name("extension")70 .long("extension")71 .short("e")72 .takes_value(true)73 .value_name("ext")55 .help("Filter by file extension"))56 .arg(Arg::with_name("color")74 .help("Filter by file extension"),75 )76 .arg(77 Arg::with_name("color")78 .long("color")79 .short("c")80 .takes_value(true)81 .possible_values(&["never", "auto", "always"])82 .hide_possible_values(true)83 .help(62 .help("When to use color in the output:\n\63 never, auto, always (default: auto)"))64 .arg(Arg::with_name("threads")84 "When to use color in the output:\n\85 never, auto, always (default: auto)",86 ),87 )88 .arg(89 Arg::with_name("threads")90 .long("threads")91 .short("j")92 .takes_value(true)93 .help(68 .help("Set number of threads to use for searching\n\69 (default: number of available CPU cores)"))70 .arg(Arg::with_name("max-buffer-time")94 "Set number of threads to use for searching\n\95 (default: number of available CPU cores)",96 ),97 )98 .arg(99 Arg::with_name("max-buffer-time")100 .long("max-buffer-time")101 .takes_value(true)102 .hidden(true)74 .help("the time (in ms) to buffer, before streaming to the console"))75 .arg(Arg::with_name("pattern")76 .help("the search pattern, a regular expression (optional)"))77 .arg(Arg::with_name("path")78 .help("the root directory for the filesystem search (optional)"))79}103 .help("the time (in ms) to buffer, before streaming to the console"),104 )105 .arg(Arg::with_name("pattern").help("the search pattern, a regular expression (optional)"))106 .arg(Arg::with_name("path").help("the root directory for the filesystem search (optional)"))107}
modified:src/main.rs+12 added-13 removed
15 unmodified lines
16use std::io::Write;17use std::ops::Deref;18#[cfg(target_family = "unix")]19use std::os::unix::fs::PermissionsExt;20use std::path::{Path, PathBuf, Component};20use std::path::{Component, Path, PathBuf};21use std::process;22use std::sync::Arc;23use std::sync::mpsc::channel;24use std::thread;
11 unmodified lines
36 /// As an absolute path37 Absolute,3839 /// As a relative path40 Relative40 Relative,41}4243/// The type of file to search for.44#[derive(Copy, Clone)]45enum FileType {46 Any,47 RegularFile,48 Directory,49 SymLink49 SymLink,50}5152/// Configuration options for *fd*.53struct FdOptions {
52 unmodified lines
106 /// enough.107 Buffering,108109 /// Receiver is directly printing results to the output.110 Streaming110 Streaming,111}112113/// Root directory114static ROOT_DIR : &'static str = "/";114static ROOT_DIR: &'static str = "/";115116/// Parent directory117static PARENT_DIR : &'static str = "..";117static PARENT_DIR: &'static str = "..";118119/// Print a search result to the console.120fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) {121 let path_full = base.join(entry);
6 unmodified lines
128 .unwrap_or(false)129 };130131 #[cfg(not(target_family = "unix"))]132 let is_executable = |_: Option<&std::fs::Metadata>| { false };132 let is_executable = |_: Option<&std::fs::Metadata>| false;133134 let stdout = std::io::stdout();135 let mut handle = stdout.lock();136
54 unmodified lines
191 }192 }193194 let r = if config.null_separator {195 write!(handle, "\0")195 write!(handle, "\0")196 } else {197 writeln!(handle, "")197 writeln!(handle, "")198 };199 if r.is_err() {200 // Probably a broken pipe. Exit gracefully.201 process::exit(0);
34 unmodified lines
236 let rx_base = base.to_owned();237 let receiver_thread = thread::spawn(move || {238 let start = time::Instant::now();239240 let mut buffer = vec!();240 let mut buffer = vec![];241242 // Start in buffering mode243 let mut mode = ReceiverMode::Buffering;244
43 unmodified lines
288289 Box::new(move |entry_o| {290 let entry = match entry_o {291 Ok(e) => e,292 Err(_) => return ignore::WalkState::Continue292 Err(_) => return ignore::WalkState::Continue,293 };294295 // Filter out unwanted file types.296 match config.file_type {
50 unmodified lines
347}348349/// Print error message to stderr and exit with status `1`.350fn error(message: &str) -> ! {351 writeln!(&mut std::io::stderr(), "{}", message)352 .expect("Failed writing to stderr");351 writeln!(&mut std::io::stderr(), "{}", message).expect("Failed writing to stderr");352 process::exit(1);353}354355fn main() {
103 unmodified lines