mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
4e2a06f221
commit
e1d6530a2f
13 changed files with 56 additions and 64 deletions
|
|
@ -127,6 +127,7 @@ impl Executor {
|
|||
exec.named.contains_key("confirm"),
|
||||
),
|
||||
"hidden" => cx.manager.active_mut().hidden(exec),
|
||||
"linemode" => cx.manager.active_mut().linemode(exec),
|
||||
"search" => match exec.args.get(0).map(|s| s.as_str()).unwrap_or("") {
|
||||
"rg" => cx.manager.active_mut().search(true),
|
||||
"fd" => cx.manager.active_mut().search(false),
|
||||
|
|
|
|||
|
|
@ -67,6 +67,12 @@ keymap = [
|
|||
{ on = [ "z" ], exec = "jump zoxide", desc = "Jump to a directory using zoxide" },
|
||||
{ on = [ "Z" ], exec = "jump fzf", desc = "Jump to a directory, or reveal a file using fzf" },
|
||||
|
||||
# Linemode
|
||||
{ on = [ "m", "s" ], exec = "linemode size", desc = "Set linemode to size" },
|
||||
{ on = [ "m", "p" ], exec = "linemode permissions", desc = "Set linemode to permissions" },
|
||||
{ on = [ "m", "m" ], exec = "linemode mtime", desc = "Set linemode to mtime" },
|
||||
{ on = [ "m", "n" ], exec = "linemode none", desc = "Set linemode to none" },
|
||||
|
||||
# Copy
|
||||
{ on = [ "c", "c" ], exec = "copy path", desc = "Copy the absolute path" },
|
||||
{ on = [ "c", "d" ], exec = "copy dirname", desc = "Copy the path of the parent directory" },
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
use anyhow::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "String")]
|
||||
pub enum Linemode {
|
||||
#[default]
|
||||
None,
|
||||
Size,
|
||||
Mtime,
|
||||
Permissions,
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Linemode {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||
Ok(match s.as_str() {
|
||||
"none" => Self::None,
|
||||
"size" => Self::Size,
|
||||
"mtime" => Self::Mtime,
|
||||
"permissions" => Self::Permissions,
|
||||
_ => bail!("invalid linemode value: {s}"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for Linemode {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Self::None => "none",
|
||||
Self::Size => "size",
|
||||
Self::Mtime => "mtime",
|
||||
Self::Permissions => "permissions",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
use super::{Linemode, ManagerLayout, SortBy};
|
||||
use crate::MERGED_YAZI;
|
||||
use super::{ManagerLayout, SortBy};
|
||||
use crate::{validation::check_validation, MERGED_YAZI};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, Validate)]
|
||||
pub struct Manager {
|
||||
pub layout: ManagerLayout,
|
||||
|
||||
|
|
@ -14,7 +15,8 @@ pub struct Manager {
|
|||
pub sort_dir_first: bool,
|
||||
|
||||
// Display
|
||||
pub linemode: Linemode,
|
||||
#[validate(length(min = 1, max = 20, message = "must be between 1 and 20 characters"))]
|
||||
pub linemode: String,
|
||||
pub show_hidden: bool,
|
||||
pub show_symlink: bool,
|
||||
}
|
||||
|
|
@ -26,6 +28,9 @@ impl Default for Manager {
|
|||
manager: Manager,
|
||||
}
|
||||
|
||||
toml::from_str::<Outer>(&MERGED_YAZI).unwrap().manager
|
||||
let manager = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().manager;
|
||||
|
||||
check_validation(manager.validate());
|
||||
manager
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
mod layout;
|
||||
mod linemode;
|
||||
mod manager;
|
||||
mod sorting;
|
||||
|
||||
pub use layout::*;
|
||||
pub use linemode::*;
|
||||
pub use manager::*;
|
||||
pub use sorting::*;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl Tabs {
|
|||
}
|
||||
|
||||
let mut tab = Tab::from(url);
|
||||
tab.conf = self.active().conf;
|
||||
tab.conf = self.active().conf.clone();
|
||||
tab.apply_files_attrs(false);
|
||||
|
||||
self.items.insert(self.idx + 1, tab);
|
||||
|
|
|
|||
16
core/src/tab/commands/linemode.rs
Normal file
16
core/src/tab/commands/linemode.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use config::keymap::Exec;
|
||||
|
||||
use crate::tab::Tab;
|
||||
|
||||
impl Tab {
|
||||
pub fn linemode(&mut self, e: &Exec) -> bool {
|
||||
self.conf.patch(|c| {
|
||||
let Some(mode) = e.args.get(0) else {
|
||||
return;
|
||||
};
|
||||
if !mode.is_empty() && mode.len() <= 20 {
|
||||
c.linemode = mode.to_owned();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ mod find;
|
|||
mod hidden;
|
||||
mod jump;
|
||||
mod leave;
|
||||
mod linemode;
|
||||
mod search;
|
||||
mod select;
|
||||
mod shell;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use config::{manager::{Linemode, SortBy}, MANAGER};
|
||||
use config::{manager::SortBy, MANAGER};
|
||||
|
||||
use crate::files::FilesSorter;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct Config {
|
||||
// Sorting
|
||||
pub sort_by: SortBy,
|
||||
|
|
@ -11,7 +11,7 @@ pub struct Config {
|
|||
pub sort_dir_first: bool,
|
||||
|
||||
// Display
|
||||
pub linemode: Linemode,
|
||||
pub linemode: String,
|
||||
pub show_hidden: bool,
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ impl Default for Config {
|
|||
sort_dir_first: MANAGER.sort_dir_first,
|
||||
|
||||
// Display
|
||||
linemode: MANAGER.linemode,
|
||||
linemode: MANAGER.linemode.to_owned(),
|
||||
show_hidden: MANAGER.show_hidden,
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ impl Default for Config {
|
|||
|
||||
impl Config {
|
||||
pub(super) fn patch<F: FnOnce(&mut Self)>(&mut self, f: F) -> bool {
|
||||
let old = *self;
|
||||
let old = self.clone();
|
||||
f(self);
|
||||
*self != old
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,22 +43,25 @@ function Folder:highlighted_name(file)
|
|||
end
|
||||
|
||||
function Folder:labels(area)
|
||||
local linemode = cx.active.conf.linemode
|
||||
if linemode == "none" then
|
||||
local mode = cx.active.conf.linemode
|
||||
if mode == "none" then
|
||||
return {}
|
||||
end
|
||||
|
||||
local lines = {}
|
||||
for _, f in ipairs(self:by_kind(self.CURRENT).window) do
|
||||
if linemode == "size" then
|
||||
lines[#lines + 1] = ui.Line { ui.Span(utils.readable_size(f:size())) }
|
||||
elseif linemode == "mtime" then
|
||||
lines[#lines + 1] = ui.Line { ui.Span(os.date("%y-%m-%d %H:%M", f.modified)) }
|
||||
elseif linemode == "permissions" then
|
||||
lines[#lines + 1] = ui.Line { ui.Span(f:permissions() or "") }
|
||||
local spans = { ui.Span(" ") }
|
||||
if mode == "size" then
|
||||
local size = f:size()
|
||||
spans[#spans + 1] = ui.Span(size and utils.readable_size(size) or "")
|
||||
elseif mode == "mtime" then
|
||||
spans[#spans + 1] = ui.Span(os.date("%y-%m-%d %H:%M", f.modified))
|
||||
elseif mode == "permissions" then
|
||||
spans[#spans + 1] = ui.Span(f:permissions() or "")
|
||||
end
|
||||
lines[#lines + 1] = ui.Line(spans)
|
||||
end
|
||||
return ui.Paragraph(area, lines):align(ui.Alignment.RIGHT)
|
||||
return ui.Paragraph(area:padding(ui.Padding.right(1)), lines):align(ui.Alignment.RIGHT)
|
||||
end
|
||||
|
||||
function Folder:markers(area, markers)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function Status:size()
|
|||
|
||||
local style = self.style()
|
||||
return ui.Line {
|
||||
ui.Span(" " .. utils.readable_size(h:size()) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg),
|
||||
ui.Span(" " .. utils.readable_size(h:size() or h.length) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg),
|
||||
ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg),
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl<'a, 'b> Active<'a, 'b> {
|
|||
reg.add_field_method_get("sort_reverse", |_, me| Ok(me.sort_reverse));
|
||||
reg.add_field_method_get("sort_dir_first", |_, me| Ok(me.sort_dir_first));
|
||||
|
||||
reg.add_field_method_get("linemode", |_, me| Ok(me.linemode.to_string()));
|
||||
reg.add_field_method_get("linemode", |_, me| Ok(me.linemode.to_owned()));
|
||||
reg.add_field_method_get("show_hidden", |_, me| Ok(me.show_hidden));
|
||||
})?;
|
||||
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ impl Files {
|
|||
reg.add_function("size", |_, me: AnyUserData| {
|
||||
let file = me.borrow::<core::files::File>()?;
|
||||
if !file.is_dir() {
|
||||
return Ok(file.meta.len());
|
||||
return Ok(Some(file.meta.len()));
|
||||
}
|
||||
|
||||
let folder = me.named_user_value::<UserDataRef<core::tab::Folder>>("folder")?;
|
||||
Ok(folder.files.sizes.get(&file.url).copied().unwrap_or(file.meta.len()))
|
||||
Ok(folder.files.sizes.get(&file.url).copied())
|
||||
});
|
||||
reg.add_function("mime", |_, me: AnyUserData| {
|
||||
let manager = me.named_user_value::<UserDataRef<core::manager::Manager>>("manager")?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue