Implement support attributes support for the windows terminal. (#62)
This commit is contained in:
parent
ddcda09602
commit
14bd60af78
@ -207,6 +207,15 @@ pub fn print_font_with_attributes() {
|
|||||||
println!("{}", style("Crossed out font").crossed_out());
|
println!("{}", style("Crossed out font").crossed_out());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn print_font_with_attributes() {
|
||||||
|
println!("{}", style("Normal text"));
|
||||||
|
println!("{}", style("Bold text").bold());
|
||||||
|
println!("{}", style("Underlined text").underlined());
|
||||||
|
println!("{}", style("Negative text").negative());
|
||||||
|
}
|
||||||
|
|
||||||
/// Print all supported RGB colors | demonstration.
|
/// Print all supported RGB colors | demonstration.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn print_supported_colors() {
|
pub fn print_supported_colors() {
|
||||||
|
@ -71,7 +71,8 @@ where
|
|||||||
ObjectStyle::new().apply_to(val)
|
ObjectStyle::new().apply_to(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attributes that could be applied on some text.
|
/// Attributes that could be applied on some text. (*nix values)
|
||||||
|
#[cfg(unix)]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
||||||
pub enum Attribute {
|
pub enum Attribute {
|
||||||
Bold = 1,
|
Bold = 1,
|
||||||
@ -85,6 +86,18 @@ pub enum Attribute {
|
|||||||
CrossedOut = 9,
|
CrossedOut = 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attributes that could be applied on some text. (Windows specific)
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
|
||||||
|
pub enum Attribute {
|
||||||
|
Reset = 0,
|
||||||
|
Bold = 1,
|
||||||
|
Underlined = 4,
|
||||||
|
NoUnderline = 24,
|
||||||
|
Negative = 7,
|
||||||
|
Positive = 27,
|
||||||
|
}
|
||||||
|
|
||||||
/// Colors that are available for coloring the terminal font.
|
/// Colors that are available for coloring the terminal font.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
|
@ -4,7 +4,6 @@ use super::{Color, StyledObject};
|
|||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
use super::Attribute;
|
use super::Attribute;
|
||||||
|
|
||||||
/// Struct that contains the style properties that can be applied to an displayable object.
|
/// Struct that contains the style properties that can be applied to an displayable object.
|
||||||
@ -13,7 +12,6 @@ pub struct ObjectStyle {
|
|||||||
pub fg_color: Option<Color>,
|
pub fg_color: Option<Color>,
|
||||||
pub bg_color: Option<Color>,
|
pub bg_color: Option<Color>,
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
pub attrs: Vec<Attribute>,
|
pub attrs: Vec<Attribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +20,6 @@ impl Default for ObjectStyle {
|
|||||||
ObjectStyle {
|
ObjectStyle {
|
||||||
fg_color: Some(Color::White),
|
fg_color: Some(Color::White),
|
||||||
bg_color: Some(Color::Black),
|
bg_color: Some(Color::Black),
|
||||||
#[cfg(unix)]
|
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,7 +39,6 @@ impl ObjectStyle {
|
|||||||
ObjectStyle {
|
ObjectStyle {
|
||||||
fg_color: None,
|
fg_color: None,
|
||||||
bg_color: None,
|
bg_color: None,
|
||||||
#[cfg(unix)]
|
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +55,6 @@ impl ObjectStyle {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
/// Add an `Attribute` to the current text. Like italic or bold.
|
/// Add an `Attribute` to the current text. Like italic or bold.
|
||||||
pub fn add_attr(&mut self, attr: Attribute) {
|
pub fn add_attr(&mut self, attr: Attribute) {
|
||||||
self.attrs.push(attr);
|
self.attrs.push(attr);
|
||||||
|
@ -6,7 +6,6 @@ use Screen;
|
|||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
use super::Attribute;
|
use super::Attribute;
|
||||||
|
|
||||||
/// Struct that contains both the style and the content wits can be styled.
|
/// Struct that contains both the style and the content wits can be styled.
|
||||||
@ -72,14 +71,12 @@ impl<'a, D: Display + 'a> StyledObject<D> {
|
|||||||
///
|
///
|
||||||
/// println!("{}", style("Some bold text").attr(Attribute::Bold);
|
/// println!("{}", style("Some bold text").attr(Attribute::Bold);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(unix)]
|
|
||||||
pub fn attr(mut self, attr: Attribute) -> StyledObject<D> {
|
pub fn attr(mut self, attr: Attribute) -> StyledObject<D> {
|
||||||
self.object_style.add_attr(attr);
|
self.object_style.add_attr(attr);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Increase the font intensity.
|
/// Increase the font intensity.
|
||||||
#[cfg(unix)]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn bold(self) -> StyledObject<D> {
|
pub fn bold(self) -> StyledObject<D> {
|
||||||
self.attr(Attribute::Bold)
|
self.attr(Attribute::Bold)
|
||||||
@ -97,11 +94,16 @@ impl<'a, D: Display + 'a> StyledObject<D> {
|
|||||||
self.attr(Attribute::Italic)
|
self.attr(Attribute::Italic)
|
||||||
}
|
}
|
||||||
/// Underline font.
|
/// Underline font.
|
||||||
#[cfg(unix)]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn underlined(self) -> StyledObject<D> {
|
pub fn underlined(self) -> StyledObject<D> {
|
||||||
self.attr(Attribute::Underlined)
|
self.attr(Attribute::Underlined)
|
||||||
}
|
}
|
||||||
|
/// Invert colours.
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn negative(self) -> StyledObject<D> {
|
||||||
|
self.attr(Attribute::Negative)
|
||||||
|
}
|
||||||
/// Slow Blink (less than 150 per minute; not widely supported).
|
/// Slow Blink (less than 150 per minute; not widely supported).
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -158,7 +160,6 @@ impl<'a, D: Display + 'a> StyledObject<D> {
|
|||||||
reset = true;
|
reset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
for attr in self.object_style.attrs.iter() {
|
for attr in self.object_style.attrs.iter() {
|
||||||
screen
|
screen
|
||||||
.stdout
|
.stdout
|
||||||
@ -210,7 +211,6 @@ impl<D: Display> Display for StyledObject<D> {
|
|||||||
reset = true;
|
reset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
for attr in self.object_style.attrs.iter() {
|
for attr in self.object_style.attrs.iter() {
|
||||||
write!(f, "{}", format!(csi!("{}m"), *attr as i16));
|
write!(f, "{}", format!(csi!("{}m"), *attr as i16));
|
||||||
reset = true;
|
reset = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user