mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
Minor import and module exporting changes
This commit is contained in:
parent
2d2a018cbe
commit
552096acf0
@ -22,7 +22,7 @@ use crate::{
|
|||||||
info,
|
info,
|
||||||
list::{self, ListOptions},
|
list::{self, ListOptions},
|
||||||
utils::{
|
utils::{
|
||||||
self, concatenate_list_of_os_str, dir_is_empty, nice_directory_display, to_utf, try_infer,
|
self, concatenate_list_of_os_str, dir_is_empty, nice_directory_display, to_utf, try_infer_extension,
|
||||||
user_wants_to_continue_decompressing,
|
user_wants_to_continue_decompressing,
|
||||||
},
|
},
|
||||||
warning, Opts, QuestionPolicy, Subcommand,
|
warning, Opts, QuestionPolicy, Subcommand,
|
||||||
@ -495,7 +495,7 @@ fn check_mime_type(
|
|||||||
if format.is_empty() {
|
if format.is_empty() {
|
||||||
// File with no extension
|
// File with no extension
|
||||||
// Try to detect it automatically and prompt the user about it
|
// Try to detect it automatically and prompt the user about it
|
||||||
if let Some(detected_format) = try_infer(path) {
|
if let Some(detected_format) = try_infer_extension(path) {
|
||||||
info!("Detected file: `{}` extension as `{}`", path.display(), detected_format);
|
info!("Detected file: `{}` extension as `{}`", path.display(), detected_format);
|
||||||
if user_wants_to_continue_decompressing(path, question_policy)? {
|
if user_wants_to_continue_decompressing(path, question_policy)? {
|
||||||
format.push(detected_format);
|
format.push(detected_format);
|
||||||
@ -503,7 +503,7 @@ fn check_mime_type(
|
|||||||
return Ok(ControlFlow::Break(()));
|
return Ok(ControlFlow::Break(()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(detected_format) = try_infer(path) {
|
} else if let Some(detected_format) = try_infer_extension(path) {
|
||||||
// File ending with extension
|
// File ending with extension
|
||||||
// Try to detect the extension and warn the user if it differs from the written one
|
// Try to detect the extension and warn the user if it differs from the written one
|
||||||
let outer_ext = format.iter().next().unwrap();
|
let outer_ext = format.iter().next().unwrap();
|
||||||
|
@ -4,6 +4,8 @@ use std::{
|
|||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
env,
|
env,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
|
fs::ReadDir,
|
||||||
|
io::Read,
|
||||||
path::{Component, Path, PathBuf},
|
path::{Component, Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -13,7 +15,7 @@ use crate::{extension::Extension, info};
|
|||||||
|
|
||||||
/// Checks given path points to an empty directory.
|
/// Checks given path points to an empty directory.
|
||||||
pub fn dir_is_empty(dir_path: &Path) -> bool {
|
pub fn dir_is_empty(dir_path: &Path) -> bool {
|
||||||
let is_empty = |mut rd: std::fs::ReadDir| rd.next().is_none();
|
let is_empty = |mut rd: ReadDir| rd.next().is_none();
|
||||||
|
|
||||||
dir_path.read_dir().map(is_empty).unwrap_or_default()
|
dir_path.read_dir().map(is_empty).unwrap_or_default()
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ pub fn nice_directory_display(os_str: impl AsRef<OsStr>) -> Cow<'static, str> {
|
|||||||
|
|
||||||
/// Try to detect the file extension by looking for known magic strings
|
/// Try to detect the file extension by looking for known magic strings
|
||||||
/// Source: https://en.wikipedia.org/wiki/List_of_file_signatures
|
/// Source: https://en.wikipedia.org/wiki/List_of_file_signatures
|
||||||
pub fn try_infer(path: &Path) -> Option<Extension> {
|
pub fn try_infer_extension(path: &Path) -> Option<Extension> {
|
||||||
fn is_zip(buf: &[u8]) -> bool {
|
fn is_zip(buf: &[u8]) -> bool {
|
||||||
buf.len() > 3
|
buf.len() > 3
|
||||||
&& buf[0] == 0x50
|
&& buf[0] == 0x50
|
||||||
@ -155,10 +157,12 @@ pub fn try_infer(path: &Path) -> Option<Extension> {
|
|||||||
/// Module with a list of bright colors.
|
/// Module with a list of bright colors.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub mod colors {
|
pub mod colors {
|
||||||
|
use std::env;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
static DISABLE_COLORED_TEXT: Lazy<bool> = Lazy::new(|| {
|
static DISABLE_COLORED_TEXT: Lazy<bool> = Lazy::new(|| {
|
||||||
std::env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr)
|
env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr)
|
||||||
});
|
});
|
||||||
|
|
||||||
macro_rules! color {
|
macro_rules! color {
|
||||||
|
@ -5,10 +5,5 @@ mod fs;
|
|||||||
mod question_policy;
|
mod question_policy;
|
||||||
|
|
||||||
pub use bytes::Bytes;
|
pub use bytes::Bytes;
|
||||||
pub use fs::{
|
pub use fs::*;
|
||||||
cd_into_same_dir_as, colors, concatenate_list_of_os_str, create_dir_if_non_existent, dir_is_empty,
|
pub use question_policy::*;
|
||||||
nice_directory_display, strip_cur_dir, to_utf, try_infer,
|
|
||||||
};
|
|
||||||
pub use question_policy::{
|
|
||||||
create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy,
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user