Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamdavidonuh committed Oct 3, 2024
1 parent 40ddc75 commit 65840a1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions ahnlich/cli/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crossterm::{
ExecutableCommand,
};
use std::io::{self, stdout, Stdout, Write};
use std::usize;

use crate::connect::AgentPool;

Expand All @@ -18,7 +17,6 @@ enum SpecialEntry {
Enter,
Up,
Down,
Break,
Left,
Right,
Del,
Expand All @@ -28,7 +26,6 @@ enum SpecialEntry {
enum Entry {
Char(char),
Special(SpecialEntry),
Other(KeyCode),
None,
}

Expand All @@ -41,7 +38,7 @@ impl Term {
Self { client_pool }
}

pub(crate) fn read_char(&self) -> io::Result<Entry> {
fn read_char(&self) -> io::Result<Entry> {
if let Event::Key(KeyEvent { code, .. }) = event::read()? {
Ok(match code {
KeyCode::Enter => Entry::Special(SpecialEntry::Enter),
Expand All @@ -51,7 +48,7 @@ impl Term {
KeyCode::Down => Entry::Special(SpecialEntry::Down),
KeyCode::Right => Entry::Special(SpecialEntry::Right),
KeyCode::Backspace => Entry::Special(SpecialEntry::Del),
_ => Entry::Other(code),
_ => Entry::None,
})
} else {
Ok(Entry::None)
Expand Down Expand Up @@ -94,11 +91,7 @@ impl Term {
.char_indices()
.nth(char_index as usize)
.map(|(entry, _)| entry)
.expect(&format!(
"Index out of bounds {} --> {}",
input.len(),
char_index
));
.unwrap_or_else(|| panic!("Index out of bounds {} --> {}", input.len(), char_index));

input.remove(byte_index);
}
Expand All @@ -109,7 +102,7 @@ impl Term {
output: &str,
col_pos: u16,
) -> io::Result<()> {
let formatted_output = self.format_output(&output);
let formatted_output = self.format_output(output);
queue!(
stdout,
cursor::MoveToColumn(col_pos),
Expand All @@ -125,12 +118,12 @@ impl Term {
output: &str,
col_pos: u16,
) -> io::Result<()> {
let formatted_output = self.format_output(&output);
let formatted_output = self.format_output(output);
let clean = vec![" "; output.len() + 1];
queue!(
stdout,
cursor::MoveToColumn(col_pos),
Print(format!("{}", clean.join(""))),
Print(clean.join("").to_string()),
cursor::MoveToColumn(col_pos),
Print(formatted_output)
)?;
Expand All @@ -154,7 +147,7 @@ impl Term {
SpecialEntry::Up | SpecialEntry::Down => {
continue;
}
SpecialEntry::Enter | SpecialEntry::Break => {
SpecialEntry::Enter => {
queue!(stdout, Print("\n"), cursor::MoveToColumn(0))?;
stdout.flush()?;
break;
Expand Down Expand Up @@ -182,7 +175,7 @@ impl Term {
}
}
},
Entry::Other(_) | Entry::None => {
Entry::None => {
continue;
}
}
Expand Down

0 comments on commit 65840a1

Please sign in to comment.