Warnings cleanup (#198)
This commit is contained in:
parent
ec44719d2c
commit
68346699e1
@ -53,7 +53,7 @@ impl TerminalInput {
|
|||||||
pub fn read_line(&self) -> io::Result<String> {
|
pub fn read_line(&self) -> io::Result<String> {
|
||||||
let mut rv = String::new();
|
let mut rv = String::new();
|
||||||
io::stdin().read_line(&mut rv)?;
|
io::stdin().read_line(&mut rv)?;
|
||||||
let len = rv.trim_right_matches(&['\r', '\n'][..]).len();
|
let len = rv.trim_end_matches(&['\r', '\n'][..]).len();
|
||||||
rv.truncate(len);
|
rv.truncate(len);
|
||||||
Ok(rv)
|
Ok(rv)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ pub struct AsyncReader {
|
|||||||
impl AsyncReader {
|
impl AsyncReader {
|
||||||
/// Construct a new instance of the `AsyncReader`.
|
/// Construct a new instance of the `AsyncReader`.
|
||||||
/// The reading will immediately start when calling this function.
|
/// The reading will immediately start when calling this function.
|
||||||
pub fn new(function: Box<Fn(&Sender<u8>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
|
pub fn new(function: Box<dyn Fn(&Sender<u8>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
|
||||||
let shutdown_handle = Arc::new(AtomicBool::new(false));
|
let shutdown_handle = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let (event_tx, event_rx) = mpsc::channel();
|
let (event_tx, event_rx) = mpsc::channel();
|
||||||
@ -242,7 +242,7 @@ where
|
|||||||
Some(b'O') => {
|
Some(b'O') => {
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
// F1-F4
|
// F1-F4
|
||||||
Some(val @ b'P'...b'S') => {
|
Some(val @ b'P'..=b'S') => {
|
||||||
InputEvent::Keyboard(KeyEvent::F(1 + val - b'P'))
|
InputEvent::Keyboard(KeyEvent::F(1 + val - b'P'))
|
||||||
}
|
}
|
||||||
_ => return Err(error),
|
_ => return Err(error),
|
||||||
@ -263,10 +263,10 @@ where
|
|||||||
b'\n' | b'\r' => InputEvent::Keyboard(KeyEvent::Char('\n')),
|
b'\n' | b'\r' => InputEvent::Keyboard(KeyEvent::Char('\n')),
|
||||||
b'\t' => InputEvent::Keyboard(KeyEvent::Char('\t')),
|
b'\t' => InputEvent::Keyboard(KeyEvent::Char('\t')),
|
||||||
b'\x7F' => InputEvent::Keyboard(KeyEvent::Backspace),
|
b'\x7F' => InputEvent::Keyboard(KeyEvent::Backspace),
|
||||||
c @ b'\x01'...b'\x1A' => {
|
c @ b'\x01'..=b'\x1A' => {
|
||||||
InputEvent::Keyboard(KeyEvent::Ctrl((c as u8 - 0x1 + b'a') as char))
|
InputEvent::Keyboard(KeyEvent::Ctrl((c as u8 - 0x1 + b'a') as char))
|
||||||
}
|
}
|
||||||
c @ b'\x1C'...b'\x1F' => {
|
c @ b'\x1C'..=b'\x1F' => {
|
||||||
InputEvent::Keyboard(KeyEvent::Ctrl((c as u8 - 0x1C + b'4') as char))
|
InputEvent::Keyboard(KeyEvent::Ctrl((c as u8 - 0x1C + b'4') as char))
|
||||||
}
|
}
|
||||||
b'\0' => InputEvent::Keyboard(KeyEvent::Null),
|
b'\0' => InputEvent::Keyboard(KeyEvent::Null),
|
||||||
@ -290,7 +290,7 @@ where
|
|||||||
Some(b'[') => match iter.next() {
|
Some(b'[') => match iter.next() {
|
||||||
// NOTE (@imdaveho): cannot find when this occurs;
|
// NOTE (@imdaveho): cannot find when this occurs;
|
||||||
// having another '[' after ESC[ not a likely scenario
|
// having another '[' after ESC[ not a likely scenario
|
||||||
Some(val @ b'A'...b'E') => InputEvent::Keyboard(KeyEvent::F(1 + val - b'A')),
|
Some(val @ b'A'..=b'E') => InputEvent::Keyboard(KeyEvent::F(1 + val - b'A')),
|
||||||
_ => InputEvent::Unknown,
|
_ => InputEvent::Unknown,
|
||||||
},
|
},
|
||||||
Some(b'D') => InputEvent::Keyboard(KeyEvent::Left),
|
Some(b'D') => InputEvent::Keyboard(KeyEvent::Left),
|
||||||
@ -350,7 +350,7 @@ where
|
|||||||
let cy = nums.next().unwrap().parse::<u16>().unwrap();
|
let cy = nums.next().unwrap().parse::<u16>().unwrap();
|
||||||
|
|
||||||
match cb {
|
match cb {
|
||||||
0...2 | 64...65 => {
|
0..=2 | 64..=65 => {
|
||||||
let button = match cb {
|
let button = match cb {
|
||||||
0 => MouseButton::Left,
|
0 => MouseButton::Left,
|
||||||
1 => MouseButton::Middle,
|
1 => MouseButton::Middle,
|
||||||
@ -370,7 +370,7 @@ where
|
|||||||
_ => InputEvent::Unknown,
|
_ => InputEvent::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(c @ b'0'...b'9') => {
|
Some(c @ b'0'..=b'9') => {
|
||||||
// Numbered escape code.
|
// Numbered escape code.
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
buf.push(c);
|
buf.push(c);
|
||||||
@ -430,9 +430,9 @@ where
|
|||||||
4 | 8 => InputEvent::Keyboard(KeyEvent::End),
|
4 | 8 => InputEvent::Keyboard(KeyEvent::End),
|
||||||
5 => InputEvent::Keyboard(KeyEvent::PageUp),
|
5 => InputEvent::Keyboard(KeyEvent::PageUp),
|
||||||
6 => InputEvent::Keyboard(KeyEvent::PageDown),
|
6 => InputEvent::Keyboard(KeyEvent::PageDown),
|
||||||
v @ 11...15 => InputEvent::Keyboard(KeyEvent::F(v - 10)),
|
v @ 11..=15 => InputEvent::Keyboard(KeyEvent::F(v - 10)),
|
||||||
v @ 17...21 => InputEvent::Keyboard(KeyEvent::F(v - 11)),
|
v @ 17..=21 => InputEvent::Keyboard(KeyEvent::F(v - 11)),
|
||||||
v @ 23...24 => InputEvent::Keyboard(KeyEvent::F(v - 12)),
|
v @ 23..=24 => InputEvent::Keyboard(KeyEvent::F(v - 12)),
|
||||||
_ => InputEvent::Unknown,
|
_ => InputEvent::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::{execute, impl_display, queue, write_cout, Result};
|
#[cfg(windows)]
|
||||||
|
use crate::Result;
|
||||||
|
use crate::{execute, impl_display, queue, write_cout};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
@ -31,13 +33,13 @@ pub trait Command {
|
|||||||
/// This can be used in order to get more performance.
|
/// This can be used in order to get more performance.
|
||||||
pub trait QueueableCommand<T: Display> {
|
pub trait QueueableCommand<T: Display> {
|
||||||
/// Queues the given command for later execution.
|
/// Queues the given command for later execution.
|
||||||
fn queue(mut self, command: impl Command<AnsiType = T>) -> Self;
|
fn queue(self, command: impl Command<AnsiType = T>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait that defines behaviour for a command that will be executed immediately.
|
/// A trait that defines behaviour for a command that will be executed immediately.
|
||||||
pub trait ExecutableCommand<T: Display> {
|
pub trait ExecutableCommand<T: Display> {
|
||||||
/// Execute the given command directly.
|
/// Execute the given command directly.
|
||||||
fn execute(mut self, command: impl Command<AnsiType = T>) -> Self;
|
fn execute(self, command: impl Command<AnsiType = T>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, A> QueueableCommand<A> for T
|
impl<T, A> QueueableCommand<A> for T
|
||||||
@ -66,7 +68,7 @@ where
|
|||||||
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
||||||
/// - Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.
|
/// - Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.
|
||||||
fn queue(mut self, command: impl Command<AnsiType = A>) -> Self {
|
fn queue(mut self, command: impl Command<AnsiType = A>) -> Self {
|
||||||
queue!(self, command);
|
let _ = queue!(self, command);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +92,7 @@ where
|
|||||||
/// This is happening because Windows versions lower then 10 do not support ANSI codes, and thus they can't be written to the given buffer.
|
/// This is happening because Windows versions lower then 10 do not support ANSI codes, and thus they can't be written to the given buffer.
|
||||||
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
||||||
fn execute(mut self, command: impl Command<AnsiType = A>) -> Self {
|
fn execute(mut self, command: impl Command<AnsiType = A>) -> Self {
|
||||||
execute!(self, command);
|
let _ = execute!(self, command);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/// Append a the first few characters of an ANSI escape code to the given string.
|
/// Append a the first few characters of an ANSI escape code to the given string.
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! csi {
|
macro_rules! csi {
|
||||||
($( $l:expr ),*) => { concat!("\x1B[", $( $l ),*) };
|
($( $l:expr ),*) => { concat!("\x1B[", $( $l ),*) };
|
||||||
@ -66,8 +65,9 @@ macro_rules! write_cout {
|
|||||||
/// - Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.
|
/// - Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! queue {
|
macro_rules! queue {
|
||||||
($write:expr, $($command:expr), *) =>
|
($write:expr, $($command:expr), *) => {{
|
||||||
{{
|
// Silent warning when the macro is used inside the `command` module
|
||||||
|
#[allow(unused_imports)]
|
||||||
use $crate::Command;
|
use $crate::Command;
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ macro_rules! queue {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
if $crate::supports_ansi() {
|
if $crate::supports_ansi() {
|
||||||
match write!($write, "{}",$command.get_ansi_code()) {
|
match write!($write, "{}", $command.get_ansi_code()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error = Some(Err($crate::ErrorKind::from(e)));
|
error = Some(Err($crate::ErrorKind::from(e)));
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ macro_rules! queue {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
match write!($write, "{}",$command.get_ansi_code()) {
|
match write!($write, "{}", $command.get_ansi_code()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error = Some(Err($crate::ErrorKind::from(e)));
|
error = Some(Err($crate::ErrorKind::from(e)));
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ macro_rules! queue {
|
|||||||
|
|
||||||
if let Some(error) = error {
|
if let Some(error) = error {
|
||||||
error
|
error
|
||||||
}else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -137,8 +137,9 @@ macro_rules! queue {
|
|||||||
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! execute {
|
macro_rules! execute {
|
||||||
($write:expr, $($command:expr), *) =>
|
($write:expr, $($command:expr), *) => {{
|
||||||
{{
|
// Silent warning when the macro is used inside the `command` module
|
||||||
|
#[allow(unused_imports)]
|
||||||
use $crate::{Command, write_cout};
|
use $crate::{Command, write_cout};
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
@ -172,7 +173,7 @@ macro_rules! execute {
|
|||||||
|
|
||||||
if let Some(error) = error {
|
if let Some(error) = error {
|
||||||
error
|
error
|
||||||
}else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
extern crate crossterm;
|
extern crate crossterm;
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
execute, queue, Clear, ClearType, Color, Colorize, ExecutableCommand, Goto, Output,
|
execute, queue, Clear, ClearType, ExecutableCommand, Goto, Output, QueueableCommand,
|
||||||
PrintStyledFont, QueueableCommand,
|
|
||||||
};
|
};
|
||||||
use std::fmt::Display;
|
use std::io::{stdout, Write};
|
||||||
use std::io::{stdout, Stdout, Write};
|
|
||||||
|
|
||||||
/// execute commands by using normal functions
|
/// execute commands by using normal functions
|
||||||
fn execute_command_directly_using_functions() {
|
fn execute_command_directly_using_functions() {
|
||||||
// single command
|
// single command
|
||||||
stdout().execute(Output("Text1 ".to_string()));
|
let _ = stdout().execute(Output("Text1 ".to_string()));
|
||||||
|
|
||||||
// multiple commands
|
// multiple commands
|
||||||
stdout()
|
let _ = stdout()
|
||||||
.execute(Output("Text2 ".to_string()))
|
.execute(Output("Text2 ".to_string()))
|
||||||
.execute(Output("Text3 ".to_string()));
|
.execute(Output("Text3 ".to_string()));
|
||||||
}
|
}
|
||||||
@ -21,10 +21,10 @@ fn execute_command_directly_using_functions() {
|
|||||||
/// execute commands by using macro's
|
/// execute commands by using macro's
|
||||||
fn execute_command_directly_using_macros() {
|
fn execute_command_directly_using_macros() {
|
||||||
// single command
|
// single command
|
||||||
execute!(stdout(), Output("Text1 ".to_string()));
|
let _ = execute!(stdout(), Output("Text1 ".to_string()));
|
||||||
|
|
||||||
// multiple commands
|
// multiple commands
|
||||||
execute!(
|
let _ = execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
Output("Text2 ".to_string()),
|
Output("Text2 ".to_string()),
|
||||||
Output("Text 3".to_string())
|
Output("Text 3".to_string())
|
||||||
@ -49,7 +49,7 @@ fn later_execution_command_using_functions() {
|
|||||||
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||||
|
|
||||||
// when you call this all commands will be executed
|
// when you call this all commands will be executed
|
||||||
sdout.flush();
|
let _ = sdout.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// queue commands without executing them directly by using macro's
|
/// queue commands without executing them directly by using macro's
|
||||||
@ -57,10 +57,10 @@ fn later_execution_command_directly_using_macros() {
|
|||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
|
||||||
// single command
|
// single command
|
||||||
queue!(stdout, Output("Text1 ".to_string()));
|
let _ = queue!(stdout, Output("Text1 ".to_string()));
|
||||||
|
|
||||||
// multiple commands
|
// multiple commands
|
||||||
queue!(
|
let _ = queue!(
|
||||||
stdout,
|
stdout,
|
||||||
Clear(ClearType::All),
|
Clear(ClearType::All),
|
||||||
Goto(5, 5),
|
Goto(5, 5),
|
||||||
@ -70,7 +70,7 @@ fn later_execution_command_directly_using_macros() {
|
|||||||
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||||
|
|
||||||
// when you call this all commands will be executed
|
// when you call this all commands will be executed
|
||||||
stdout.flush();
|
let _ = stdout.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// Remove once the TODO below is fixed
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
extern crate crossterm;
|
extern crate crossterm;
|
||||||
|
|
||||||
use crossterm::{Color, Crossterm};
|
use crossterm::{Color, Crossterm};
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
extern crate crossterm;
|
extern crate crossterm;
|
||||||
|
|
||||||
use self::crossterm::{color, Attribute, Color, Colored, Colorize, Styler};
|
use self::crossterm::{color, Attribute, Color, Colored, Colorize, Styler};
|
||||||
use std::io::stdout;
|
|
||||||
|
|
||||||
/// print some red text | demonstration.
|
/// print some red text | demonstration.
|
||||||
pub fn paint_foreground() {
|
pub fn paint_foreground() {
|
||||||
@ -412,6 +411,5 @@ pub fn reset_fg_and_bg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use std::io::Write;
|
|
||||||
print_all_background_colors_with_method()
|
print_all_background_colors_with_method()
|
||||||
}
|
}
|
||||||
|
@ -136,5 +136,5 @@ pub fn exit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
scroll_down();
|
let _ = scroll_down();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user