Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: destructure tuples to enhance readability #1874

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions yazi-adapter/src/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions yazi-adapter/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}

Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/manager/commands/peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/src/tab/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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)))
}
}
Expand Down
12 changes: 6 additions & 6 deletions yazi-fm/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ 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)
}
} 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 },
}
Expand Down
26 changes: 13 additions & 13 deletions yazi-plugin/src/elements/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?
}
Expand All @@ -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());
}
Expand All @@ -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,
Expand All @@ -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))
});
}
}
4 changes: 2 additions & 2 deletions yazi-plugin/src/elements/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
8 changes: 4 additions & 4 deletions yazi-plugin/src/elements/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?
}
Expand All @@ -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))
});
}
}
16 changes: 8 additions & 8 deletions yazi-plugin/src/elements/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?
}
Expand All @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/src/external/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down