mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: add a warning about <Backspace> key
This commit is contained in:
parent
f7f1e34649
commit
4d7d2ef082
4 changed files with 39 additions and 28 deletions
|
|
@ -35,6 +35,17 @@ impl<'de> Deserialize<'de> for Keymap {
|
|||
}
|
||||
|
||||
let shadow = Shadow::deserialize(deserializer)?;
|
||||
|
||||
// TODO: remove this when v0.1.6 is released --
|
||||
if !shadow.input.keymap.iter().any(|c| c.on() == "<Backspace>") {
|
||||
println!(
|
||||
"WARNING: Default keybinding for `<Backspace>` is missing, please add a `{}` to the `[input]` section of `keymap.toml`.
|
||||
In Yazi v0.1.6, `<Backspace>` previously hardcoded within the Input component has been moved to `keymap.toml` to allow users to customize it.",
|
||||
r#"{ on = [ "<Backspace>" ], exec = "backspace" }"#
|
||||
);
|
||||
}
|
||||
// TODO: -- remove this when v0.1.6 is released
|
||||
|
||||
Ok(Self {
|
||||
manager: shadow.manager.keymap,
|
||||
tasks: shadow.tasks.keymap,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::BTreeMap, ffi::OsStr, fs::Metadata, ops::Der
|
|||
|
||||
use anyhow::Result;
|
||||
use tokio::fs;
|
||||
use yazi_shared::{Cha, ChaMeta, Url};
|
||||
use yazi_shared::{Cha, ChaKind, Url};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct File {
|
||||
|
|
@ -26,30 +26,30 @@ impl File {
|
|||
}
|
||||
|
||||
pub async fn from_meta(url: Url, mut meta: Metadata) -> Self {
|
||||
let mut cm = ChaMeta::empty();
|
||||
let mut cm = ChaKind::empty();
|
||||
|
||||
let (is_link, mut link_to) = (meta.is_symlink(), None);
|
||||
if is_link {
|
||||
cm |= ChaMeta::LINK;
|
||||
cm |= ChaKind::LINK;
|
||||
meta = fs::metadata(&url).await.unwrap_or(meta);
|
||||
link_to = fs::read_link(&url).await.map(Url::from).ok();
|
||||
}
|
||||
|
||||
if is_link && meta.is_symlink() {
|
||||
cm |= ChaMeta::BAD_LINK;
|
||||
cm |= ChaKind::BAD_LINK;
|
||||
}
|
||||
|
||||
if url.is_hidden() {
|
||||
cm |= ChaMeta::HIDDEN;
|
||||
cm |= ChaKind::HIDDEN;
|
||||
}
|
||||
|
||||
Self { url, cha: Cha::from(meta).with_meta(cm), link_to }
|
||||
Self { url, cha: Cha::from(meta).with_kind(cm), link_to }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_dummy(url: Url) -> Self {
|
||||
let cm = if url.is_hidden() { ChaMeta::HIDDEN } else { ChaMeta::empty() };
|
||||
Self { url, cha: Cha::default().with_meta(cm), link_to: None }
|
||||
let cm = if url.is_hidden() { ChaKind::HIDDEN } else { ChaKind::empty() };
|
||||
Self { url, cha: Cha::default().with_kind(cm), link_to: None }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ impl Preview {
|
|||
&& self.skip == lock.skip
|
||||
&& cha.len == cha_.len
|
||||
&& cha.modified == cha_.modified
|
||||
&& cha.meta == cha_.meta
|
||||
&& cha.kind == cha_.kind
|
||||
&& {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use bitflags::bitflags;
|
|||
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct ChaMeta: u8 {
|
||||
pub struct ChaKind: u8 {
|
||||
const DIR = 0b00000001;
|
||||
|
||||
const HIDDEN = 0b00000010;
|
||||
|
|
@ -20,7 +20,7 @@ bitflags! {
|
|||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Cha {
|
||||
pub meta: ChaMeta,
|
||||
pub kind: ChaKind,
|
||||
pub len: u64,
|
||||
pub accessed: Option<SystemTime>,
|
||||
pub created: Option<SystemTime>,
|
||||
|
|
@ -31,30 +31,30 @@ pub struct Cha {
|
|||
|
||||
impl From<Metadata> for Cha {
|
||||
fn from(m: Metadata) -> Self {
|
||||
let mut cm = ChaMeta::empty();
|
||||
let mut ck = ChaKind::empty();
|
||||
if m.is_dir() {
|
||||
cm |= ChaMeta::DIR;
|
||||
ck |= ChaKind::DIR;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::prelude::FileTypeExt;
|
||||
if m.file_type().is_block_device() {
|
||||
cm |= ChaMeta::BLOCK_DEVICE;
|
||||
ck |= ChaKind::BLOCK_DEVICE;
|
||||
}
|
||||
if m.file_type().is_char_device() {
|
||||
cm |= ChaMeta::CHAR_DEVICE;
|
||||
ck |= ChaKind::CHAR_DEVICE;
|
||||
}
|
||||
if m.file_type().is_fifo() {
|
||||
cm |= ChaMeta::FIFO;
|
||||
ck |= ChaKind::FIFO;
|
||||
}
|
||||
if m.file_type().is_socket() {
|
||||
cm |= ChaMeta::SOCKET;
|
||||
ck |= ChaKind::SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
meta: cm,
|
||||
kind: ck,
|
||||
len: m.len(),
|
||||
accessed: m.accessed().ok(),
|
||||
// TODO: remove this once https://github.com/rust-lang/rust/issues/108277 is fixed.
|
||||
|
|
@ -72,38 +72,38 @@ impl From<Metadata> for Cha {
|
|||
|
||||
impl Cha {
|
||||
#[inline]
|
||||
pub fn with_meta(mut self, meta: ChaMeta) -> Self {
|
||||
self.meta |= meta;
|
||||
pub fn with_kind(mut self, kind: ChaKind) -> Self {
|
||||
self.kind |= kind;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Cha {
|
||||
#[inline]
|
||||
pub fn is_dir(self) -> bool { self.meta.contains(ChaMeta::DIR) }
|
||||
pub fn is_dir(self) -> bool { self.kind.contains(ChaKind::DIR) }
|
||||
|
||||
#[inline]
|
||||
pub fn is_hidden(self) -> bool { self.meta.contains(ChaMeta::HIDDEN) }
|
||||
pub fn is_hidden(self) -> bool { self.kind.contains(ChaKind::HIDDEN) }
|
||||
|
||||
#[inline]
|
||||
pub fn is_link(self) -> bool { self.meta.contains(ChaMeta::LINK) }
|
||||
pub fn is_link(self) -> bool { self.kind.contains(ChaKind::LINK) }
|
||||
|
||||
#[inline]
|
||||
pub fn is_bad_link(self) -> bool { self.meta.contains(ChaMeta::BAD_LINK) }
|
||||
pub fn is_bad_link(self) -> bool { self.kind.contains(ChaKind::BAD_LINK) }
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
pub fn is_block_device(self) -> bool { self.meta.contains(ChaMeta::BLOCK_DEVICE) }
|
||||
pub fn is_block_device(self) -> bool { self.kind.contains(ChaKind::BLOCK_DEVICE) }
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
pub fn is_char_device(self) -> bool { self.meta.contains(ChaMeta::CHAR_DEVICE) }
|
||||
pub fn is_char_device(self) -> bool { self.kind.contains(ChaKind::CHAR_DEVICE) }
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
pub fn is_fifo(self) -> bool { self.meta.contains(ChaMeta::FIFO) }
|
||||
pub fn is_fifo(self) -> bool { self.kind.contains(ChaKind::FIFO) }
|
||||
|
||||
#[cfg(unix)]
|
||||
#[inline]
|
||||
pub fn is_socket(self) -> bool { self.meta.contains(ChaMeta::SOCKET) }
|
||||
pub fn is_socket(self) -> bool { self.kind.contains(ChaKind::SOCKET) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue