From 43aa1c222e96e621a9a02656498ee39f21ead82b Mon Sep 17 00:00:00 2001 From: Zrzka Date: Fri, 13 Sep 2019 23:27:19 +0200 Subject: [PATCH] namespace reformat and 2018 style (#208) --- crossterm_style/examples/style.rs | 11 ++--------- crossterm_style/src/ansi_color.rs | 8 ++++---- crossterm_style/src/color.rs | 4 ++-- crossterm_style/src/enums/attribute.rs | 1 + crossterm_style/src/enums/colored.rs | 5 +++-- crossterm_style/src/enums/mod.rs | 4 ++-- crossterm_style/src/lib.rs | 11 +++-------- crossterm_style/src/objectstyle.rs | 4 +--- crossterm_style/src/styledobject.rs | 7 +++++-- crossterm_style/src/traits.rs | 3 ++- crossterm_style/src/winapi_color.rs | 8 +++++--- 11 files changed, 30 insertions(+), 36 deletions(-) diff --git a/crossterm_style/examples/style.rs b/crossterm_style/examples/style.rs index 127e095..bdd5fa4 100644 --- a/crossterm_style/examples/style.rs +++ b/crossterm_style/examples/style.rs @@ -1,12 +1,7 @@ //! //! Examples of coloring the terminal. //! -#[macro_use] -extern crate crossterm_style; - -use self::crossterm_style::{ - color, style, Attribute, Color, Colored, Colorize, Styler, TerminalColor, -}; +use crossterm_style::{color, Attribute, Color, Colored, Colorize, Styler}; /// print some red text | demonstration. pub fn paint_foreground() { @@ -393,6 +388,4 @@ pub fn reset_fg_and_bg() { println!("{}", Colored::Bg(Color::Reset)); } -fn main() { - command() -} +fn main() {} diff --git a/crossterm_style/src/ansi_color.rs b/crossterm_style/src/ansi_color.rs index 132c435..58bd3b1 100644 --- a/crossterm_style/src/ansi_color.rs +++ b/crossterm_style/src/ansi_color.rs @@ -1,12 +1,12 @@ //! This is a ANSI specific implementation for styling related action. //! This module is used for Windows 10 terminals and Unix terminals by default. -use crate::{Attribute, Color, ITerminalColor}; -use crossterm_utils::{write_cout, Result}; - -use crate::Colored; use std::io::Write; +use crossterm_utils::{csi, write_cout, Result}; + +use crate::{Attribute, Color, Colored, ITerminalColor}; + #[inline] pub fn get_set_fg_ansi(fg_color: Color) -> String { format!(csi!("{}m"), color_value(Colored::Fg(fg_color)),) diff --git a/crossterm_style/src/color.rs b/crossterm_style/src/color.rs index 1910ee8..2a7e857 100644 --- a/crossterm_style/src/color.rs +++ b/crossterm_style/src/color.rs @@ -1,15 +1,15 @@ //! A module that contains all the actions related to the styling of the terminal. //! Like applying attributes to text and changing the foreground and background. +use std::clone::Clone; use std::io; use super::*; use crate::{Color, ITerminalColor}; -use crossterm_utils::{impl_display, Command, Result}; -use std::clone::Clone; #[cfg(windows)] use crossterm_utils::supports_ansi; +use crossterm_utils::{impl_display, Command, Result}; /// Allows you to style the terminal. /// diff --git a/crossterm_style/src/enums/attribute.rs b/crossterm_style/src/enums/attribute.rs index 2c56df3..5993d6a 100644 --- a/crossterm_style/src/enums/attribute.rs +++ b/crossterm_style/src/enums/attribute.rs @@ -1,5 +1,6 @@ use std::fmt::Display; +use crossterm_utils::csi; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/crossterm_style/src/enums/colored.rs b/crossterm_style/src/enums/colored.rs index 995ffdd..aa5bfc9 100644 --- a/crossterm_style/src/enums/colored.rs +++ b/crossterm_style/src/enums/colored.rs @@ -1,10 +1,11 @@ -use crate::color::color; -use crate::enums::Color; use std::fmt::Display; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::color::color; +use crate::enums::Color; + /// Could be used to color the foreground or background color. /// /// `Colored::Fg` represents the foreground color. diff --git a/crossterm_style/src/enums/mod.rs b/crossterm_style/src/enums/mod.rs index 683c76c..e790c64 100644 --- a/crossterm_style/src/enums/mod.rs +++ b/crossterm_style/src/enums/mod.rs @@ -1,5 +1,5 @@ +pub use self::{attribute::Attribute, color::Color, colored::Colored}; + mod attribute; mod color; mod colored; - -pub use self::{attribute::Attribute, color::Color, colored::Colored}; diff --git a/crossterm_style/src/lib.rs b/crossterm_style/src/lib.rs index 908547d..ea20bb4 100644 --- a/crossterm_style/src/lib.rs +++ b/crossterm_style/src/lib.rs @@ -1,11 +1,6 @@ //! A module that contains all the actions related to the styling of the terminal. //! Like applying attributes to text and changing the foreground and background. -#[macro_use] -extern crate crossterm_utils; -#[cfg(windows)] -extern crate crossterm_winapi; - #[macro_use] mod macros; mod color; @@ -18,18 +13,18 @@ mod ansi_color; #[cfg(windows)] mod winapi_color; +use std::fmt::Display; + use self::ansi_color::AnsiColor; #[cfg(windows)] use self::winapi_color::WinApiColor; - -use std::fmt::Display; +pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; pub use self::color::{color, PrintStyledFont, SetAttr, SetBg, SetFg, TerminalColor}; pub use self::enums::{Attribute, Color, Colored}; pub use self::objectstyle::ObjectStyle; pub use self::styledobject::StyledObject; pub use self::traits::{Colorize, Styler}; -pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; /// This trait defines the actions that can be performed with terminal colors. /// This trait can be implemented so that a concrete implementation of the ITerminalColor can fulfill diff --git a/crossterm_style/src/objectstyle.rs b/crossterm_style/src/objectstyle.rs index 29acb91..2ff0851 100644 --- a/crossterm_style/src/objectstyle.rs +++ b/crossterm_style/src/objectstyle.rs @@ -1,10 +1,8 @@ //! This module contains the `object style` that can be applied to an `styled object`. -use super::{Color, StyledObject}; - use std::fmt::Display; -use super::Attribute; +use super::{Attribute, Color, StyledObject}; /// Struct that contains the style properties that can be applied to a displayable object. #[derive(Debug, Clone)] diff --git a/crossterm_style/src/styledobject.rs b/crossterm_style/src/styledobject.rs index a851f7b..0f70c31 100644 --- a/crossterm_style/src/styledobject.rs +++ b/crossterm_style/src/styledobject.rs @@ -1,12 +1,15 @@ //! This module contains the logic to style an object that contains some 'content' which can be styled. -use super::{color, Color, ObjectStyle, SetBg, SetFg}; use std::fmt::{self, Display, Formatter}; use std::result; -use super::Attribute; +use crossterm_utils::{csi, queue}; + use crate::{Colorize, Styler}; +use super::Attribute; +use super::{color, Color, ObjectStyle, SetBg, SetFg}; + /// Contains both the style and the content which can be styled. #[derive(Clone)] pub struct StyledObject { diff --git a/crossterm_style/src/traits.rs b/crossterm_style/src/traits.rs index 28f0604..f5c6a4e 100644 --- a/crossterm_style/src/traits.rs +++ b/crossterm_style/src/traits.rs @@ -1,6 +1,7 @@ -use crate::StyledObject; use std::fmt::Display; +use crate::StyledObject; + /// Provides a set of methods to color any type implementing `Display` with attributes. /// /// This trait is implemented for `&static str` and `StyledObject` and thus the methods of this trait could be called on them. diff --git a/crossterm_style/src/winapi_color.rs b/crossterm_style/src/winapi_color.rs index eb742be..181393e 100644 --- a/crossterm_style/src/winapi_color.rs +++ b/crossterm_style/src/winapi_color.rs @@ -1,13 +1,15 @@ //! This is a `WinApi` specific implementation for styling related action. //! This module is used for non supporting `ANSI` Windows terminals. -use crate::{Color, Colored, ITerminalColor}; -use crossterm_utils::Result; -use crossterm_winapi::{Console, Handle, HandleType, ScreenBuffer}; use std::io; use std::sync::{Once, ONCE_INIT}; + +use crossterm_utils::Result; +use crossterm_winapi::{Console, Handle, HandleType, ScreenBuffer}; use winapi::um::wincon; +use crate::{Color, Colored, ITerminalColor}; + const FG_GREEN: u16 = wincon::FOREGROUND_GREEN; const FG_RED: u16 = wincon::FOREGROUND_RED; const FG_BLUE: u16 = wincon::FOREGROUND_BLUE;