Skip to content

Commit

Permalink
Fix Clippy 1.80 warnings (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa authored Aug 12, 2024
1 parent 51de3d1 commit ccb799e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 62 deletions.
6 changes: 2 additions & 4 deletions crates/modalkit-ratatui/src/windows/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ where
let mut carea = rect_zero_height(area);

let mut f = |value: &mut Value<W, X, Y>| {
let (_, h) = value.dimensions();
let height = slopped_length(height, h as u16, &mut slop);
let height = slopped_length(height, value.height() as u16, &mut slop);

carea = rect_down(carea, height);

Expand All @@ -155,8 +154,7 @@ where
let mut carea = rect_zero_width(area);

let mut f = |value: &mut Value<W, X, Y>| {
let (w, _) = value.dimensions();
let width = slopped_length(width, w as u16, &mut slop);
let width = slopped_length(width, value.width() as u16, &mut slop);

carea = rect_right(carea, width);

Expand Down
1 change: 1 addition & 0 deletions crates/modalkit-ratatui/src/windows/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ where
fn weight(&self) -> usize;

/// Fetch a mutable reference to the n<sup>th</sup> `Value` in the tree.
#[allow(unused)]
fn val_mut(&mut self, at: usize) -> Option<&mut Value<W, X, Y>>;

/// Iterate over immutable references to each [Value] in this tree.
Expand Down
2 changes: 1 addition & 1 deletion crates/modalkit/src/editing/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! movements. For example:
//!
//! - Performing edit operations like text deletion or case changes using content-aware movements
//! (e.g., by word, up to a specific character or to the start of the line, etc.)
//! (e.g., by word, up to a specific character or to the start of the line, etc.)
//! - Copying and pasting text between registers and the buffer
//! - Visual selections
//! - Cursor groups
Expand Down
9 changes: 4 additions & 5 deletions crates/modalkit/src/editing/rope/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub enum DeltaElement<'a> {
#[derive(Clone, Debug)]
pub struct Delta<'a> {
pub els: Vec<DeltaElement<'a>>,
pub base_len: usize,
}

fn find_ne_char_back(
Expand Down Expand Up @@ -130,7 +129,7 @@ pub fn compute_delta<'a>(base: &Rope, target: &'a Rope) -> Delta<'a> {

// if our preliminary scan finds no differences we're done
if start_offset == base.len_chars() && target.len_chars() == base.len_chars() {
return builder.into_delta(base, target);
return builder.into_delta(target);
}

let line_hashes = make_line_hashes(base, MIN_SIZE);
Expand Down Expand Up @@ -198,7 +197,7 @@ pub fn compute_delta<'a>(base: &Rope, target: &'a Rope) -> Delta<'a> {
builder.copy(base.len_chars() - diff_end, target.len_chars() - diff_end, diff_end);
}

builder.into_delta(base, target)
builder.into_delta(target)
}

/// Given two ropes and the offsets of two equal bytes, finds the largest
Expand Down Expand Up @@ -295,7 +294,7 @@ impl DiffBuilder {
self.ops.push(DiffOp { target_idx: target, base_idx: base, len })
}

