Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
* Most (use vs full paths) was done using `clippy --fix`.
* The unused methods and traits did look unused and have been removed.
* The doc comments have been indented to a consistent level.
  • Loading branch information
tpoliaw committed Aug 29, 2024
1 parent fe974c3 commit c89f083
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 62 deletions.
16 changes: 0 additions & 16 deletions inquire/src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,6 @@ impl<'a> Iterator for AnsiStrippedChars<'a> {
}
}

/// Constructs an iterator over the chars of the input string, stripping away ANSI escape codes.
pub trait AnsiStrippable {
fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_>;
}

impl<T> AnsiStrippable for T
where
T: AsRef<str>,
{
fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_> {
AnsiStrippedChars {
input: self.as_ref(),
}
}
}

pub trait AnsiAware {
fn ansi_aware_chars(&self) -> AnsiAwareChars<'_>;
}
Expand Down
12 changes: 6 additions & 6 deletions inquire/src/date_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn get_current_date() -> NaiveDate {
}

pub fn get_start_date(month: chrono::Month, year: i32) -> NaiveDate {
chrono::NaiveDate::from_ymd_opt(year, month.number_from_month(), 1).unwrap()
NaiveDate::from_ymd_opt(year, month.number_from_month(), 1).unwrap()
}

pub fn get_month(month: u32) -> chrono::Month {
Expand Down Expand Up @@ -43,23 +43,23 @@ mod tests {
fn test_get_start_date() {
assert_eq!(
get_start_date(chrono::Month::January, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 1, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 1, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::February, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 2, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 2, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::March, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 3, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 3, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::December, 1883),
chrono::NaiveDate::from_ymd_opt(1883, 12, 1).unwrap()
NaiveDate::from_ymd_opt(1883, 12, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::June, 3042),
chrono::NaiveDate::from_ymd_opt(3042, 6, 1).unwrap()
NaiveDate::from_ymd_opt(3042, 6, 1).unwrap()
);
}

Expand Down
28 changes: 14 additions & 14 deletions inquire/src/prompts/one_liners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ where
/// # Returns
///
/// * `InquireResult<NaiveDate>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(NaiveDate)` where NaiveDate's value is the date selected by the user. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(NaiveDate)` where NaiveDate's value is the date selected by the user. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -158,8 +158,8 @@ where
/// # Returns
///
/// * `InquireResult<f64>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(f64)` where f64 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(f64)` where f64 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -193,8 +193,8 @@ where
/// # Returns
///
/// * `InquireResult<f32>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(f32)` where f32 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(f32)` where f32 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -228,8 +228,8 @@ where
/// # Returns
///
/// * `InquireResult<u64>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(u64)` where u64 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(u64)` where u64 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -263,8 +263,8 @@ where
/// # Returns
///
/// * `InquireResult<u32>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(u32)` where u32 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(u32)` where u32 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -298,8 +298,8 @@ where
/// # Returns
///
/// * `InquireResult<usize>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(usize)` where usize is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(usize)` where usize is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down Expand Up @@ -333,8 +333,8 @@ where
/// # Returns
///
/// * `InquireResult<u128>`: An enum that represents the result of the prompt operation. If the operation is successful,
/// it returns `InquireResult::Ok(u128)` where u128 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
/// it returns `InquireResult::Ok(u128)` where u128 is the number parsed from the user's input. If the operation
/// encounters an error, it returns `InquireResult::Err(InquireError)`.
///
/// # Example
///
Expand Down
8 changes: 0 additions & 8 deletions inquire/src/terminal/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ impl Terminal for ConsoleTerminal {
}
}

fn cursor_move_to_column(&mut self, idx: u16) -> Result<()> {
// console has no built-in method to set cursor column ¯\_(ツ)_/¯
self.term.move_cursor_left(1000)?;
self.term.move_cursor_right(idx as usize)?;

Ok(())
}

fn flush(&mut self) -> Result<()> {
self.term.flush()
}
Expand Down
6 changes: 1 addition & 5 deletions inquire/src/terminal/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl InputReader for CrosstermKeyReader {

impl CrosstermTerminal {
pub fn new() -> InquireResult<Self> {
crossterm::terminal::enable_raw_mode()?;
terminal::enable_raw_mode()?;

Ok(Self {
io: IO::Std(stderr()),
Expand Down Expand Up @@ -125,10 +125,6 @@ impl Terminal for CrosstermTerminal {
}
}

fn cursor_move_to_column(&mut self, idx: u16) -> Result<()> {
self.write_command(cursor::MoveToColumn(idx))
}

fn flush(&mut self) -> Result<()> {
self.get_writer().flush()
}
Expand Down
1 change: 0 additions & 1 deletion inquire/src/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub trait Terminal: Sized {
fn cursor_down(&mut self, cnt: u16) -> Result<()>;
fn cursor_left(&mut self, cnt: u16) -> Result<()>;
fn cursor_right(&mut self, cnt: u16) -> Result<()>;
fn cursor_move_to_column(&mut self, idx: u16) -> Result<()>;

fn flush(&mut self) -> Result<()>;
}
Expand Down
8 changes: 2 additions & 6 deletions inquire/src/terminal/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ impl<'a> Terminal for TermionTerminal<'a> {
}
}

fn cursor_move_to_column(&mut self, idx: u16) -> Result<()> {
write!(self.get_writer(), "\x1b[{}G", idx.saturating_add(1))
}

fn flush(&mut self) -> Result<()> {
self.get_writer().flush()
}
Expand Down Expand Up @@ -196,11 +192,11 @@ impl<'a> Terminal for TermionTerminal<'a> {
}

fn cursor_hide(&mut self) -> Result<()> {
write!(self.get_writer(), "{}", termion::cursor::Hide)
write!(self.get_writer(), "{}", cursor::Hide)
}

fn cursor_show(&mut self) -> Result<()> {
write!(self.get_writer(), "{}", termion::cursor::Show)
write!(self.get_writer(), "{}", cursor::Show)
}
}

Expand Down
6 changes: 0 additions & 6 deletions inquire/src/terminal/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ impl Terminal for MockTerminal {
Ok(())
}

fn cursor_move_to_column(&mut self, idx: u16) -> std::io::Result<()> {
let token = MockTerminalToken::CursorMoveToColumn(idx);
self.output.push_back(token);
Ok(())
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
Expand Down

0 comments on commit c89f083

Please sign in to comment.