Skip to content

Commit

Permalink
Merge pull request #654 from gwenn/clippy
Browse files Browse the repository at this point in the history
Clippy
  • Loading branch information
gwenn authored Oct 28, 2022
2 parents 187d408 + 47abd70 commit cf0b5e8
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions examples/custom_key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ impl Highlighter for MyHelper {
default: bool,
) -> Cow<'b, str> {
if default {
Owned(format!("\x1b[1;32m{}\x1b[m", prompt))
Owned(format!("\x1b[1;32m{prompt}\x1b[m"))
} else {
Borrowed(prompt)
}
}

fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
Owned(format!("\x1b[1m{}\x1b[m", hint))
Owned(format!("\x1b[1m{hint}\x1b[m"))
}
}

Expand Down Expand Up @@ -103,6 +103,6 @@ fn main() -> Result<()> {
loop {
let line = rl.readline("> ")?;
rl.add_history_entry(line.as_str());
println!("Line: {}", line);
println!("Line: {line}");
}
}
2 changes: 1 addition & 1 deletion examples/diy_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ fn main() -> Result<()> {

loop {
let input = rl.readline("> ")?;
println!("input: {}", input);
println!("input: {input}");
}
}
8 changes: 4 additions & 4 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ fn main() -> rustyline::Result<()> {
}
let mut count = 1;
loop {
let p = format!("{}> ", count);
rl.helper_mut().expect("No helper").colored_prompt = format!("\x1b[1;32m{}\x1b[0m", p);
let p = format!("{count}> ");
rl.helper_mut().expect("No helper").colored_prompt = format!("\x1b[1;32m{p}\x1b[0m");
let readline = rl.readline(&p);
match readline {
Ok(line) => {
rl.add_history_entry(line.as_str());
println!("Line: {}", line);
println!("Line: {line}");
}
Err(ReadlineError::Interrupted) => {
println!("Interrupted");
Expand All @@ -88,7 +88,7 @@ fn main() -> rustyline::Result<()> {
break;
}
Err(err) => {
println!("Error: {:?}", err);
println!("Error: {err:?}");
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/external_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> Result<()> {
let mut i = 0usize;
loop {
printer
.print(format!("External message #{}", i))
.print(format!("External message #{i}"))
.expect("External print failure");
let wait_ms = rng.gen_range(1000..10000);
thread::sleep(Duration::from_millis(wait_ms));
Expand All @@ -24,6 +24,6 @@ fn main() -> Result<()> {
loop {
let line = rl.readline("> ")?;
rl.add_history_entry(line.as_str());
println!("Line: {}", line);
println!("Line: {line}");
}
}
2 changes: 1 addition & 1 deletion examples/input_multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> Result<()> {
);

let input = rl.readline("> ")?;
println!("Input: {}", input);
println!("Input: {input}");

Ok(())
}
2 changes: 1 addition & 1 deletion examples/input_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fn main() -> Result<()> {
rl.set_helper(Some(h));

let input = rl.readline("> ")?;
println!("Input: {}", input);
println!("Input: {input}");
Ok(())
}
2 changes: 1 addition & 1 deletion examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() -> Result<()> {
let mut rl = Editor::<()>::new()?;
loop {
let line = rl.readline("> ")?; // read
println!("Line: {}", line); // eval / print
println!("Line: {line}"); // eval / print
} // loop
}
2 changes: 1 addition & 1 deletion examples/numeric_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ fn main() -> Result<()> {

loop {
let line = rl.readline("> ")?;
println!("Num: {}", line);
println!("Num: {line}");
}
}
4 changes: 2 additions & 2 deletions examples/read_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fn main() -> Result<()> {
rl.set_helper(Some(h));

let username = rl.readline("Username:")?;
println!("Username: {}", username);
println!("Username: {username}");

rl.helper_mut().expect("No helper").masking = true;
rl.set_color_mode(ColorMode::Forced); // force masking
rl.set_auto_add_history(false); // make sure password is not added to history
let passwd = rl.readline("Password:")?;
println!("Secret: {}", passwd);
println!("Secret: {passwd}");
Ok(())
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ fn reverse_incremental_search<H: Helper>(
// Display the reverse-i-search prompt and process chars
loop {
let prompt = if success {
format!("(reverse-i-search)`{}': ", search_buf)
format!("(reverse-i-search)`{search_buf}': ")
} else {
format!("(failed reverse-i-search)`{}': ", search_buf)
format!("(failed reverse-i-search)`{search_buf}': ")
};
s.refresh_prompt_and_line(&prompt)?;

Expand Down
12 changes: 6 additions & 6 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ impl PosixRenderer {
let cursor_row_movement = old_rows.saturating_sub(current_row);
// move the cursor down as required
if cursor_row_movement > 0 {
write!(self.buffer, "\x1b[{}B", cursor_row_movement).unwrap();
write!(self.buffer, "\x1b[{cursor_row_movement}B").unwrap();
}
// clear old rows
for _ in 0..old_rows {
Expand All @@ -912,15 +912,15 @@ impl Renderer for PosixRenderer {
if row_shift == 1 {
self.buffer.push_str("\x1b[B");
} else {
write!(self.buffer, "\x1b[{}B", row_shift)?;
write!(self.buffer, "\x1b[{row_shift}B")?;
}
} else if row_ordering == cmp::Ordering::Less {
// move up
let row_shift = old.row - new.row;
if row_shift == 1 {
self.buffer.push_str("\x1b[A");
} else {
write!(self.buffer, "\x1b[{}A", row_shift)?;
write!(self.buffer, "\x1b[{row_shift}A")?;
}
}
let col_ordering = new.col.cmp(&old.col);
Expand All @@ -930,15 +930,15 @@ impl Renderer for PosixRenderer {
if col_shift == 1 {
self.buffer.push_str("\x1b[C");
} else {
write!(self.buffer, "\x1b[{}C", col_shift)?;
write!(self.buffer, "\x1b[{col_shift}C")?;
}
} else if col_ordering == cmp::Ordering::Less {
// move left
let col_shift = old.col - new.col;
if col_shift == 1 {
self.buffer.push_str("\x1b[D");
} else {
write!(self.buffer, "\x1b[{}D", col_shift)?;
write!(self.buffer, "\x1b[{col_shift}D")?;
}
}
write_all(self.out, self.buffer.as_str())?;
Expand Down Expand Up @@ -997,7 +997,7 @@ impl Renderer for PosixRenderer {
let new_cursor_row_movement = end_pos.row - cursor.row;
// move the cursor up as required
if new_cursor_row_movement > 0 {
write!(self.buffer, "\x1b[{}A", new_cursor_row_movement)?;
write!(self.buffer, "\x1b[{new_cursor_row_movement}A")?;
}
// position the cursor within the line
if cursor.col > 0 {
Expand Down

0 comments on commit cf0b5e8

Please sign in to comment.