diff --git a/CHANGELOG.md b/CHANGELOG.md index 18bf866..6a559e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ -# Master +# Version 0.13.0 +**Major API-change, removed old-api** +- Remove `Crossterm` type +- Remove `TerminalCursor`, `TerminalColor`, `Terminal` +- Remove `cursor()`, `color()` , `terminal()` +- Remove re-exports at root, accessible via `module::types` (`cursor::MoveTo`) - `input` module - Derive 'Copy' for 'KeyEvent' - Add the `EnableMouseCapture` and `EnableMouseCapture` commands - `cursor` module - - Remove `TerminalCursor`, `cursor`, `Crossterm::cursor()` - Introduce static function `crossterm::cursor::position` in place of `TerminalCursor::pos` - Rename `Goto` to `MoveTo` - Rename `Up` to `MoveLeft` @@ -14,34 +18,29 @@ - Rename `BlinkOff` to `DisableBlinking` - Rename `ResetPos` to `ResetPosition` - Rename `SavePos` to `SavePosition` - - Remove re-export cursor module types at root level, are now accessible from `crossterm::cursor` - `terminal` - - Remove `Terminal`, `terminal`, `Crossterm::terminal()` - Introduce static function `crossterm::terminal::size` in place of `Terminal::size` - Introduce static function `crossterm::terminal::exit` in place of `Terminal::exit` - - Remove re-export terminal module types at root level, are move those to `crossterm::terminal` - `style module` - - Rename `ObjectStyle` to `ContentStyle`. Now full names are used for methods. - - Rename `StyledObject` to `StyledContent` and made members private. + - Rename `ObjectStyle` to `ContentStyle`. Now full names are used for methods + - Rename `StyledObject` to `StyledContent` and made members private - Rename `PrintStyledFont` to `PrintStyledContent` - Rename `attr` method to `attribute`. - Rename `Attribute::NoInverse` to `NoReverse` - - `Crossterm::style()` and `Crossterm::color()` - - Remove re-exports from style module at at root and only expose those in the `crossterm::style` module. - - Remove `TerminalColor` (/style.rs), - - Remove `color` (style.rs) - Update documentation - - Made `Colored` private, user should use commands instead. + - Made `Colored` private, user should use commands instead - Rename `SetFg` -> `SetForegroundColor` - Rename `SetBg` -> `SetBackgroundColor` - Rename `SetAttr` -> `SetAttribute` - Rename `ContentStyle::fg_color` -> `ContentStyle::foreground_color` - Rename `ContentStyle::bg_color` -> `ContentStyle::background_color` - Rename `ContentStyle::attrs` -> `ContentStyle::attributes` +- Improve documentation +- Unix terminal size calculation with TPUT # Version 0.12.1 -- All the `crossterm_` crates code was moved to the `crossterm` crate +- Move all the `crossterm_` crates code was moved to the `crossterm` crate - `crossterm_cursor` is in the `cursor` module, etc. - All these modules are public - No public API breaking changes @@ -58,34 +57,27 @@ ## `crossterm_cursor` 0.4.0 -- Internal refactoring ([PR #2](https://github.com/crossterm-rs/crossterm-cursor/pull/2)) - - Improved public documentation - - `sys` module is no longer public -- Fixed examples link ([PR #6](https://github.com/crossterm-rs/crossterm-cursor/pull/6)) +- Fix examples link ([PR #6](https://github.com/crossterm-rs/crossterm-cursor/pull/6)) - Sync documentation style ([PR #7](https://github.com/crossterm-rs/crossterm-cursor/pull/7)) -- Removed all references to the crossterm book ([PR #8](https://github.com/crossterm-rs/crossterm-cursor/pull/8)) -- Replaced `RAW_MODE_ENABLED` with `is_raw_mode_enabled` ([PR #9](https://github.com/crossterm-rs/crossterm-cursor/pull/9)) +- Remove all references to the crossterm book ([PR #8](https://github.com/crossterm-rs/crossterm-cursor/pull/8)) +- Replace `RAW_MODE_ENABLED` with `is_raw_mode_enabled` ([PR #9](https://github.com/crossterm-rs/crossterm-cursor/pull/9)) - Use `SyncReader` & `InputEvent::CursorPosition` for `pos_raw()` ([PR #10](https://github.com/crossterm-rs/crossterm-cursor/pull/10)) ## `crossterm_input` 0.5.0 -- Internal refactoring ([PR #3](https://github.com/crossterm-rs/crossterm-input/pull/3)) - - Removed unsafe `static mut` - - Documentation update - - Remove all references to the crossterm book - Sync documentation style ([PR #4](https://github.com/crossterm-rs/crossterm-input/pull/4)) - Sync `SyncReader::next()` Windows and UNIX behavior ([PR #5](https://github.com/crossterm-rs/crossterm-input/pull/5)) - Remove all references to the crossterm book ([PR #6](https://github.com/crossterm-rs/crossterm-input/pull/6)) - Mouse coordinates synchronized with the cursor ([PR #7](https://github.com/crossterm-rs/crossterm-input/pull/7)) - Upper/left reported as `(0, 0)` -- Fixed bug that read sync didn't block (Windows) ([PR #8](https://github.com/crossterm-rs/crossterm-input/pull/8)) -- Refactored UNIX readers ([PR #9](https://github.com/crossterm-rs/crossterm-input/pull/9)) +- Fix bug that read sync didn't block (Windows) ([PR #8](https://github.com/crossterm-rs/crossterm-input/pull/8)) +- Refactor UNIX readers ([PR #9](https://github.com/crossterm-rs/crossterm-input/pull/9)) - AsyncReader produces mouse events - One reading thread per application, not per `AsyncReader` - Cursor position no longer consumed by another `AsyncReader` - - Implemented sync reader for read_char (requires raw mode) - - Fixed `SIGTTIN` when executed under the LLDB - - Added mio for reading from FD and more efficient polling (UNIX only) + - Implement sync reader for read_char (requires raw mode) + - Fix `SIGTTIN` when executed under the LLDB + - Add mio for reading from FD and more efficient polling (UNIX only) - Sync UNIX and Windows vertical mouse position ([PR #11](https://github.com/crossterm-rs/crossterm-input/pull/11)) - Top is always reported as `0` @@ -103,10 +95,9 @@ ## `crossterm_style` 0.5.2 -- Refactoring ([PR #2](https://github.com/crossterm-rs/crossterm-style/pull/2)) +- Refactor ([PR #2](https://github.com/crossterm-rs/crossterm-style/pull/2)) - Added unit tests - - Restructured files - - Improved documentation and added book page to lib.rs + - Improved documentation and added book page to `lib.rs` - Fixed bug with `SetBg` command, WinApi logic - Fixed bug with `StyledObject`, used stdout for resetting terminal color - Introduced `ResetColor` command @@ -166,8 +157,8 @@ As a preparation for crossterm 0.1.0 we have moved crossterm to an organisation * `TerminalInput::read_char` returns `crossterm::Result` instead of `io::Result` * Maybe I forgot something, a lot of functions have changed - Removed all unwraps/expects from library -- Added KeyEvent::Enter and KeyEvent::Tab: [added-key-event-enter], [added-key-event-tab] -- Synced set/get terminal size behaviour: [fixed-get-set-terminal-size] +- Add KeyEvent::Enter and KeyEvent::Tab: [added-key-event-enter], [added-key-event-tab] +- Sync set/get terminal size behaviour: [fixed-get-set-terminal-size] - Method renames: * `AsyncReader::stop_reading()` to `stop()` * `RawScreen::disable_raw_mode_on_drop` to `keep_raw_mode_on_drop` @@ -210,11 +201,11 @@ As a preparation for crossterm 0.1.0 we have moved crossterm to an organisation # Version 0.10.1 # Version 0.10.0 ~ yanked -- Implemented command API, to have better performance and more control over how and when commands are executed. [PR](https://github.com/crossterm-rs/crossterm/commit/1a60924abd462ab169b6706aab68f4cca31d7bc2), [issue](https://github.com/crossterm-rs/crossterm/issues/171) -- Fixed showing, hiding cursor windows implementation -- Removed some of the parsing logic from windows keys to ansi codes to key events [PR](https://github.com/crossterm-rs/crossterm/commit/762c3a9b8e3d1fba87acde237f8ed09e74cd9ecd) +- Implement command API, to have better performance and more control over how and when commands are executed. [PR](https://github.com/crossterm-rs/crossterm/commit/1a60924abd462ab169b6706aab68f4cca31d7bc2), [issue](https://github.com/crossterm-rs/crossterm/issues/171) +- Fix showing, hiding cursor windows implementation +- Remove some of the parsing logic from windows keys to ansi codes to key events [PR](https://github.com/crossterm-rs/crossterm/commit/762c3a9b8e3d1fba87acde237f8ed09e74cd9ecd) - Made terminal size 1-based [PR](https://github.com/crossterm-rs/crossterm/commit/d689d7e8ed46a335474b8262bd76f21feaaf0c50) -- Added some derive implementation +- Add some derives # Version 0.9.6 @@ -225,7 +216,7 @@ As a preparation for crossterm 0.1.0 we have moved crossterm to an organisation # Version 0.9.5 -- Prefetching buffer size for more efficient windows input reads. [PR](https://github.com/crossterm-rs/crossterm/pull/144) +- Prefetch buffer size for more efficient windows input reads. [PR](https://github.com/crossterm-rs/crossterm/pull/144) # Version 0.9.4 diff --git a/README.md b/README.md index 5b285d3..7efef02 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,19 @@ worry about the platform you are working with. This crate supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested, see [Tested Terminals](#tested-terminals) for more info). +## Note on Migration + +You may have noticed that Crossterm has been [changing](https://github.com/crossterm-rs/crossterm/blob/master/CHANGELOG.md) very quickly with the latest versions. +We have done a lot of API-breaking things by renaming functions, commands, changing the exports, improving the encapsulation, etc.. +However, all of this happens to improve the library and make it ready for a possible [1.0 release](#287). +We want to stick to the [Command API](https://docs.rs/crossterm/#command-api) and remove all other ways to use crossterm. +Try to use this API and change your code accordingly. +This way you will survive or overcome major migration problems ;). +We want to reduce the ways crossterm can be used to make it simpler and easier to maintain. + +We hope you can understand this, feel free to ask around in [discord ](https://discord.gg/K4nyTDB) if you have questions on how to migrate. +Also, for up-to-date examples, have a look at the [examples](https://github.com/crossterm-rs/examples/tree/masteri) repository. + ## Table of Contents * [Features](#features) @@ -30,6 +43,7 @@ see [Tested Terminals](#tested-terminals) for more info). - Multi-threaded (send, sync) - Detailed documentation - Few dependencies +- Full control over output buffer - Cursor (feature `cursor`) - Move the cursor N times (up, down, left, right) - Set/get the cursor position @@ -94,22 +108,31 @@ crossterm = "0.12" ```rust use std::io::{stdout, Write}; -use crossterm::{execute, Attribute, Color, Output, ResetColor, Result, SetBg, SetFg}; +use crossterm::{execute, ExecutableCommand, style::{Attribute, Color, SetForegroundColor, SetBackgroundColor, ResetColor}, Output, Result}; fn main() -> Result<()> { + // using the macro execute!( stdout(), - // Blue foreground - SetFg(Color::Blue), - // Red background - SetBg(Color::Red), - Output("Styled text here.".to_string()), - // Reset to default colors + SetForegroundColor(Color::Blue), + SetBackgroundColor(Color::Red), + Output("Styled text here."), ResetColor - ) + )?; + + // or using functions + stdout() + .execute(SetForegroundColor(Color::Blue))? + .execute(SetBackgroundColor(Color::Red))? + .execute(Output("Styled text here."))? + .execute(ResetColor)?; + + Ok(()) } ``` +Checkout this [list](https://docs.rs/crossterm/0.13.0/crossterm/index.html#supported-commands) with all possible commands. + ### Feature Flags All features are enabled by default. You can disable default features and enable some of them only. diff --git a/src/crossterm.rs b/src/crossterm.rs deleted file mode 100644 index dc22233..0000000 --- a/src/crossterm.rs +++ /dev/null @@ -1,15 +0,0 @@ -/// A crossterm functionality wrapper. -pub struct Crossterm; - -impl Crossterm { - /// Creates a new `Crossterm`. - pub fn new() -> Crossterm { - Crossterm - } - - /// Creates a new `TerminalInput`. - #[cfg(feature = "input")] - pub fn input(&self) -> crate::input::TerminalInput { - crate::input::TerminalInput::new() - } -} diff --git a/src/input.rs b/src/input.rs index 0bb842c..c60f1e2 100644 --- a/src/input.rs +++ b/src/input.rs @@ -205,7 +205,7 @@ impl From for Option { /// ```no_run /// // You can replace the following line with `use crossterm::...;` /// // if you're using the `crossterm` crate with the `input` feature enabled. -/// use crossterm::{Result, TerminalInput, RawScreen}; +/// use crossterm::{Result, input::{TerminalInput}, screen::RawScreen}; /// /// fn main() -> Result<()> { /// let input = TerminalInput::new(); @@ -261,7 +261,7 @@ impl TerminalInput { /// # Examples /// /// ```no_run - /// let input = crossterm::input(); + /// let input = crossterm::input::input(); /// match input.read_line() { /// Ok(s) => println!("string typed: {}", s), /// Err(e) => println!("error: {}", e), @@ -276,7 +276,7 @@ impl TerminalInput { /// # Examples /// /// ```no_run - /// let input = crossterm::input(); + /// let input = crossterm::input::input(); /// match input.read_char() { /// Ok(c) => println!("character pressed: {}", c), /// Err(e) => println!("error: {}", e), @@ -302,7 +302,7 @@ impl TerminalInput { /// /// ```no_run /// use std::{thread, time::Duration}; - /// use crossterm::input; + /// use crossterm::input::input; /// /// let mut async_stdin = input().read_async(); /// @@ -335,8 +335,9 @@ impl TerminalInput { /// /// ```no_run /// use std::{thread, time::Duration}; + /// use crossterm::input::input; /// - /// let mut async_stdin = crossterm::input().read_until_async(b'x'); + /// let mut async_stdin = input().read_until_async(b'x'); /// /// loop { /// if let Some(key_event) = async_stdin.next() { @@ -360,8 +361,9 @@ impl TerminalInput { /// /// ```no_run /// use std::{thread, time::Duration}; + /// use crossterm::input::input; /// - /// let mut sync_stdin = crossterm::input().read_sync(); + /// let mut sync_stdin = input().read_sync(); /// /// loop { /// if let Some(key_event) = sync_stdin.next() { @@ -397,7 +399,7 @@ impl TerminalInput { /// ```no_run /// // You can replace the following line with `use crossterm::...;` /// // if you're using the `crossterm` crate with the `input` feature enabled. -/// use crossterm::{input, RawScreen, Result}; +/// use crossterm::{input::input, screen::RawScreen, Result}; /// /// fn main() -> Result<()> { /// let input = input(); diff --git a/src/input/input.rs b/src/input/input.rs index af0cda0..d263fca 100644 --- a/src/input/input.rs +++ b/src/input/input.rs @@ -39,7 +39,7 @@ pub(crate) trait Input { /// # Examples /// /// ```no_run - /// let input = crossterm::input(); + /// let input = crossterm::input::input(); /// match input.read_line() { /// Ok(s) => println!("string typed: {}", s), /// Err(e) => println!("error: {}", e), diff --git a/src/input/input/unix.rs b/src/input/input/unix.rs index 9d16160..a61a3ab 100644 --- a/src/input/input/unix.rs +++ b/src/input/input/unix.rs @@ -92,7 +92,7 @@ impl Input for UnixInput { /// ```no_run /// use std::{thread, time::Duration}; /// -/// use crossterm::{input, InputEvent, KeyEvent, RawScreen}; +/// use crossterm::{screen::RawScreen, input::{input, InputEvent, KeyEvent}}; /// /// fn main() { /// println!("Press 'ESC' to quit."); @@ -221,7 +221,7 @@ impl Iterator for AsyncReader { /// ```no_run /// use std::{thread, time::Duration}; /// -/// use crossterm::{input, InputEvent, KeyEvent, RawScreen}; +/// use crossterm::{screen::RawScreen, input::{input, InputEvent, KeyEvent}}; /// /// fn main() { /// println!("Press 'ESC' to quit."); diff --git a/src/input/input/windows.rs b/src/input/input/windows.rs index 93f2ee5..b77a644 100644 --- a/src/input/input/windows.rs +++ b/src/input/input/windows.rs @@ -29,13 +29,9 @@ use winapi::um::{ use lazy_static::lazy_static; +use crate::input::{input::Input, InputEvent, KeyEvent, MouseButton}; use crate::utils::Result; -use super::{ - super::{InputEvent, KeyEvent, MouseButton}, - Input, -}; - const ENABLE_MOUSE_MODE: u32 = 0x0010 | 0x0080 | 0x0008; lazy_static! { @@ -172,7 +168,7 @@ impl Input for WindowsInput { /// ```no_run /// use std::{thread, time::Duration}; /// -/// use crossterm::{input, InputEvent, KeyEvent, RawScreen}; +/// use crossterm::{screen::RawScreen, input::{input, InputEvent, KeyEvent}}; /// /// fn main() { /// println!("Press 'ESC' to quit."); @@ -245,7 +241,7 @@ impl Iterator for SyncReader { /// ```no_run /// use std::{thread, time::Duration}; /// -/// use crossterm::{input, InputEvent, KeyEvent, RawScreen}; +/// use crossterm::{screen::RawScreen, input::{input, InputEvent, KeyEvent}}; /// /// fn main() { /// println!("Press 'ESC' to quit."); @@ -534,7 +530,7 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option { } } -fn parse_mouse_event_record(event: &MouseEvent) -> Result> { +fn parse_mouse_event_record(event: &MouseEvent) -> Result> { // NOTE (@imdaveho): xterm emulation takes the digits of the coords and passes them // individually as bytes into a buffer; the below cxbs and cybs replicates that and // mimicks the behavior; additionally, in xterm, mouse move is only handled when a @@ -554,10 +550,12 @@ fn parse_mouse_event_record(event: &MouseEvent) -> Result { // Single click match event.button_state { - ButtonState::Release => Some(crate::MouseEvent::Release(xpos as u16, ypos as u16)), + ButtonState::Release => { + Some(crate::input::MouseEvent::Release(xpos as u16, ypos as u16)) + } ButtonState::FromLeft1stButtonPressed => { // left click - Some(crate::MouseEvent::Press( + Some(crate::input::MouseEvent::Press( MouseButton::Left, xpos as u16, ypos as u16, @@ -565,7 +563,7 @@ fn parse_mouse_event_record(event: &MouseEvent) -> Result { // right click - Some(crate::MouseEvent::Press( + Some(crate::input::MouseEvent::Press( MouseButton::Right, xpos as u16, ypos as u16, @@ -573,7 +571,7 @@ fn parse_mouse_event_record(event: &MouseEvent) -> Result { // middle click - Some(crate::MouseEvent::Press( + Some(crate::input::MouseEvent::Press( MouseButton::Middle, xpos as u16, ypos as u16, @@ -586,7 +584,7 @@ fn parse_mouse_event_record(event: &MouseEvent) -> Result Result Result<()> { /// let _alternate = AlternateScreen::to_alternate(true)?; @@ -145,7 +145,7 @@ impl Drop for AlternateScreen { /// /// ```no_run /// use std::io::{stdout, Write}; -/// use crossterm::{execute, Result, EnterAlternateScreen, LeaveAlternateScreen}; +/// use crossterm::{execute, Result,screen::{EnterAlternateScreen, LeaveAlternateScreen}}; /// /// fn main() -> Result<()> { /// execute!(stdout(), EnterAlternateScreen)?; @@ -181,7 +181,7 @@ impl Command for EnterAlternateScreen { /// /// ```no_run /// use std::io::{stdout, Write}; -/// use crossterm::{execute, Result, EnterAlternateScreen, LeaveAlternateScreen}; +/// use crossterm::{execute, Result, screen::{EnterAlternateScreen, LeaveAlternateScreen}}; /// /// fn main() -> Result<()> { /// execute!(stdout(), EnterAlternateScreen)?; diff --git a/src/screen/alternate.rs b/src/screen/alternate.rs index 9dc8f26..ea9de4e 100644 --- a/src/screen/alternate.rs +++ b/src/screen/alternate.rs @@ -3,7 +3,7 @@ pub(crate) use ansi::AnsiAlternateScreen; pub(crate) use windows::WinApiAlternateScreen; #[cfg(windows)] -use crate::utils::supports_ansi; +use crate::supports_ansi; use crate::utils::Result; pub(crate) mod ansi; diff --git a/src/screen/raw.rs b/src/screen/raw.rs index 9e9f825..3ee57cc 100644 --- a/src/screen/raw.rs +++ b/src/screen/raw.rs @@ -15,7 +15,7 @@ use super::sys; /// Basic usage: /// /// ```no_run -/// use crossterm::{RawScreen, Result}; +/// use crossterm::{screen::RawScreen, Result}; /// /// fn main() -> Result<()> { /// let _raw = RawScreen::into_raw_mode()?; @@ -27,7 +27,7 @@ use super::sys; /// Do not disable the raw mode implicitly: /// /// ```no_run -/// use crossterm::{RawScreen, Result}; +/// use crossterm::{screen::RawScreen, Result}; /// /// fn main() -> Result<()> { /// let mut raw = RawScreen::into_raw_mode()?; @@ -93,7 +93,7 @@ impl RawScreen { /// /// ```no_run /// use std::io::stdout; -/// use crossterm::{IntoRawMode, Result}; +/// use crossterm::{screen::IntoRawMode, Result}; /// /// fn main() -> Result<()> { /// let stdout = stdout(); diff --git a/src/style.rs b/src/style.rs index 0e3cca8..1130109 100644 --- a/src/style.rs +++ b/src/style.rs @@ -16,10 +16,14 @@ //! * [Attribute](enum.Attribute.html#platform-specific-notes) //! //! ## Examples +//! A few examples of how to use the style module. //! //! ### Colors +//! How to change the terminal text color. //! -//! The command API: +//! **Command API** +//! +//! Using the Command API to color text. //! //! ```no_run //! use std::io::{stdout, Write}; @@ -42,7 +46,9 @@ //! } //! ``` //! -//! The [`Colorize`](trait.Colorize.html) trait: +//! **Functions** +//! +//! Using functions from [`Colorize`](trait.Colorize.html) on a `String` or `&'static str` to color it. //! //! ```no_run //! use crossterm::style::Colorize; @@ -51,8 +57,11 @@ //! ``` //! //! ### Attributes +//! How to appy terminal attributes to text. //! -//! The command API: +//! **Command API** +//! +//! Using the Command API to set attributes. //! //! ```no_run //! use std::io::{stdout, Write}; @@ -72,7 +81,9 @@ //! } //! ``` //! -//! The [`Styler`](trait.Styler.html) trait: +//! **Functions**: +//! +//! Using [`Styler`](trait.Styler.html) functions on a `String` or `&'static str` to set attributes to it. //! //! ```no_run //! use crossterm::style::Styler; @@ -82,7 +93,9 @@ //! println!("{}", "Negative".negative()); //! ``` //! -//! The [`Attribute`](enum.Attribute.html) enum: +//! **Displayable** +//! +//! [`Attribute`](enum.Attribute.html) implements [Display](https://doc.rust-lang.org/beta/std/fmt/trait.Display.html) and therefore it can be formatted like: //! //! ```no_run //! use crossterm::style::Attribute; @@ -99,7 +112,6 @@ use std::fmt::Display; use crate::impl_display; use crate::utils::Command; - #[cfg(windows)] use crate::Result; diff --git a/src/style/content_style.rs b/src/style/content_style.rs index 693e745..80a5b51 100644 --- a/src/style/content_style.rs +++ b/src/style/content_style.rs @@ -4,7 +4,7 @@ use std::fmt::Display; use crate::style::{Attribute, Color, StyledContent}; -/// A content style. +/// The style that can be put on content. #[derive(Debug, Clone, Default)] pub struct ContentStyle { /// The foreground color. diff --git a/src/style/styled_content.rs b/src/style/styled_content.rs index c6b7282..f0d4a3e 100644 --- a/src/style/styled_content.rs +++ b/src/style/styled_content.rs @@ -4,13 +4,12 @@ use std::fmt::{self, Display, Formatter}; use std::result; use crate::queue; - use crate::style::{ Attribute, Color, Colorize, ContentStyle, ResetColor, SetAttribute, SetBackgroundColor, SetForegroundColor, Styler, }; -/// A styled content. +/// The style with the content to be styled. /// /// # Examples /// diff --git a/src/style/sys/windows.rs b/src/style/sys/windows.rs index 65bd12b..1faaa4e 100644 --- a/src/style/sys/windows.rs +++ b/src/style/sys/windows.rs @@ -180,10 +180,11 @@ impl From for u16 { #[cfg(test)] mod tests { + use crate::style::sys::windows::set_foreground_color; + use super::{ Color, Colored, BG_INTENSITY, BG_RED, FG_INTENSITY, FG_RED, ORIGINAL_CONSOLE_COLOR, }; - use crate::style::sys::windows::set_foreground_color; #[test] fn test_parse_fg_color() { diff --git a/src/utils.rs b/src/utils.rs index 6f27eba..06c99cd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,11 +2,9 @@ pub use self::command::{Command, ExecutableCommand, Output, QueueableCommand}; pub use self::error::{ErrorKind, Result}; -#[cfg(windows)] -pub use self::functions::supports_ansi; mod command; mod error; -mod functions; +pub(crate) mod functions; pub(crate) mod macros; pub(crate) mod sys; diff --git a/src/utils/command.rs b/src/utils/command.rs index e90ee2a..392fad9 100644 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::io::Write; -use crate::{execute, impl_display, queue, write_cout}; +use crate::{execute, queue, write_cout}; use super::error::Result; @@ -93,13 +93,13 @@ where } } -/// When executed, this command will output the given string to the terminal. +/// When executed, this command will output the given displayable to the buffer. /// /// See `crossterm/examples/command.rs` for more information on how to execute commands. -pub struct Output(pub String); +pub struct Output(pub T); -impl Command for Output { - type AnsiType = String; +impl Command for Output { + type AnsiType = T; fn ansi_code(&self) -> Self::AnsiType { return self.0.clone(); @@ -112,4 +112,11 @@ impl Command for Output { } } -impl_display!(for Output); +impl Display for Output { + fn fmt( + &self, + f: &mut ::std::fmt::Formatter<'_>, + ) -> ::std::result::Result<(), ::std::fmt::Error> { + write!(f, "{}", self.ansi_code()) + } +} diff --git a/src/utils/macros.rs b/src/utils/macros.rs index 4363d21..b428701 100644 --- a/src/utils/macros.rs +++ b/src/utils/macros.rs @@ -1,10 +1,12 @@ /// Append a the first few characters of an ANSI escape code to the given string. #[macro_export] +#[doc(hidden)] macro_rules! csi { ($( $l:expr ),*) => { concat!("\x1B[", $( $l ),*) }; } /// Write a string to standard output whereafter the stdout will be flushed. +#[doc(hidden)] #[macro_export] macro_rules! write_cout { ($write:expr, $string:expr) => {{ @@ -77,7 +79,7 @@ macro_rules! queue { $( #[cfg(windows)] { - if $crate::utils::supports_ansi() { + if $crate::supports_ansi() { match write!($write, "{}", $command.ansi_code()) { Err(e) => { error = Some(Err($crate::ErrorKind::from(e))); @@ -149,7 +151,7 @@ macro_rules! execute { $( #[cfg(windows)] { - if $crate::utils::supports_ansi() { + if $crate::supports_ansi() { if let Err(e) = write_cout!($write, $command.ansi_code()) { error = Some($crate::ErrorKind::from(e)); }; @@ -175,6 +177,7 @@ macro_rules! execute { }} } +#[doc(hidden)] #[macro_export] macro_rules! impl_display { (for $($t:ty),+) => { @@ -187,6 +190,7 @@ macro_rules! impl_display { } } +#[doc(hidden)] #[macro_export] macro_rules! impl_from { ($from:path, $to:expr) => {