1 //! Random and miscellaneous utils used in ouch.
3 //! In here we have the logic for custom formatting, some file and directory utils, and user
4 //! stdin interaction helpers.
12 pub use file_visibility::FileVisibilityPolicy;
13 pub use formatting::{nice_directory_display, pretty_format_list_of_paths, strip_cur_dir, to_utf, EscapedPathDisplay};
15 cd_into_same_dir_as, clear_path, create_dir_if_non_existent, is_symlink, remove_file_or_dir, try_infer_extension,
18 ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy,
20 pub use utf8::{get_invalid_utf8_paths, is_invalid_utf8};
23 use std::{ffi::OsStr, path::PathBuf};
25 /// Check, without allocating, if os_str can be converted into &str
26 pub fn is_invalid_utf8(os_str: impl AsRef<OsStr>) -> bool {
27 os_str.as_ref().to_str().is_none()
30 /// Filter out list of paths that are not utf8 valid
31 pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<&PathBuf> {
34 .filter_map(|path| is_invalid_utf8(path).then_some(path))