Make imports & docs more consistent (#524)

This commit is contained in:
Koxiaet 2020-12-28 08:47:20 +00:00 committed by GitHub
parent 5be7d18475
commit 0797441893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 45 additions and 39 deletions

View File

@ -85,6 +85,7 @@ impl<T: Write + ?Sized> QueueableCommand for T {
/// ///
/// ```rust /// ```rust
/// use std::io::{Write, stdout}; /// use std::io::{Write, stdout};
///
/// use crossterm::{Result, QueueableCommand, style::Print}; /// use crossterm::{Result, QueueableCommand, style::Print};
/// ///
/// fn main() -> Result<()> { /// fn main() -> Result<()> {
@ -113,7 +114,7 @@ impl<T: Write + ?Sized> QueueableCommand for T {
/// # Notes /// # Notes
/// ///
/// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'. /// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'.
/// * In case of Windows versions lower than 10, a direct WinApi call will be made. /// * In case of Windows versions lower than 10, a direct WinAPI call will be made.
/// The reason for this is that Windows versions lower than 10 do not support ANSI codes, /// The reason for this is that Windows versions lower than 10 do not support ANSI codes,
/// and can therefore not be written to the given `writer`. /// and can therefore not be written to the given `writer`.
/// Therefore, there is no difference between [execute](./trait.ExecutableCommand.html) /// Therefore, there is no difference between [execute](./trait.ExecutableCommand.html)
@ -150,6 +151,7 @@ impl<T: Write + ?Sized> ExecutableCommand for T {
/// ///
/// ```rust /// ```rust
/// use std::io::{Write, stdout}; /// use std::io::{Write, stdout};
///
/// use crossterm::{Result, ExecutableCommand, style::Print}; /// use crossterm::{Result, ExecutableCommand, style::Print};
/// ///
/// fn main() -> Result<()> { /// fn main() -> Result<()> {
@ -171,7 +173,7 @@ impl<T: Write + ?Sized> ExecutableCommand for T {
/// # Notes /// # Notes
/// ///
/// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'. /// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'.
/// * In case of Windows versions lower than 10, a direct WinApi call will be made. /// * In case of Windows versions lower than 10, a direct WinAPI call will be made.
/// The reason for this is that Windows versions lower than 10 do not support ANSI codes, /// The reason for this is that Windows versions lower than 10 do not support ANSI codes,
/// and can therefore not be written to the given `writer`. /// and can therefore not be written to the given `writer`.
/// Therefore, there is no difference between [execute](./trait.ExecutableCommand.html) /// Therefore, there is no difference between [execute](./trait.ExecutableCommand.html)

View File

@ -42,12 +42,13 @@
//! //!
//! For manual execution control check out [crossterm::queue](../macro.queue.html). //! For manual execution control check out [crossterm::queue](../macro.queue.html).
pub use sys::position; use std::fmt;
#[cfg(windows)] #[cfg(windows)]
use crate::Result; use crate::Result;
use crate::{impl_display, Command}; use crate::{impl_display, Command};
use std::fmt;
pub use sys::position;
mod ansi; mod ansi;
pub(crate) mod sys; pub(crate) mod sys;

View File

@ -1,4 +1,4 @@
//! WinApi related logic to cursor manipulation. //! WinAPI related logic to cursor manipulation.
use std::{io, sync::Mutex}; use std::{io, sync::Mutex};
@ -106,7 +106,7 @@ pub(crate) fn restore_position() -> Result<()> {
Ok(()) Ok(())
} }
/// WinApi wrapper over terminal cursor behaviour. /// WinAPI wrapper over terminal cursor behaviour.
struct ScreenBufferCursor { struct ScreenBufferCursor {
screen_buffer: ScreenBuffer, screen_buffer: ScreenBuffer,
} }

View File

@ -78,14 +78,15 @@ use parking_lot::RwLock;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use bitflags::bitflags; use bitflags::bitflags;
use filter::{EventFilter, Filter};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::{Command, Result};
use filter::{EventFilter, Filter};
#[cfg(feature = "event-stream")] #[cfg(feature = "event-stream")]
pub use stream::EventStream; pub use stream::EventStream;
use timeout::PollTimeout; use timeout::PollTimeout;
use crate::{Command, Result};
mod ansi; mod ansi;
pub(crate) mod filter; pub(crate) mod filter;
mod read; mod read;

View File

@ -1,7 +1,5 @@
use std::{collections::vec_deque::VecDeque, io, time::Duration}; use std::{collections::vec_deque::VecDeque, io, time::Duration};
use crate::ErrorKind;
#[cfg(unix)] #[cfg(unix)]
use super::source::unix::UnixInternalEventSource; use super::source::unix::UnixInternalEventSource;
#[cfg(windows)] #[cfg(windows)]
@ -10,6 +8,8 @@ use super::source::windows::WindowsEventSource;
use super::sys::Waker; use super::sys::Waker;
use super::{filter::Filter, source::EventSource, timeout::PollTimeout, InternalEvent, Result}; use super::{filter::Filter, source::EventSource, timeout::PollTimeout, InternalEvent, Result};
use crate::ErrorKind;
/// Can be used to read `InternalEvent`s. /// Can be used to read `InternalEvent`s.
pub(crate) struct InternalEventReader { pub(crate) struct InternalEventReader {
events: VecDeque<InternalEvent>, events: VecDeque<InternalEvent>,

View File

@ -1,6 +1,7 @@
use std::{collections::VecDeque, io, time::Duration};
use mio::{unix::SourceFd, Events, Interest, Poll, Token}; use mio::{unix::SourceFd, Events, Interest, Poll, Token};
use signal_hook::iterator::Signals; use signal_hook::iterator::Signals;
use std::{collections::VecDeque, io, time::Duration};
use crate::{ErrorKind, Result}; use crate::{ErrorKind, Result};

View File

@ -5,14 +5,12 @@ use std::{
mpsc::{self, SyncSender}, mpsc::{self, SyncSender},
Arc, Arc,
}, },
task::{Context, Poll},
thread, thread,
time::Duration, time::Duration,
}; };
use futures_core::{ use futures_core::stream::Stream;
stream::Stream,
task::{Context, Poll},
};
use crate::Result; use crate::Result;

View File

@ -1,10 +1,11 @@
use std::io;
use crate::{ use crate::{
event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind}, event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind},
ErrorKind, Result, ErrorKind, Result,
}; };
use super::super::super::InternalEvent; use super::super::super::InternalEvent;
use std::io;
// Event parsing // Event parsing
// //

View File

@ -3,7 +3,6 @@
use std::sync::Mutex; use std::sync::Mutex;
use crossterm_winapi::{ConsoleMode, Handle}; use crossterm_winapi::{ConsoleMode, Handle};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::Result; use crate::Result;

View File

@ -34,7 +34,7 @@
//! //!
//! Linux and Windows 10 systems support ANSI escape codes. Those ANSI escape codes are strings or rather a //! Linux and Windows 10 systems support ANSI escape codes. Those ANSI escape codes are strings or rather a
//! byte sequence. When we `write` and `flush` those to the terminal we can perform some action. //! byte sequence. When we `write` and `flush` those to the terminal we can perform some action.
//! For older windows systems a WinApi call is made. //! For older windows systems a WinAPI call is made.
//! //!
//! ### Supported Commands //! ### Supported Commands
//! //!

View File

@ -50,7 +50,7 @@ macro_rules! csi {
/// ///
/// # Notes /// # Notes
/// ///
/// In case of Windows versions lower than 10, a direct WinApi call will be made. /// In case of Windows versions lower than 10, a direct WinAPI call will be made.
/// The reason for this is that Windows versions lower than 10 do not support ANSI codes, /// The reason for this is that Windows versions lower than 10 do not support ANSI codes,
/// and can therefore not be written to the given `writer`. /// and can therefore not be written to the given `writer`.
/// Therefore, there is no difference between [execute](macro.execute.html) /// Therefore, there is no difference between [execute](macro.execute.html)
@ -104,7 +104,7 @@ macro_rules! queue {
/// # Notes /// # Notes
/// ///
/// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'. /// * In the case of UNIX and Windows 10, ANSI codes are written to the given 'writer'.
/// * In case of Windows versions lower than 10, a direct WinApi call will be made. /// * In case of Windows versions lower than 10, a direct WinAPI call will be made.
/// The reason for this is that Windows versions lower than 10 do not support ANSI codes, /// The reason for this is that Windows versions lower than 10 do not support ANSI codes,
/// and can therefore not be written to the given `writer`. /// and can therefore not be written to the given `writer`.
/// Therefore, there is no difference between [execute](macro.execute.html) /// Therefore, there is no difference between [execute](macro.execute.html)
@ -248,7 +248,7 @@ mod tests {
use crate::command::Command; use crate::command::Command;
use crate::error::Result as CrosstermResult; use crate::error::Result as CrosstermResult;
// We need to test two different APIs: winapi and the write api. We // We need to test two different APIs: WinAPI and the write api. We
// don't know until runtime which we're supporting (via // don't know until runtime which we're supporting (via
// Command::is_ansi_code_supported), so we have to test them both. The // Command::is_ansi_code_supported), so we have to test them both. The
// CI environment hopefully includes both versions of windows. // CI environment hopefully includes both versions of windows.
@ -287,7 +287,7 @@ mod tests {
} }
} }
// Helper function for running tests against either winapi or an // Helper function for running tests against either WinAPI or an
// io::Write. // io::Write.
// //
// This function will execute the `test` function, which should // This function will execute the `test` function, which should

View File

@ -243,6 +243,7 @@ impl Command for SetBackgroundColor {
/// For example: /// For example:
/// ```no_run /// ```no_run
/// use std::io::{stdout, Write}; /// use std::io::{stdout, Write};
///
/// use crossterm::execute; /// use crossterm::execute;
/// use crossterm::style::{Color::{Green, Black}, Colors, Print, SetColors}; /// use crossterm::style::{Color::{Green, Black}, Colors, Print, SetColors};
/// ///

View File

@ -1,6 +1,7 @@
use crate::style::Attribute;
use std::ops::{BitAnd, BitOr, BitXor}; use std::ops::{BitAnd, BitOr, BitXor};
use crate::style::Attribute;
/// a bitset for all possible attributes /// a bitset for all possible attributes
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Attributes(u32); pub struct Attributes(u32);

View File

@ -105,7 +105,7 @@ lazy_static! {
} }
impl From<Colored> for u16 { impl From<Colored> for u16 {
/// Returns the WinApi color value (u16) from the `Colored` struct. /// Returns the WinAPI color value (u16) from the `Colored` struct.
fn from(colored: Colored) -> Self { fn from(colored: Colored) -> Self {
match colored { match colored {
Colored::ForegroundColor(color) => { Colored::ForegroundColor(color) => {
@ -137,7 +137,7 @@ impl From<Colored> for u16 {
original_color & !REMOVE_BG_MASK original_color & !REMOVE_BG_MASK
} }
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/ /* WinAPI will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
Color::Rgb { .. } => 0, Color::Rgb { .. } => 0,
Color::AnsiValue(_val) => 0, Color::AnsiValue(_val) => 0,
} }
@ -169,7 +169,7 @@ impl From<Colored> for u16 {
original_color & !REMOVE_FG_MASK original_color & !REMOVE_FG_MASK
} }
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/ /* WinAPI will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
Color::Rgb { .. } => 0, Color::Rgb { .. } => 0,
Color::AnsiValue(_val) => 0, Color::AnsiValue(_val) => 0,
} }

View File

@ -1,8 +1,8 @@
use crate::style::Color;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::style::Color;
/// Represents a foreground or background color. /// Represents a foreground or background color.
/// ///
/// This can be converted to a [Colors](struct.Colors.html) by calling `into()` and applied /// This can be converted to a [Colors](struct.Colors.html) by calling `into()` and applied

View File

@ -1,7 +1,9 @@
//! UNIX related logic for terminal manipulation. //! UNIX related logic for terminal manipulation.
use std::fs::File;
use std::os::unix::io::{IntoRawFd, RawFd};
use std::{io, mem, process, sync::Mutex}; use std::{io, mem, process, sync::Mutex};
use crate::event::sys::unix::file_descriptor::{tty_fd, FileDesc};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use libc::{ use libc::{
cfmakeraw, ioctl, tcgetattr, tcsetattr, termios as Termios, winsize, STDOUT_FILENO, TCSANOW, cfmakeraw, ioctl, tcgetattr, tcsetattr, termios as Termios, winsize, STDOUT_FILENO, TCSANOW,
@ -9,8 +11,7 @@ use libc::{
}; };
use crate::error::{ErrorKind, Result}; use crate::error::{ErrorKind, Result};
use std::fs::File; use crate::event::sys::unix::file_descriptor::{tty_fd, FileDesc};
use std::os::unix::io::{IntoRawFd, RawFd};
lazy_static! { lazy_static! {
// Some(Termios) -> we're in the raw mode and this is the previous mode // Some(Termios) -> we're in the raw mode and this is the previous mode
@ -40,7 +41,7 @@ pub(crate) fn size() -> Result<(u16, u16)> {
STDOUT_FILENO STDOUT_FILENO
}; };
if let Ok(true) = wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }) { if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }).is_ok() {
Ok((size.ws_col, size.ws_row)) Ok((size.ws_col, size.ws_row))
} else { } else {
tput_size().ok_or_else(|| std::io::Error::last_os_error().into()) tput_size().ok_or_else(|| std::io::Error::last_os_error().into())
@ -127,14 +128,14 @@ fn get_terminal_attr(fd: RawFd) -> Result<Termios> {
} }
} }
fn set_terminal_attr(fd: RawFd, termios: &Termios) -> Result<bool> { fn set_terminal_attr(fd: RawFd, termios: &Termios) -> Result<()> {
wrap_with_result(unsafe { tcsetattr(fd, TCSANOW, termios) }) wrap_with_result(unsafe { tcsetattr(fd, TCSANOW, termios) })
} }
pub fn wrap_with_result(result: i32) -> Result<bool> { fn wrap_with_result(result: i32) -> Result<()> {
if result == -1 { if result == -1 {
Err(ErrorKind::IoError(io::Error::last_os_error())) Err(ErrorKind::IoError(io::Error::last_os_error()))
} else { } else {
Ok(true) Ok(())
} }
} }

View File

@ -1,4 +1,4 @@
//! WinApi related logic for terminal manipulation. //! WinAPI related logic for terminal manipulation.
use crossterm_winapi::{Console, ConsoleMode, Coord, Handle, ScreenBuffer, Size}; use crossterm_winapi::{Console, ConsoleMode, Coord, Handle, ScreenBuffer, Size};
use winapi::{ use winapi::{
shared::minwindef::DWORD, shared::minwindef::DWORD,
@ -295,9 +295,8 @@ fn clear_winapi(start_location: Coord, cells_to_write: u32, current_attribute: u
mod tests { mod tests {
use std::{ffi::OsString, os::windows::ffi::OsStringExt}; use std::{ffi::OsString, os::windows::ffi::OsStringExt};
use winapi::um::wincon::GetConsoleTitleW;
use crossterm_winapi::ScreenBuffer; use crossterm_winapi::ScreenBuffer;
use winapi::um::wincon::GetConsoleTitleW;
use super::{scroll_down, scroll_up, set_size, set_window_title, size}; use super::{scroll_down, scroll_up, set_size, set_window_title, size};

View File

@ -7,6 +7,7 @@
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
#[cfg(windows)] #[cfg(windows)]
use std::os::windows::io::AsRawHandle; use std::os::windows::io::AsRawHandle;
#[cfg(windows)] #[cfg(windows)]
use winapi::um::consoleapi::GetConsoleMode; use winapi::um::consoleapi::GetConsoleMode;