Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap crossterm::Result<T, ErrorKind> to std::io::Result. #765

Merged
merged 12 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use crossterm::{
event,
};

fn main() -> Result<()> {
fn main() -> std::io::Result<()> {
// using the macro
execute!(
stdout(),
Expand Down
9 changes: 4 additions & 5 deletions examples/event-poll-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
//!
//! cargo run --example event-poll-read

use std::{io::stdout, time::Duration};
use std::{io, time::Duration};

use crossterm::{
cursor::position,
event::{poll, read, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
execute,
terminal::{disable_raw_mode, enable_raw_mode},
Result,
};

const HELP: &str = r#"Blocking poll() & non-blocking read()
Expand All @@ -19,7 +18,7 @@ const HELP: &str = r#"Blocking poll() & non-blocking read()
- Use Esc to quit
"#;

fn print_events() -> Result<()> {
fn print_events() -> io::Result<()> {
loop {
// Wait up to 1s for another event
if poll(Duration::from_millis(1_000))? {
Expand All @@ -44,12 +43,12 @@ fn print_events() -> Result<()> {
Ok(())
}

fn main() -> Result<()> {
fn main() -> io::Result<()> {
println!("{}", HELP);

enable_raw_mode()?;

let mut stdout = stdout();
let mut stdout = io::stdout();
execute!(stdout, EnableMouseCapture)?;

if let Err(e) = print_events() {
Expand Down
11 changes: 5 additions & 6 deletions examples/event-read-char-line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
//!
//! cargo run --example event-read-char-line

use crossterm::{
event::{self, Event, KeyCode, KeyEvent},
Result,
};
use std::io;

pub fn read_char() -> Result<char> {
use crossterm::event::{self, Event, KeyCode, KeyEvent};

pub fn read_char() -> io::Result<char> {
loop {
if let Event::Key(KeyEvent {
code: KeyCode::Char(c),
Expand All @@ -20,7 +19,7 @@ pub fn read_char() -> Result<char> {
}
}

pub fn read_line() -> Result<String> {
pub fn read_line() -> io::Result<String> {
let mut line = String::new();
while let Event::Key(KeyEvent { code, .. }) = event::read()? {
match code {
Expand Down
9 changes: 4 additions & 5 deletions examples/event-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! cargo run --example event-read

use std::io::stdout;
use std::io;

use crossterm::event::{
poll, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
Expand All @@ -15,7 +15,6 @@ use crossterm::{
},
execute, queue,
terminal::{disable_raw_mode, enable_raw_mode},
Result,
};
use std::time::Duration;

Expand All @@ -25,7 +24,7 @@ const HELP: &str = r#"Blocking read()
- Use Esc to quit
"#;

fn print_events() -> Result<()> {
fn print_events() -> io::Result<()> {
loop {
// Blocking read
let event = read()?;
Expand Down Expand Up @@ -63,12 +62,12 @@ fn flush_resize_events(first_resize: (u16, u16)) -> ((u16, u16), (u16, u16)) {
(first_resize, last_resize)
}

fn main() -> Result<()> {
fn main() -> io::Result<()> {
println!("{}", HELP);

enable_raw_mode()?;

let mut stdout = stdout();
let mut stdout = io::stdout();

let supports_keyboard_enhancement = matches!(
crossterm::terminal::supports_keyboard_enhancement(),
Expand Down
3 changes: 1 addition & 2 deletions examples/event-stream-async-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode},
execute,
terminal::{disable_raw_mode, enable_raw_mode},
Result,
};

const HELP: &str = r#"EventStream based on futures_util::stream::Stream with async-std
Expand Down Expand Up @@ -52,7 +51,7 @@ async fn print_events() {
}
}

fn main() -> Result<()> {
fn main() -> std::io::Result<()> {
println!("{}", HELP);

enable_raw_mode()?;
Expand Down
3 changes: 1 addition & 2 deletions examples/event-stream-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream, KeyCode},
execute,
terminal::{disable_raw_mode, enable_raw_mode},
Result,
};

const HELP: &str = r#"EventStream based on futures_util::Stream with tokio
Expand Down Expand Up @@ -53,7 +52,7 @@ async fn print_events() {
}

#[tokio::main]
async fn main() -> Result<()> {
async fn main() -> std::io::Result<()> {
println!("{}", HELP);

enable_raw_mode()?;
Expand Down
14 changes: 7 additions & 7 deletions examples/interactive-demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![allow(clippy::cognitive_complexity)]

use std::io::{self, Write};
use std::io;

use crossterm::event::KeyEventKind;
pub use crossterm::{
cursor,
event::{self, Event, KeyCode, KeyEvent},
execute, queue, style,
terminal::{self, ClearType},
Command, Result,
Command,
};

#[macro_use]
Expand All @@ -33,9 +33,9 @@ Available tests:
Select test to run ('1', '2', ...) or hit 'q' to quit.
"#;

fn run<W>(w: &mut W) -> Result<()>
fn run<W>(w: &mut W) -> io::Result<()>
where
W: Write,
W: io::Write,
{
execute!(w, terminal::EnterAlternateScreen)?;

Expand Down Expand Up @@ -80,7 +80,7 @@ where
terminal::disable_raw_mode()
}

pub fn read_char() -> Result<char> {
pub fn read_char() -> std::io::Result<char> {
loop {
if let Ok(Event::Key(KeyEvent {
code: KeyCode::Char(c),
Expand All @@ -94,11 +94,11 @@ pub fn read_char() -> Result<char> {
}
}

pub fn buffer_size() -> Result<(u16, u16)> {
pub fn buffer_size() -> io::Result<(u16> {
terminal::size()
}

fn main() -> Result<()> {
fn main() -> std::io::Result<()> {
let mut stdout = io::stdout();
run(&mut stdout)
}
4 changes: 2 additions & 2 deletions examples/interactive-demo/src/test/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ATTRIBUTES: [(style::Attribute, style::Attribute); 10] = [
(style::Attribute::SlowBlink, style::Attribute::NoBlink),
];

fn test_set_display_attributes<W>(w: &mut W) -> Result<()>
fn test_set_display_attributes<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand All @@ -48,7 +48,7 @@ where
Ok(())
}

pub fn run<W>(w: &mut W) -> Result<()>
pub fn run<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand Down
16 changes: 8 additions & 8 deletions examples/interactive-demo/src/test/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const COLORS: [Color; 21] = [
Color::Rgb { r: 0, g: 0, b: 255 },
];

fn test_set_foreground_color<W>(w: &mut W) -> Result<()>
fn test_set_foreground_color<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand Down Expand Up @@ -63,7 +63,7 @@ where
Ok(())
}

fn test_set_background_color<W>(w: &mut W) -> Result<()>
fn test_set_background_color<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand Down Expand Up @@ -98,7 +98,7 @@ where
Ok(())
}

fn test_color_values_matrix_16x16<W, F>(w: &mut W, title: &str, color: F) -> Result<()>
fn test_color_values_matrix_16x16<W, F>(w: &mut W, title: &str, color: F) -> std::io::Result<()>
where
W: Write,
F: Fn(u16, u16) -> Color,
Expand Down Expand Up @@ -140,7 +140,7 @@ where
Ok(())
}

fn test_color_ansi_values<W>(w: &mut W) -> Result<()>
fn test_color_ansi_values<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand All @@ -149,7 +149,7 @@ where
})
}

fn test_rgb_red_values<W>(w: &mut W) -> Result<()>
fn test_rgb_red_values<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand All @@ -160,7 +160,7 @@ where
})
}

fn test_rgb_green_values<W>(w: &mut W) -> Result<()>
fn test_rgb_green_values<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand All @@ -171,7 +171,7 @@ where
})
}

fn test_rgb_blue_values<W>(w: &mut W) -> Result<()>
fn test_rgb_blue_values<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand All @@ -182,7 +182,7 @@ where
})
}

pub fn run<W>(w: &mut W) -> Result<()>
pub fn run<W>(w: &mut W) -> std::io::Result<()>
where
W: Write,
{
Expand Down
Loading