mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: consistent naming for enum variants (#2339)
This commit is contained in:
parent
b9416d8a04
commit
38e45c647b
13 changed files with 41 additions and 184 deletions
2
.github/DISCUSSION_TEMPLATE/1-q-a.yml
vendored
2
.github/DISCUSSION_TEMPLATE/1-q-a.yml
vendored
|
|
@ -50,5 +50,7 @@ body:
|
|||
label: Checklist
|
||||
description: Before submitting the post, please make sure you have completed the following
|
||||
options:
|
||||
- label: I have read all the documentation
|
||||
required: true
|
||||
- label: I have searched the existing discussions/issues
|
||||
required: true
|
||||
|
|
|
|||
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -334,9 +334,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.13"
|
||||
version = "1.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7777341816418c02e033934a09f20dc0ccaf65a5201ef8a450ae0105a573fda"
|
||||
checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
|
|
@ -373,9 +373,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.28"
|
||||
version = "4.5.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e77c3243bd94243c03672cb5154667347c457ca271254724f9f393aee1c05ff"
|
||||
checksum = "8acebd8ad879283633b343856142139f2da2317c96b05b4dd6181c61e2480184"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
|
|
@ -383,9 +383,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.27"
|
||||
version = "4.5.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7"
|
||||
checksum = "f6ba32cbda51c7e1dfd49acc1457ba1a7dec5b64fe360e828acb13ca8dc9c2f9"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
|
@ -1529,9 +1529,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.3"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924"
|
||||
checksum = "b3b1c9bd4fe1f0f8b387f6eb9eb3b4a1aa26185e5750efb9140301703f62cd1b"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
|
|
@ -3581,6 +3581,7 @@ version = "25.2.11"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"mlua",
|
||||
"serde",
|
||||
"tokio",
|
||||
"yazi-config",
|
||||
"yazi-macro",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ ansi-to-tui = "7.0.0"
|
|||
anyhow = "1.0.95"
|
||||
base64 = "0.22.1"
|
||||
bitflags = "2.8.0"
|
||||
clap = { version = "4.5.28", features = [ "derive" ] }
|
||||
clap = { version = "4.5.29", features = [ "derive" ] }
|
||||
core-foundation-sys = "0.8.7"
|
||||
crossterm = { version = "0.28.1", features = [ "event-stream" ] }
|
||||
dirs = "6.0.0"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Origin {
|
||||
#[default]
|
||||
TopLeft,
|
||||
|
|
@ -19,32 +18,6 @@ pub enum Origin {
|
|||
Hovered,
|
||||
}
|
||||
|
||||
impl FromStr for Origin {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"top-left" => Self::TopLeft,
|
||||
"top-center" => Self::TopCenter,
|
||||
"top-right" => Self::TopRight,
|
||||
|
||||
"bottom-left" => Self::BottomLeft,
|
||||
"bottom-center" => Self::BottomCenter,
|
||||
"bottom-right" => Self::BottomRight,
|
||||
|
||||
"center" => Self::Center,
|
||||
"hovered" => Self::Hovered,
|
||||
_ => bail!("Invalid `origin` value: {s}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Origin {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value) }
|
||||
}
|
||||
|
||||
impl Display for Origin {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(match self {
|
||||
|
|
@ -61,3 +34,11 @@ impl Display for Origin {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Origin {
|
||||
type Err = serde::de::value::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Self::deserialize(serde::de::value::StrDeserializer::new(s))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,8 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PreviewWrap {
|
||||
No,
|
||||
Yes,
|
||||
}
|
||||
|
||||
impl FromStr for PreviewWrap {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"no" => Self::No,
|
||||
"yes" => Self::Yes,
|
||||
_ => bail!("Invalid `wrap` value: {s}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for PreviewWrap {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,10 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug, Deserialize)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Priority {
|
||||
Low = 0,
|
||||
#[default]
|
||||
Normal = 1,
|
||||
High = 2,
|
||||
}
|
||||
|
||||
impl FromStr for Priority {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"low" => Ok(Self::Low),
|
||||
"normal" => Ok(Self::Normal),
|
||||
"high" => Ok(Self::High),
|
||||
_ => Err(anyhow!("Invalid priority: {s}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Priority {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::Deserialize;
|
||||
use yazi_fs::Cha;
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Is {
|
||||
#[default]
|
||||
None,
|
||||
|
|
@ -21,32 +18,6 @@ pub enum Is {
|
|||
Sticky,
|
||||
}
|
||||
|
||||
impl FromStr for Is {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"hidden" => Self::Hidden,
|
||||
"link" => Self::Link,
|
||||
"orphan" => Self::Orphan,
|
||||
"dummy" => Self::Dummy,
|
||||
"block" => Self::Block,
|
||||
"char" => Self::Char,
|
||||
"fifo" => Self::Fifo,
|
||||
"sock" => Self::Sock,
|
||||
"exec" => Self::Exec,
|
||||
"sticky" => Self::Sticky,
|
||||
_ => bail!("invalid filetype: {s}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Is {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
|
||||
}
|
||||
|
||||
impl Is {
|
||||
#[inline]
|
||||
pub fn check(&self, cha: &Cha) -> bool {
|
||||
|
|
|
|||
|
|
@ -1,32 +1,10 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum SortBy {
|
||||
#[default]
|
||||
None,
|
||||
Key,
|
||||
Desc,
|
||||
}
|
||||
|
||||
impl FromStr for SortBy {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"none" => Self::None,
|
||||
"key" => Self::Key,
|
||||
"desc" => Self::Desc,
|
||||
_ => bail!("Invalid `sort_by` value: {s}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for SortBy {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "String")]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum SortBy {
|
||||
#[default]
|
||||
None,
|
||||
|
|
@ -18,29 +17,13 @@ pub enum SortBy {
|
|||
}
|
||||
|
||||
impl FromStr for SortBy {
|
||||
type Err = anyhow::Error;
|
||||
type Err = serde::de::value::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"none" => Self::None,
|
||||
"mtime" => Self::Mtime,
|
||||
"btime" => Self::Btime,
|
||||
"extension" => Self::Extension,
|
||||
"alphabetical" => Self::Alphabetical,
|
||||
"natural" => Self::Natural,
|
||||
"size" => Self::Size,
|
||||
"random" => Self::Random,
|
||||
_ => bail!("invalid sort_by value: {s}"),
|
||||
})
|
||||
Self::deserialize(serde::de::value::StrDeserializer::new(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for SortBy {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
|
||||
}
|
||||
|
||||
impl Display for SortBy {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(match self {
|
||||
|
|
|
|||
|
|
@ -32,10 +32,9 @@ function M:peek(job)
|
|||
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
||||
else
|
||||
lines = lines:gsub("\t", string.rep(" ", PREVIEW.tab_size))
|
||||
ya.preview_widgets(
|
||||
job,
|
||||
{ ui.Text.parse(lines):area(job.area):wrap(PREVIEW.wrap == "Yes" and ui.Text.WRAP or ui.Text.WRAP_NO) }
|
||||
)
|
||||
ya.preview_widgets(job, {
|
||||
ui.Text.parse(lines):area(job.area):wrap(PREVIEW.wrap == "yes" and ui.Text.WRAP or ui.Text.WRAP_NO),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ yazi-shared = { path = "../yazi-shared", version = "25.2.11" }
|
|||
# External dependencies
|
||||
anyhow = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use anyhow::bail;
|
||||
use mlua::{ExternalError, ExternalResult};
|
||||
use serde::Deserialize;
|
||||
use yazi_config::THEME;
|
||||
use yazi_shared::{event::CmdCow, theme::Style};
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ impl TryFrom<mlua::Table> for NotifyOpt {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Default, Deserialize, Eq, PartialEq)]
|
||||
pub enum NotifyLevel {
|
||||
#[default]
|
||||
Info,
|
||||
|
|
@ -71,14 +71,9 @@ impl NotifyLevel {
|
|||
}
|
||||
|
||||
impl FromStr for NotifyLevel {
|
||||
type Err = anyhow::Error;
|
||||
type Err = serde::de::value::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"info" => Self::Info,
|
||||
"warn" => Self::Warn,
|
||||
"error" => Self::Error,
|
||||
_ => bail!("Invalid notify level: {s}"),
|
||||
})
|
||||
Self::deserialize(serde::de::value::StrDeserializer::new(s))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use anyhow::bail;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Layer {
|
||||
#[default]
|
||||
App,
|
||||
|
|
@ -35,21 +36,9 @@ impl Display for Layer {
|
|||
}
|
||||
|
||||
impl FromStr for Layer {
|
||||
type Err = anyhow::Error;
|
||||
type Err = serde::de::value::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"app" => Self::App,
|
||||
"manager" => Self::Manager,
|
||||
"tasks" => Self::Tasks,
|
||||
"spot" => Self::Spot,
|
||||
"pick" => Self::Pick,
|
||||
"input" => Self::Input,
|
||||
"confirm" => Self::Confirm,
|
||||
"help" => Self::Help,
|
||||
"completion" => Self::Completion,
|
||||
"which" => Self::Which,
|
||||
_ => bail!("invalid layer: {s}"),
|
||||
})
|
||||
Self::deserialize(serde::de::value::StrDeserializer::new(s))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue