namespace reformat and 2018 style (#208)

This commit is contained in:
Zrzka 2019-09-13 23:27:19 +02:00 committed by Timon
parent ea8a367c11
commit 43aa1c222e
11 changed files with 30 additions and 36 deletions

View File

@ -1,12 +1,7 @@
//! //!
//! Examples of coloring the terminal. //! Examples of coloring the terminal.
//! //!
#[macro_use] use crossterm_style::{color, Attribute, Color, Colored, Colorize, Styler};
extern crate crossterm_style;
use self::crossterm_style::{
color, style, Attribute, Color, Colored, Colorize, Styler, TerminalColor,
};
/// print some red text | demonstration. /// print some red text | demonstration.
pub fn paint_foreground() { pub fn paint_foreground() {
@ -393,6 +388,4 @@ pub fn reset_fg_and_bg() {
println!("{}", Colored::Bg(Color::Reset)); println!("{}", Colored::Bg(Color::Reset));
} }
fn main() { fn main() {}
command()
}

View File

@ -1,12 +1,12 @@
//! This is a ANSI specific implementation for styling related action. //! This is a ANSI specific implementation for styling related action.
//! This module is used for Windows 10 terminals and Unix terminals by default. //! 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 std::io::Write;
use crossterm_utils::{csi, write_cout, Result};
use crate::{Attribute, Color, Colored, ITerminalColor};
#[inline] #[inline]
pub fn get_set_fg_ansi(fg_color: Color) -> String { pub fn get_set_fg_ansi(fg_color: Color) -> String {
format!(csi!("{}m"), color_value(Colored::Fg(fg_color)),) format!(csi!("{}m"), color_value(Colored::Fg(fg_color)),)

View File

@ -1,15 +1,15 @@
//! A module that contains all the actions related to the styling of the terminal. //! 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. //! Like applying attributes to text and changing the foreground and background.
use std::clone::Clone;
use std::io; use std::io;
use super::*; use super::*;
use crate::{Color, ITerminalColor}; use crate::{Color, ITerminalColor};
use crossterm_utils::{impl_display, Command, Result};
use std::clone::Clone;
#[cfg(windows)] #[cfg(windows)]
use crossterm_utils::supports_ansi; use crossterm_utils::supports_ansi;
use crossterm_utils::{impl_display, Command, Result};
/// Allows you to style the terminal. /// Allows you to style the terminal.
/// ///

View File

@ -1,5 +1,6 @@
use std::fmt::Display; use std::fmt::Display;
use crossterm_utils::csi;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,10 +1,11 @@
use crate::color::color;
use crate::enums::Color;
use std::fmt::Display; use std::fmt::Display;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::color::color;
use crate::enums::Color;
/// Could be used to color the foreground or background color. /// Could be used to color the foreground or background color.
/// ///
/// `Colored::Fg` represents the foreground color. /// `Colored::Fg` represents the foreground color.

View File

@ -1,5 +1,5 @@
pub use self::{attribute::Attribute, color::Color, colored::Colored};
mod attribute; mod attribute;
mod color; mod color;
mod colored; mod colored;
pub use self::{attribute::Attribute, color::Color, colored::Colored};

View File

@ -1,11 +1,6 @@
//! A module that contains all the actions related to the styling of the terminal. //! 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. //! 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] #[macro_use]
mod macros; mod macros;
mod color; mod color;
@ -18,18 +13,18 @@ mod ansi_color;
#[cfg(windows)] #[cfg(windows)]
mod winapi_color; mod winapi_color;
use std::fmt::Display;
use self::ansi_color::AnsiColor; use self::ansi_color::AnsiColor;
#[cfg(windows)] #[cfg(windows)]
use self::winapi_color::WinApiColor; use self::winapi_color::WinApiColor;
pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result};
use std::fmt::Display;
pub use self::color::{color, PrintStyledFont, SetAttr, SetBg, SetFg, TerminalColor}; pub use self::color::{color, PrintStyledFont, SetAttr, SetBg, SetFg, TerminalColor};
pub use self::enums::{Attribute, Color, Colored}; pub use self::enums::{Attribute, Color, Colored};
pub use self::objectstyle::ObjectStyle; pub use self::objectstyle::ObjectStyle;
pub use self::styledobject::StyledObject; pub use self::styledobject::StyledObject;
pub use self::traits::{Colorize, Styler}; 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 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 /// This trait can be implemented so that a concrete implementation of the ITerminalColor can fulfill

View File

@ -1,10 +1,8 @@
//! This module contains the `object style` that can be applied to an `styled object`. //! This module contains the `object style` that can be applied to an `styled object`.
use super::{Color, StyledObject};
use std::fmt::Display; 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. /// Struct that contains the style properties that can be applied to a displayable object.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -1,12 +1,15 @@
//! This module contains the logic to style an object that contains some 'content' which can be styled. //! 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::fmt::{self, Display, Formatter};
use std::result; use std::result;
use super::Attribute; use crossterm_utils::{csi, queue};
use crate::{Colorize, Styler}; 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. /// Contains both the style and the content which can be styled.
#[derive(Clone)] #[derive(Clone)]
pub struct StyledObject<D: Display + Clone> { pub struct StyledObject<D: Display + Clone> {

View File

@ -1,6 +1,7 @@
use crate::StyledObject;
use std::fmt::Display; use std::fmt::Display;
use crate::StyledObject;
/// Provides a set of methods to color any type implementing `Display` with attributes. /// 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. /// This trait is implemented for `&static str` and `StyledObject` and thus the methods of this trait could be called on them.

View File

@ -1,13 +1,15 @@
//! This is a `WinApi` specific implementation for styling related action. //! This is a `WinApi` specific implementation for styling related action.
//! This module is used for non supporting `ANSI` Windows terminals. //! 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::io;
use std::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT};
use crossterm_utils::Result;
use crossterm_winapi::{Console, Handle, HandleType, ScreenBuffer};
use winapi::um::wincon; use winapi::um::wincon;
use crate::{Color, Colored, ITerminalColor};
const FG_GREEN: u16 = wincon::FOREGROUND_GREEN; const FG_GREEN: u16 = wincon::FOREGROUND_GREEN;
const FG_RED: u16 = wincon::FOREGROUND_RED; const FG_RED: u16 = wincon::FOREGROUND_RED;
const FG_BLUE: u16 = wincon::FOREGROUND_BLUE; const FG_BLUE: u16 = wincon::FOREGROUND_BLUE;