Skip to content

Commit

Permalink
lint: remove rustyline
Browse files Browse the repository at this point in the history
2,512,192 -> 2,299,024
  • Loading branch information
fosskers committed Jul 23, 2024
1 parent 52a05c5 commit 8cb2408
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 138 deletions.
144 changes: 20 additions & 124 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rust/aura-pm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pacmanconf = "2.0"
r2d2 = "0.8"
rayon = "1.8"
rust-embed = "8.0"
rustyline = "14"
serde = "1.0"
serde_json = "1.0"
simplelog = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion rust/aura-pm/src/command/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const FIVE_HUNDRED_MB: i64 = 524_288_000;
const CMPR_SWITCH: i64 = 1_577_404_800;

pub(crate) enum Error {
Readline(rustyline::error::ReadlineError),
Readline(std::io::Error),
Sudo(crate::utils::SudoError),
Pacman(crate::pacman::Error),
Cancelled,
Expand Down
2 changes: 1 addition & 1 deletion rust/aura-pm/src/command/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use time::macros::format_description;

pub(crate) enum Error {
Pacman(crate::pacman::Error),
Readline(rustyline::error::ReadlineError),
Readline(std::io::Error),
JsonWrite(PathBuf, serde_json::Error),
DeleteFile(PathBuf, std::io::Error),
OpenFile(PathBuf, std::io::Error),
Expand Down
34 changes: 23 additions & 11 deletions rust/aura-pm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use i18n_embed::fluent::FluentLanguageLoader;
use i18n_embed_fl::fl;
use karen::RunningAs;
use nonempty_collections::NEVec;
use rustyline::Editor;
use std::io::Write;
use std::iter::Peekable;
use std::path::Path;
Expand Down Expand Up @@ -97,25 +96,38 @@ fn pad(mult: usize, longest: usize, s: &str) -> usize {

/// Prompt the user for confirmation.
pub(crate) fn prompt(fll: &FluentLanguageLoader, msg: &str) -> Option<()> {
let mut rl = Editor::<(), _>::new().ok()?;
let line = rl.readline(msg).ok()?;
let accept_small = fl!(fll, "proceed-affirmative");
let accept_large = fl!(fll, "proceed-affirmative-alt");

(line.is_empty() || line == accept_small || line == accept_large).then_some(())
print!("{msg}");
std::io::stdout().flush().ok()?;

let mut input = String::new();
match std::io::stdin().read_line(&mut input) {
Err(_) => todo!(),
Ok(_) => {
let line = input.trim();
let accept_small = fl!(fll, "proceed-affirmative");
let accept_large = fl!(fll, "proceed-affirmative-alt");
(line.is_empty() || line == accept_small || line == accept_large).then_some(())
}
}
}

/// Prompt the user for a numerical selection.
pub(crate) fn select(msg: &str, max: usize) -> Result<usize, rustyline::error::ReadlineError> {
let mut rl = Editor::<(), _>::new()?;
pub(crate) fn select(msg: &str, max: usize) -> Result<usize, std::io::Error> {
let mut input = String::new();
let stdin = std::io::stdin();
let mut stdout = std::io::stdout();

loop {
let raw = rl.readline(msg)?;
print!("{msg}");
stdout.flush()?;
stdin.read_line(&mut input)?;

if let Ok(num) = usize::from_str(&raw) {
if let Ok(num) = usize::from_str(input.trim()) {
if max >= num {
return Ok(num);
}
} else {
input.clear();
}
}
}
Expand Down

0 comments on commit 8cb2408

Please sign in to comment.