pub fn complete_path(buffer: &str, for_dir: bool) -> Vec<Completion> {
    let mut res = Vec::new();
    let mut path_sep = String::new();
    let mut path = String::new();
    if !buffer.ends_with(' ') {
        let tokens = parsers::parser_line::cmd_to_tokens(buffer);
        if tokens.is_empty() {
            return res;
        }

        let (ref _path_sep, ref _path) = tokens[tokens.len() - 1];
        path = _path.clone();
        path_sep = _path_sep.clone();
    }
    let (_dir_orig, _) = split_path(&path);
    let dir_orig = if let Some(_dir) = _dir_orig { _dir } else { "" };
    // let mut path_extended = String::from(path);
    let mut path_extended = path.clone();
    if tools::needs_extend_home(path_extended.as_str()) {
        tools::extend_home(&mut path_extended)
    }
    let (_dir_lookup, file_name) = split_path(path_extended.as_str());
    let dir_lookup = _dir_lookup.unwrap_or(".");
    if let Ok(entries) = read_dir(dir_lookup) {
        for entry in entries {
            if let Ok(entry) = entry {
                let pathbuf = entry.path();
                let is_dir = pathbuf.is_dir();
                if for_dir && !is_dir {
                    continue;
                }

                let entry_name = entry.file_name();
                // TODO: Deal with non-UTF8 paths in some way
                if let Ok(_path) = entry_name.into_string() {
                    if _path.starts_with(file_name) {
                        let (name, display) = if dir_orig != "" {
                            (
                                format!("{}{}{}", dir_orig, MAIN_SEPARATOR, _path),
                                Some(_path)
                            )
                        } else {
                            (_path, None)
                        };
                        let mut name = str::replace(name.as_str(), "//", "/");
                        if path_sep.is_empty() {
                            name = str::replace(name.as_str(), " ", "\\ ");
                        }
                        let suffix = if is_dir {
                            Suffix::Some(MAIN_SEPARATOR)
                        } else {
                            Suffix::Default
                        };
                        res.push(Completion {
                            completion: name,
                            display: display,
                            suffix: suffix,
                        });
                    }
                }
            }
        }
    }
    res
}
/// Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path .
pub fn complete_path(buffer: &str, for_dir: bool) -> Vec<Completion> {
    let mut res = Vec::new();
    let mut path_sep = String::new();
    let mut path = String::new();
    if !buffer.ends_with(' ') {
        let tokens = parsers::parser_line::cmd_to_tokens(buffer);
        if tokens.is_empty() {
            return res;
        }
        let (ref _path_sep, ref _path) = tokens[tokens.len() - 1];
        path = _path.clone();
        path_sep = _path_sep.clone();
    }
    let (_dir_orig, _) = split_path(&path);
    let dir_orig = if let Some(_dir) = _dir_orig { _dir } else { "" };
    // let mut path_extended = String::from(path);
    let mut path_extended = path.clone();
    if tools::needs_extend_home(path_extended.as_str()) {
        tools::extend_home(&mut path_extended)
    }
    let (_dir_lookup, file_name) = split_path(path_extended.as_str());
    let dir_lookup = _dir_lookup.unwrap_or(".");
    if let Ok(entries) = read_dir(dir_lookup) {
        for entry in entries {
            if let Ok(entry) = entry {
                let pathbuf = entry.path();
                let is_dir = pathbuf.is_dir();
                if for_dir && !is_dir {
                    continue;
                }
                let entry_name = entry.file_name();
                // TODO: Deal with non-UTF8 paths in some way
                if let Ok(_path) = entry_name.into_string() {
                    if _path.starts_with(file_name) {
                        let (name, display) = if dir_orig != "" {
                            (
                                format!("{}{}{}", dir_orig, MAIN_SEPARATOR, _path),
                                Some(_path)
                            )
                        } else {
                            (_path, None)
                        };
                        let mut name = str::replace(name.as_str(), "//", "/");
                        if path_sep.is_empty() {
                            name = str::replace(name.as_str(), " ", "\\ ");
                        }
                        let suffix = if is_dir {
                            Suffix::Some(MAIN_SEPARATOR)
                        } else {
                            Suffix::Default
                        };
                        res.push(Completion {
                            completion: name,
                            display: display,
                            suffix: suffix,
                        });
                    }
                }
            }
        }
    }
    res
}
pub fn complete_path ( buffer : & str , for_dir : bool ) -> Vec < Completion > { let mut res = Vec :: new ( ) ; let mut path_sep = String :: new ( ) ; let mut path = String :: new ( ) ; if ! buffer . ends_with ( ' ' ) { let tokens = parsers :: parser_line :: cmd_to_tokens ( buffer ) ; if tokens . is_empty ( ) { return res ; } let ( ref _path_sep , ref _path ) = tokens [ tokens . len ( ) - 1 ] ; path = _path . clone ( ) ; path_sep = _path_sep . clone ( ) ; } let ( _dir_orig , _ ) = split_path ( & path ) ; let dir_orig = if let Some ( _dir ) = _dir_orig { _dir } else { " " } ; // let mut path_extended = String::from(path); let mut path_extended = path . clone ( ) ; if tools :: needs_extend_home ( path_extended . as_str ( ) ) { tools :: extend_home ( & mut path_extended ) } let ( _dir_lookup , file_name ) = split_path ( path_extended . as_str ( ) ) ; let dir_lookup = _dir_lookup . unwrap_or ( " " ) ; if let Ok ( entries ) = read_dir ( dir_lookup ) { for entry in entries { if let Ok ( entry ) = entry { let pathbuf = entry . path ( ) ; let is_dir = pathbuf . is_dir ( ) ; if for_dir && ! is_dir { continue ; } let entry_name = entry . file_name ( ) ; // TODO: Deal with non-UTF8 paths in some way if let Ok ( _path ) = entry_name . into_string ( ) { if _path . starts_with ( file_name ) { let ( name , display ) = if dir_orig != " " { ( format ! ( " " dir_orig MAIN_SEPARATOR _path ) , Some ( _path ) ) } else { ( _path , None ) } ; let mut name = str :: replace ( name . as_str ( ) , " " , " " ) ; if path_sep . is_empty ( ) { name = str :: replace ( name . as_str ( ) , " " , " \\ " ) ; } let suffix = if is_dir { Suffix :: Some ( MAIN_SEPARATOR ) } else { Suffix :: Default } ; res . push ( Completion { completion : name , display : display , suffix : suffix , } ) ; } } } } } res }
Returns a sorted list of paths whose prefix matches the given path.
Returns a sorted list of paths whose prefix matches the given path .
buffer
&str
for_dir
bool
buffer
&str
for_dir
bool