fn into_delta<'a>(self, base: &Rope, target: &'a Rope) -> Delta<'a> {
fn into_delta(self, target: &Rope) -> Delta<'_> {
let mut els = Vec::with_capacity(self.ops.len() * 2);
let mut targ_pos = 0;
for DiffOp { base_idx, target_idx, len } in self.ops {
Expand All @@ -312,7 +311,7 @@ impl DiffBuilder {
els.push(DeltaElement::Insert(slice));
}

Delta { els, base_len: base.len_chars() }
Delta { els }
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/modalkit/src/editing/rope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! [prelude]: crate::prelude
use std::borrow::Cow;
use std::cmp::{Ord, Ordering, PartialOrd};
use std::fmt::Debug;
use std::fmt::{self, Debug, Display};
use std::io::Write;
use std::ops::{Add, AddAssign, Bound, Range, RangeBounds};

Expand Down Expand Up @@ -2313,9 +2313,9 @@ impl PartialEq<EditRope> for EditRope {

impl Eq for EditRope {}

impl ToString for EditRope {
fn to_string(&self) -> String {
self.rope.to_string()
impl Display for EditRope {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", &self.rope)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/modalkit/src/editing/store/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ where
Err(EditError::WrongBuffer(owner))
}
} else if let Some(bstore) = self.buffer.get(&id) {
bstore.get(mark).map(Cursor::clone).ok_or(unset)
bstore.get(mark).cloned().ok_or(unset)
} else {
Err(unset)
}
Expand Down
92 changes: 45 additions & 47 deletions crates/modalkit/src/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//!
//! This module contains code for representing and processing keys.
//!
use std::fmt::{self, Display};
use std::hash::Hash;
use std::str::FromStr;

Expand Down Expand Up @@ -152,74 +153,72 @@ impl FromStr for TerminalKey {
}
}

impl ToString for TerminalKey {
fn to_string(&self) -> String {
let mut res = String::new();

let push_mods = |res: &mut String, mods: KeyModifiers| {
impl Display for TerminalKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let push_mods = |f: &mut fmt::Formatter, mods: KeyModifiers| -> fmt::Result {
if mods.contains(KeyModifiers::CONTROL) {
res.push_str("C-");
write!(f, "C-")?;
}

if mods.contains(KeyModifiers::ALT) {
res.push_str("A-");
write!(f, "A-")?;
}

if mods.contains(KeyModifiers::SHIFT) {
res.push_str("S-");
write!(f, "S-")?;
}

Ok(())
};

let push_named_mods = |res: &mut String, name: &str, mods| {
res.push('<');
push_mods(res, mods);
res.push_str(name);
res.push('>');
let push_named_mods = |f: &mut fmt::Formatter, name: &str, mods| -> fmt::Result {
write!(f, "<")
.and_then(|()| push_mods(f, mods))
.and_then(|()| write!(f, "{}>", name))
};

let push_named = |res: &mut String, name: &str| push_named_mods(res, name, self.modifiers);
let push_named =
|f: &mut fmt::Formatter, name: &str| push_named_mods(f, name, self.modifiers);

match self.code {
KeyCode::Left => push_named(&mut res, "Left"),
KeyCode::Right => push_named(&mut res, "Right"),
KeyCode::Up => push_named(&mut res, "Up"),
KeyCode::Down => push_named(&mut res, "Down"),
KeyCode::Backspace => push_named(&mut res, "BS"),
KeyCode::Enter => push_named(&mut res, "Enter"),
KeyCode::Home => push_named(&mut res, "Home"),
KeyCode::End => push_named(&mut res, "End"),
KeyCode::PageUp => push_named(&mut res, "PageUp"),
KeyCode::PageDown => push_named(&mut res, "PageDown"),
KeyCode::Null => push_named(&mut res, "Nul"),
KeyCode::Esc => push_named(&mut res, "Esc"),
KeyCode::Delete => push_named(&mut res, "Del"),
KeyCode::Insert => push_named(&mut res, "Insert"),
KeyCode::CapsLock => push_named(&mut res, "CapsLock"),
KeyCode::ScrollLock => push_named(&mut res, "ScrollLock"),
KeyCode::NumLock => push_named(&mut res, "NumLock"),
KeyCode::PrintScreen => push_named(&mut res, "PrintScreen"),
KeyCode::Pause => push_named(&mut res, "Pause"),
KeyCode::Menu => push_named(&mut res, "Menu"),
KeyCode::Tab => push_named(&mut res, "Tab"),
KeyCode::BackTab => {
push_named_mods(&mut res, "Tab", self.modifiers | KeyModifiers::SHIFT)
},
KeyCode::Left => push_named(f, "Left"),
KeyCode::Right => push_named(f, "Right"),
KeyCode::Up => push_named(f, "Up"),
KeyCode::Down => push_named(f, "Down"),
KeyCode::Backspace => push_named(f, "BS"),
KeyCode::Enter => push_named(f, "Enter"),
KeyCode::Home => push_named(f, "Home"),
KeyCode::End => push_named(f, "End"),
KeyCode::PageUp => push_named(f, "PageUp"),
KeyCode::PageDown => push_named(f, "PageDown"),
KeyCode::Null => push_named(f, "Nul"),
KeyCode::Esc => push_named(f, "Esc"),
KeyCode::Delete => push_named(f, "Del"),
KeyCode::Insert => push_named(f, "Insert"),
KeyCode::CapsLock => push_named(f, "CapsLock"),
KeyCode::ScrollLock => push_named(f, "ScrollLock"),
KeyCode::NumLock => push_named(f, "NumLock"),
KeyCode::PrintScreen => push_named(f, "PrintScreen"),
KeyCode::Pause => push_named(f, "Pause"),
KeyCode::Menu => push_named(f, "Menu"),
KeyCode::Tab => push_named(f, "Tab"),
KeyCode::BackTab => push_named_mods(f, "Tab", self.modifiers | KeyModifiers::SHIFT),
KeyCode::F(n) => {
let n = n.to_string();

push_named(&mut res, n.as_str());
push_named(f, n.as_str())
},
KeyCode::Char(c) => {
if c == ' ' {
if self.modifiers.is_empty() {
res.push(c);
write!(f, "{c}")
} else {
push_named(&mut res, "Space");
push_named(f, "Space")
}
} else if c == '<' {
push_named(&mut res, "lt");
push_named(f, "lt")
} else if (self.modifiers - KeyModifiers::SHIFT).is_empty() {
res.push(c);
write!(f, "{c}")
} else {
let c =
if self.modifiers.intersects(KeyModifiers::CONTROL | KeyModifiers::SHIFT) {
Expand All @@ -228,7 +227,7 @@ impl ToString for TerminalKey {
c.to_string()
};

push_named(&mut res, c.as_str());
push_named(f, c.as_str())
}
},
KeyCode::Media(mc) => {
Expand All @@ -248,14 +247,13 @@ impl ToString for TerminalKey {
MediaKeyCode::MuteVolume => "MediaVolumeMute",
};

push_named(&mut res, name);
push_named(f, name)
},
KeyCode::Modifier(_) | KeyCode::KeypadBegin => {
// Do nothing with these for now.
Ok(())
},
}

return res;
}
}

Expand Down

0 comments on commit ccb799e

Please sign in to comment.