feat: add a warning about <Backspace> key

This commit is contained in:
sxyazi 2023-11-25 17:08:17 +08:00
parent f7f1e34649
commit 4d7d2ef082
No known key found for this signature in database
4 changed files with 39 additions and 28 deletions

View file

@ -35,6 +35,17 @@ impl<'de> Deserialize<'de> for Keymap {
} }
let shadow = Shadow::deserialize(deserializer)?; 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 { Ok(Self {
manager: shadow.manager.keymap, manager: shadow.manager.keymap,
tasks: shadow.tasks.keymap, tasks: shadow.tasks.keymap,

View file

@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::BTreeMap, ffi::OsStr, fs::Metadata, ops::Der
use anyhow::Result; use anyhow::Result;
use tokio::fs; use tokio::fs;
use yazi_shared::{Cha, ChaMeta, Url}; use yazi_shared::{Cha, ChaKind, Url};
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct File { pub struct File {
@ -26,30 +26,30 @@ impl File {
} }
pub async fn from_meta(url: Url, mut meta: Metadata) -> Self { 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); let (is_link, mut link_to) = (meta.is_symlink(), None);
if is_link { if is_link {
cm |= ChaMeta::LINK; cm |= ChaKind::LINK;
meta = fs::metadata(&url).await.unwrap_or(meta); meta = fs::metadata(&url).await.unwrap_or(meta);
link_to = fs::read_link(&url).await.map(Url::from).ok(); link_to = fs::read_link(&url).await.map(Url::from).ok();
} }
if is_link && meta.is_symlink() { if is_link && meta.is_symlink() {
cm |= ChaMeta::BAD_LINK; cm |= ChaKind::BAD_LINK;
} }
if url.is_hidden() { 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] #[inline]
pub fn from_dummy(url: Url) -> Self { pub fn from_dummy(url: Url) -> Self {
let cm = if url.is_hidden() { ChaMeta::HIDDEN } else { ChaMeta::empty() }; let cm = if url.is_hidden() { ChaKind::HIDDEN } else { ChaKind::empty() };
Self { url, cha: Cha::default().with_meta(cm), link_to: None } Self { url, cha: Cha::default().with_kind(cm), link_to: None }
} }
#[inline] #[inline]

View file

@ -139,7 +139,7 @@ impl Preview {
&& self.skip == lock.skip && self.skip == lock.skip
&& cha.len == cha_.len && cha.len == cha_.len
&& cha.modified == cha_.modified && cha.modified == cha_.modified
&& cha.meta == cha_.meta && cha.kind == cha_.kind
&& { && {
#[cfg(unix)] #[cfg(unix)]
{ {

View file

@ -4,7 +4,7 @@ use bitflags::bitflags;
bitflags! { bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ChaMeta: u8 { pub struct ChaKind: u8 {
const DIR = 0b00000001; const DIR = 0b00000001;
const HIDDEN = 0b00000010; const HIDDEN = 0b00000010;
@ -20,7 +20,7 @@ bitflags! {
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
pub struct Cha { pub struct Cha {
pub meta: ChaMeta, pub kind: ChaKind,
pub len: u64, pub len: u64,
pub accessed: Option<SystemTime>, pub accessed: Option<SystemTime>,
pub created: Option<SystemTime>, pub created: Option<SystemTime>,
@ -31,30 +31,30 @@ pub struct Cha {
impl From<Metadata> for Cha { impl From<Metadata> for Cha {
fn from(m: Metadata) -> Self { fn from(m: Metadata) -> Self {
let mut cm = ChaMeta::empty(); let mut ck = ChaKind::empty();
if m.is_dir() { if m.is_dir() {
cm |= ChaMeta::DIR; ck |= ChaKind::DIR;
} }
#[cfg(unix)] #[cfg(unix)]
{ {
use std::os::unix::prelude::FileTypeExt; use std::os::unix::prelude::FileTypeExt;
if m.file_type().is_block_device() { if m.file_type().is_block_device() {
cm |= ChaMeta::BLOCK_DEVICE; ck |= ChaKind::BLOCK_DEVICE;
} }
if m.file_type().is_char_device() { if m.file_type().is_char_device() {
cm |= ChaMeta::CHAR_DEVICE; ck |= ChaKind::CHAR_DEVICE;
} }
if m.file_type().is_fifo() { if m.file_type().is_fifo() {
cm |= ChaMeta::FIFO; ck |= ChaKind::FIFO;
} }
if m.file_type().is_socket() { if m.file_type().is_socket() {
cm |= ChaMeta::SOCKET; ck |= ChaKind::SOCKET;
} }
} }
Self { Self {
meta: cm, kind: ck,
len: m.len(), len: m.len(),
accessed: m.accessed().ok(), accessed: m.accessed().ok(),
// TODO: remove this once https://github.com/rust-lang/rust/issues/108277 is fixed. // 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 { impl Cha {
#[inline] #[inline]
pub fn with_meta(mut self, meta: ChaMeta) -> Self { pub fn with_kind(mut self, kind: ChaKind) -> Self {
self.meta |= meta; self.kind |= kind;
self self
} }
} }
impl Cha { impl Cha {
#[inline] #[inline]
pub fn is_dir(self) -> bool { self.meta.contains(ChaMeta::DIR) } pub fn is_dir(self) -> bool { self.kind.contains(ChaKind::DIR) }
#[inline] #[inline]
pub fn is_hidden(self) -> bool { self.meta.contains(ChaMeta::HIDDEN) } pub fn is_hidden(self) -> bool { self.kind.contains(ChaKind::HIDDEN) }
#[inline] #[inline]
pub fn is_link(self) -> bool { self.meta.contains(ChaMeta::LINK) } pub fn is_link(self) -> bool { self.kind.contains(ChaKind::LINK) }
#[inline] #[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)] #[cfg(unix)]
#[inline] #[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)] #[cfg(unix)]
#[inline] #[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)] #[cfg(unix)]
#[inline] #[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)] #[cfg(unix)]
#[inline] #[inline]
pub fn is_socket(self) -> bool { self.meta.contains(ChaMeta::SOCKET) } pub fn is_socket(self) -> bool { self.kind.contains(ChaKind::SOCKET) }
} }