Skip to content

Commit

Permalink
Try fix find file windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
pickfire committed Jun 1, 2022
1 parent a4a8b34 commit a5cf088
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use helix_view::{

// based on exa but not sure where to put this
/// More readable aliases for the permission bits exposed by libc.
#[allow(trivial_numeric_casts)]
#[cfg(unix)]
mod modes {
// The `libc::mode_t` type’s actual type varies, but the value returned
// from `metadata.permissions().mode()` is always `u32`.
Expand All @@ -56,11 +56,15 @@ mod modes {
pub const SETUID: Mode = libc::S_ISUID as Mode;
}

#[cfg(not(unix))]
mod modes {}

// based on exa but not sure where to put this
mod fields {
use super::modes;
use std::fmt;
use std::fs::Metadata;
#[cfg(unix)]
use std::os::unix::fs::{FileTypeExt, MetadataExt};

/// The file’s base type, which gets displayed in the very first column of the
Expand All @@ -83,6 +87,7 @@ mod fields {
Special,
}

#[cfg(unix)]
pub fn filetype(metadata: &Metadata) -> Type {
let filetype = metadata.file_type();
if metadata.is_file() {
Expand All @@ -104,6 +109,11 @@ mod fields {
}
}

#[cfg(not(unix))]
pub fn filetype(metadata: &Metadata) -> Type {
unreachable!()
}

impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand Down Expand Up @@ -143,6 +153,7 @@ mod fields {
pub setuid: bool,
}

#[cfg(unix)]
pub fn permissions(metadata: &Metadata) -> Permissions {
let bits = metadata.mode();
let has_bit = |bit| bits & bit == bit;
Expand All @@ -165,6 +176,11 @@ mod fields {
}
}

#[cfg(not(unix))]
pub fn permissions(metadata: &Metadata) -> Permissions {
unreachable!()
}

impl fmt::Display for Permissions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let bit = |bit, char| if bit { char } else { "-" };
Expand Down Expand Up @@ -230,6 +246,7 @@ mod fields {
///
/// Block and character devices return their device IDs, because they
/// usually just have a file size of zero.
#[cfg(unix)]
pub fn size(metadata: &Metadata) -> Size {
let filetype = metadata.file_type();
if metadata.is_dir() {
Expand All @@ -250,6 +267,11 @@ mod fields {
}
}

#[cfg(not(unix))]
pub fn size(metadata: &Metadata) -> Size {
unreachable!()
}

impl fmt::Display for Size {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use number_prefix::NumberPrefix;
Expand Down Expand Up @@ -335,17 +357,21 @@ impl FindFilePicker {
let suffix = if path.is_dir() { "/" } else { "" };
let metadata = fs::metadata(&*path).unwrap();
let path = path.strip_prefix(&dir1).unwrap_or(path).to_string_lossy();
let filetype = fields::filetype(&metadata);
let permissions = fields::permissions(&metadata);
let size = format!("{}", fields::size(&metadata));
Cow::Owned(format!(
"{:<22} {}{} {:>6}",
path + suffix, // TODO this should check for size and handle truncation
filetype,
permissions,
size,
// TODO add absolute/relative time? may need to handle truncation
))
if cfg!(unix) {
let filetype = fields::filetype(&metadata);
let permissions = fields::permissions(&metadata);
let size = format!("{}", fields::size(&metadata));
Cow::Owned(format!(
"{:<22} {}{} {:>6}",
path + suffix, // TODO this should check for size and handle truncation
filetype,
permissions,
size,
// TODO add absolute/relative time? may need to handle truncation
))
} else {
path + suffix
}
},
|_cx, _path, _action| {}, // we use custom callback_fn
|_editor, path| Some((path.clone(), None)),
Expand Down

0 comments on commit a5cf088

Please sign in to comment.