diff --git a/inquire/src/ansi.rs b/inquire/src/ansi.rs index 4b651c6e..feffeeb7 100644 --- a/inquire/src/ansi.rs +++ b/inquire/src/ansi.rs @@ -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 AnsiStrippable for T -where - T: AsRef, -{ - fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_> { - AnsiStrippedChars { - input: self.as_ref(), - } - } -} - pub trait AnsiAware { fn ansi_aware_chars(&self) -> AnsiAwareChars<'_>; } diff --git a/inquire/src/date_utils.rs b/inquire/src/date_utils.rs index cc348f46..5936eff7 100644 --- a/inquire/src/date_utils.rs +++ b/inquire/src/date_utils.rs @@ -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 { @@ -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() ); } diff --git a/inquire/src/prompts/one_liners.rs b/inquire/src/prompts/one_liners.rs index d6d76bdc..b348749c 100644 --- a/inquire/src/prompts/one_liners.rs +++ b/inquire/src/prompts/one_liners.rs @@ -122,8 +122,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -158,8 +158,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -193,8 +193,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -228,8 +228,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -263,8 +263,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -298,8 +298,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// @@ -333,8 +333,8 @@ where /// # Returns /// /// * `InquireResult`: 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 /// diff --git a/inquire/src/terminal/console.rs b/inquire/src/terminal/console.rs index 1c56c487..ae0e902b 100644 --- a/inquire/src/terminal/console.rs +++ b/inquire/src/terminal/console.rs @@ -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() } diff --git a/inquire/src/terminal/crossterm.rs b/inquire/src/terminal/crossterm.rs index 3d0a9cdc..be64c0f2 100644 --- a/inquire/src/terminal/crossterm.rs +++ b/inquire/src/terminal/crossterm.rs @@ -46,7 +46,7 @@ impl InputReader for CrosstermKeyReader { impl CrosstermTerminal { pub fn new() -> InquireResult { - crossterm::terminal::enable_raw_mode()?; + terminal::enable_raw_mode()?; Ok(Self { io: IO::Std(stderr()), @@ -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() } diff --git a/inquire/src/terminal/mod.rs b/inquire/src/terminal/mod.rs index 0cbf379a..0ce8cae7 100644 --- a/inquire/src/terminal/mod.rs +++ b/inquire/src/terminal/mod.rs @@ -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<()>; } diff --git a/inquire/src/terminal/termion.rs b/inquire/src/terminal/termion.rs index 6fcd6464..2537371a 100644 --- a/inquire/src/terminal/termion.rs +++ b/inquire/src/terminal/termion.rs @@ -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() } @@ -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) } } diff --git a/inquire/src/terminal/test.rs b/inquire/src/terminal/test.rs index dc0c7add..f02c931c 100644 --- a/inquire/src/terminal/test.rs +++ b/inquire/src/terminal/test.rs @@ -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(()) }