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());
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[cfg(unix)]
|
||||
pub fn print_supported_colors() {
|
||||
|
@ -71,7 +71,8 @@ where
|
||||
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)]
|
||||
pub enum Attribute {
|
||||
Bold = 1,
|
||||
@ -85,6 +86,18 @@ pub enum Attribute {
|
||||
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.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum Color {
|
||||
|
@ -4,7 +4,6 @@ use super::{Color, StyledObject};
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
#[cfg(unix)]
|
||||
use super::Attribute;
|
||||
|
||||
/// 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 bg_color: Option<Color>,
|
||||
|
||||
#[cfg(unix)]
|
||||
pub attrs: Vec<Attribute>,
|
||||
}
|
||||
|
||||
@ -22,7 +20,6 @@ impl Default for ObjectStyle {
|
||||
ObjectStyle {
|
||||
fg_color: Some(Color::White),
|
||||
bg_color: Some(Color::Black),
|
||||
#[cfg(unix)]
|
||||
attrs: Vec::new(),
|
||||
}
|
||||
}
|
||||
@ -42,7 +39,6 @@ impl ObjectStyle {
|
||||
ObjectStyle {
|
||||
fg_color: None,
|
||||
bg_color: None,
|
||||
#[cfg(unix)]
|
||||
attrs: Vec::new(),
|
||||
}
|
||||
}
|
||||
@ -59,7 +55,6 @@ impl ObjectStyle {
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
/// Add an `Attribute` to the current text. Like italic or bold.
|
||||
pub fn add_attr(&mut self, attr: Attribute) {
|
||||
self.attrs.push(attr);
|
||||
|
@ -6,7 +6,6 @@ use Screen;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io::Write;
|
||||
|
||||
#[cfg(unix)]
|
||||
use super::Attribute;
|
||||
|
||||
/// 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);
|
||||
/// ```
|
||||
#[cfg(unix)]
|
||||
pub fn attr(mut self, attr: Attribute) -> StyledObject<D> {
|
||||
self.object_style.add_attr(attr);
|
||||
self
|
||||
}
|
||||
|
||||
/// Increase the font intensity.
|
||||
#[cfg(unix)]
|
||||
#[inline(always)]
|
||||
pub fn bold(self) -> StyledObject<D> {
|
||||
self.attr(Attribute::Bold)
|
||||
@ -97,11 +94,16 @@ impl<'a, D: Display + 'a> StyledObject<D> {
|
||||
self.attr(Attribute::Italic)
|
||||
}
|
||||
/// Underline font.
|
||||
#[cfg(unix)]
|
||||
#[inline(always)]
|
||||
pub fn underlined(self) -> StyledObject<D> {
|
||||
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).
|
||||
#[cfg(unix)]
|
||||
#[inline(always)]
|
||||
@ -158,7 +160,6 @@ impl<'a, D: Display + 'a> StyledObject<D> {
|
||||
reset = true;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
for attr in self.object_style.attrs.iter() {
|
||||
screen
|
||||
.stdout
|
||||
@ -210,7 +211,6 @@ impl<D: Display> Display for StyledObject<D> {
|
||||
reset = true;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
for attr in self.object_style.attrs.iter() {
|
||||
write!(f, "{}", format!(csi!("{}m"), *attr as i16));
|
||||
reset = true;
|
||||
|
Loading…
Reference in New Issue
Block a user