mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-23 17:32:50 +03:00
refactor: destructure tuples to enhance readability (#1874)
This commit is contained in:
parent
0baccdc9aa
commit
441ebcb764
@ -12,9 +12,9 @@ impl Dimension {
|
||||
}
|
||||
|
||||
if size.rows == 0 || size.columns == 0 {
|
||||
if let Ok(s) = crossterm::terminal::size() {
|
||||
size.columns = s.0;
|
||||
size.rows = s.1;
|
||||
if let Ok((cols, rows)) = crossterm::terminal::size() {
|
||||
size.columns = cols;
|
||||
size.rows = rows;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ impl Emulator {
|
||||
("VSCODE_INJECTION", Self::VSCode),
|
||||
("TABBY_CONFIG_DIRECTORY", Self::Tabby),
|
||||
];
|
||||
match vars.into_iter().find(|v| env_exists(v.0)) {
|
||||
Some(var) => return var.1,
|
||||
match vars.into_iter().find(|(env, _)| env_exists(env)) {
|
||||
Some((_, emulator)) => return emulator,
|
||||
None => warn!("[Adapter] No special environment variables detected"),
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl Manager {
|
||||
}
|
||||
|
||||
if hovered.is_dir() {
|
||||
self.active_mut().preview.go_folder(hovered, folder.map(|f| f.1), opt.force);
|
||||
self.active_mut().preview.go_folder(hovered, folder.map(|(_, cha)| cha), opt.force);
|
||||
} else {
|
||||
self.active_mut().preview.go(hovered, mime.into(), opt.force);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl Tab {
|
||||
Box::new(self.selected.keys())
|
||||
} else {
|
||||
let mut vec: Vec<_> = self.selected.iter().collect();
|
||||
vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
|
||||
vec.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
|
||||
Box::new(vec.into_iter().map(|(k, _)| k))
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ impl Tab {
|
||||
Box::new([&h.url].into_iter().chain(self.selected.keys()))
|
||||
} else {
|
||||
let mut vec: Vec<_> = self.selected.iter().collect();
|
||||
vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
|
||||
vec.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
|
||||
Box::new([&h.url].into_iter().chain(vec.into_iter().map(|(k, _)| k)))
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ impl Signals {
|
||||
if let Some(t) = &mut term {
|
||||
select! {
|
||||
biased;
|
||||
Some(mut s) = rx.recv() => {
|
||||
term = term.filter(|_| s.0);
|
||||
s.1.take().map(|cb| cb.send(()));
|
||||
Some((state, mut callback)) = rx.recv() => {
|
||||
term = term.filter(|_| state);
|
||||
callback.take().map(|cb| cb.send(()));
|
||||
},
|
||||
Some(n) = sys.next() => if !Self::handle_sys(n) { return },
|
||||
Some(Ok(e)) = t.next() => Self::handle_term(e)
|
||||
@ -102,9 +102,9 @@ impl Signals {
|
||||
} else {
|
||||
select! {
|
||||
biased;
|
||||
Some(mut s) = rx.recv() => {
|
||||
term = s.0.then(EventStream::new);
|
||||
s.1.take().map(|cb| cb.send(()));
|
||||
Some((state, mut callback)) = rx.recv() => {
|
||||
term = state.then(EventStream::new);
|
||||
callback.take().map(|cb| cb.send(()));
|
||||
},
|
||||
Some(n) = sys.next() => if !Self::handle_sys(n) { return },
|
||||
}
|
||||
|
@ -54,11 +54,11 @@ impl TryFrom<Value<'_>> for Line {
|
||||
Value::Table(tb) => return Self::try_from(tb),
|
||||
Value::String(s) => s.to_string_lossy().into_owned().into(),
|
||||
Value::UserData(ud) => {
|
||||
if let Ok(span) = ud.take::<Span>() {
|
||||
span.0.into()
|
||||
} else if let Ok(mut line) = ud.take::<Line>() {
|
||||
line.0.spans.iter_mut().for_each(|s| s.style = line.0.style.patch(s.style));
|
||||
line.0
|
||||
if let Ok(Span(span)) = ud.take() {
|
||||
span.into()
|
||||
} else if let Ok(Line(mut line)) = ud.take() {
|
||||
line.spans.iter_mut().for_each(|s| s.style = line.style.patch(s.style));
|
||||
line
|
||||
} else {
|
||||
Err(EXPECTED.into_lua_err())?
|
||||
}
|
||||
@ -77,11 +77,11 @@ impl TryFrom<Table<'_>> for Line {
|
||||
match v? {
|
||||
Value::String(s) => spans.push(s.to_string_lossy().into_owned().into()),
|
||||
Value::UserData(ud) => {
|
||||
if let Ok(span) = ud.take::<Span>() {
|
||||
spans.push(span.0);
|
||||
} else if let Ok(mut line) = ud.take::<Line>() {
|
||||
line.0.spans.iter_mut().for_each(|s| s.style = line.0.style.patch(s.style));
|
||||
spans.extend(line.0.spans);
|
||||
if let Ok(Span(span)) = ud.take() {
|
||||
spans.push(span);
|
||||
} else if let Ok(Line(mut line)) = ud.take() {
|
||||
line.spans.iter_mut().for_each(|s| s.style = line.style.patch(s.style));
|
||||
spans.extend(line.spans);
|
||||
} else {
|
||||
return Err(EXPECTED.into_lua_err());
|
||||
}
|
||||
@ -98,7 +98,7 @@ impl UserData for Line {
|
||||
crate::impl_style_method!(methods, 0.style);
|
||||
crate::impl_style_shorthands!(methods, 0.style);
|
||||
|
||||
methods.add_method("width", |_, me, ()| Ok(me.0.width()));
|
||||
methods.add_method("width", |_, Line(me), ()| Ok(me.width()));
|
||||
methods.add_function_mut("align", |_, (ud, align): (AnyUserData, u8)| {
|
||||
ud.borrow_mut::<Self>()?.0.alignment = Some(match align {
|
||||
CENTER => ratatui::layout::Alignment::Center,
|
||||
@ -107,8 +107,8 @@ impl UserData for Line {
|
||||
});
|
||||
Ok(ud)
|
||||
});
|
||||
methods.add_method("visible", |_, me, ()| {
|
||||
Ok(me.0.iter().flat_map(|s| s.content.chars()).any(|c| c.width().unwrap_or(0) > 0))
|
||||
methods.add_method("visible", |_, Line(me), ()| {
|
||||
Ok(me.iter().flat_map(|s| s.content.chars()).any(|c| c.width().unwrap_or(0) > 0))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ impl Deref for Padding {
|
||||
|
||||
impl Padding {
|
||||
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
|
||||
let new = lua.create_function(|_, args: (Table, u16, u16, u16, u16)| {
|
||||
Ok(Self(ratatui::widgets::Padding::new(args.1, args.2, args.3, args.4)))
|
||||
let new = lua.create_function(|_, (_, left, right, top, bottom): (Table, u16, u16, u16, u16)| {
|
||||
Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom)))
|
||||
})?;
|
||||
|
||||
let padding = lua.create_table_from([
|
||||
|
@ -19,8 +19,8 @@ impl TryFrom<Value<'_>> for Span {
|
||||
Ok(Self(match value {
|
||||
Value::String(s) => s.to_string_lossy().into_owned().into(),
|
||||
Value::UserData(ud) => {
|
||||
if let Ok(span) = ud.take::<Span>() {
|
||||
span.0
|
||||
if let Ok(Span(span)) = ud.take() {
|
||||
span
|
||||
} else {
|
||||
Err(EXPECTED.into_lua_err())?
|
||||
}
|
||||
@ -35,8 +35,8 @@ impl UserData for Span {
|
||||
crate::impl_style_method!(methods, 0.style);
|
||||
crate::impl_style_shorthands!(methods, 0.style);
|
||||
|
||||
methods.add_method("visible", |_, me, ()| {
|
||||
Ok(me.0.content.chars().any(|c| c.width().unwrap_or(0) > 0))
|
||||
methods.add_method("visible", |_, Span(me), ()| {
|
||||
Ok(me.content.chars().any(|c| c.width().unwrap_or(0) > 0))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ impl TryFrom<Value<'_>> for Text {
|
||||
Value::Table(tb) => return Self::try_from(tb),
|
||||
Value::String(s) => s.to_string_lossy().into_owned().into(),
|
||||
Value::UserData(ud) => {
|
||||
if let Ok(line) = ud.take::<Line>() {
|
||||
line.0.into()
|
||||
} else if let Ok(span) = ud.take::<Span>() {
|
||||
span.0.into()
|
||||
if let Ok(Line(line)) = ud.take() {
|
||||
line.into()
|
||||
} else if let Ok(Span(span)) = ud.take() {
|
||||
span.into()
|
||||
} else {
|
||||
Err(EXPECTED.into_lua_err())?
|
||||
}
|
||||
@ -83,10 +83,10 @@ impl TryFrom<Table<'_>> for Text {
|
||||
match v? {
|
||||
Value::String(s) => lines.push(s.to_string_lossy().into_owned().into()),
|
||||
Value::UserData(ud) => {
|
||||
if let Ok(span) = ud.take::<Span>() {
|
||||
lines.push(span.0.into());
|
||||
} else if let Ok(line) = ud.take::<Line>() {
|
||||
lines.push(line.0);
|
||||
if let Ok(Span(span)) = ud.take() {
|
||||
lines.push(span.into());
|
||||
} else if let Ok(Line(line)) = ud.take() {
|
||||
lines.push(line);
|
||||
} else {
|
||||
return Err(EXPECTED.into_lua_err());
|
||||
}
|
||||
|
4
yazi-plugin/src/external/highlighter.rs
vendored
4
yazi-plugin/src/external/highlighter.rs
vendored
@ -34,8 +34,8 @@ impl Highlighter {
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let r = SYNTECT.get_or_init(|| fut).await;
|
||||
(&r.0, &r.1)
|
||||
let (theme, syntaxes) = SYNTECT.get_or_init(|| fut).await;
|
||||
(&theme, &syntaxes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user