mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 00:31:04 +00:00
55 lines
1.1 KiB
Rust
55 lines
1.1 KiB
Rust
use std::{fmt::Display, str::FromStr};
|
|
|
|
use anyhow::bail;
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
|
|
pub enum Layer {
|
|
#[default]
|
|
App,
|
|
Manager,
|
|
Tasks,
|
|
Spot,
|
|
Pick,
|
|
Input,
|
|
Confirm,
|
|
Help,
|
|
Completion,
|
|
Which,
|
|
}
|
|
|
|
impl Display for Layer {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(match self {
|
|
Self::App => "app",
|
|
Self::Manager => "manager",
|
|
Self::Tasks => "tasks",
|
|
Self::Spot => "spot",
|
|
Self::Pick => "pick",
|
|
Self::Input => "input",
|
|
Self::Confirm => "confirm",
|
|
Self::Help => "help",
|
|
Self::Completion => "completion",
|
|
Self::Which => "which",
|
|
})
|
|
}
|
|
}
|
|
|
|
impl FromStr for Layer {
|
|
type Err = anyhow::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}"),
|
|
})
|
|
}
|
|
}
|