Skip to content

Commit

Permalink
Make ColorSpec constructor and getters const
Browse files Browse the repository at this point in the history
  • Loading branch information
Property404 committed Apr 23, 2022
1 parent 677f98b commit ddb4a0c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,13 @@ pub struct ColorSpec {

impl Default for ColorSpec {
fn default() -> ColorSpec {
ColorSpec::new()
}
}

impl ColorSpec {
/// Create a new color specification that has no colors or styles.
pub const fn new() -> ColorSpec {
ColorSpec {
fg_color: None,
bg_color: None,
Expand All @@ -1601,15 +1608,9 @@ impl Default for ColorSpec {
reset: true,
}
}
}

impl ColorSpec {
/// Create a new color specification that has no colors or styles.
pub fn new() -> ColorSpec {
ColorSpec::default()
}

/// Get the foreground color.
// TODO: Make this const when MSVR is 1.48
pub fn fg(&self) -> Option<&Color> {
self.fg_color.as_ref()
}
Expand All @@ -1621,6 +1622,7 @@ impl ColorSpec {
}

/// Get the background color.
// TODO: Make this const when MSVR is 1.48
pub fn bg(&self) -> Option<&Color> {
self.bg_color.as_ref()
}
Expand All @@ -1634,7 +1636,7 @@ impl ColorSpec {
/// Get whether this is bold or not.
///
/// Note that the bold setting has no effect in a Windows console.
pub fn bold(&self) -> bool {
pub const fn bold(&self) -> bool {
self.bold
}

Expand All @@ -1649,7 +1651,7 @@ impl ColorSpec {
/// Get whether this is dimmed or not.
///
/// Note that the dimmed setting has no effect in a Windows console.
pub fn dimmed(&self) -> bool {
pub const fn dimmed(&self) -> bool {
self.dimmed
}

Expand All @@ -1664,7 +1666,7 @@ impl ColorSpec {
/// Get whether this is italic or not.
///
/// Note that the italic setting has no effect in a Windows console.
pub fn italic(&self) -> bool {
pub const fn italic(&self) -> bool {
self.italic
}

Expand All @@ -1679,7 +1681,7 @@ impl ColorSpec {
/// Get whether this is underline or not.
///
/// Note that the underline setting has no effect in a Windows console.
pub fn underline(&self) -> bool {
pub const fn underline(&self) -> bool {
self.underline
}

Expand All @@ -1698,7 +1700,7 @@ impl ColorSpec {
/// settings are applied.
///
/// Note that the reset setting has no effect in a Windows console.
pub fn reset(&self) -> bool {
pub const fn reset(&self) -> bool {
self.reset
}

Expand Down Expand Up @@ -1726,7 +1728,7 @@ impl ColorSpec {
///
/// On Windows systems, this will output the ANSI escape sequence
/// that will print a brighter version of the color specified.
pub fn intense(&self) -> bool {
pub const fn intense(&self) -> bool {
self.intense
}

Expand Down

0 comments on commit ddb4a0c

Please sign in to comment.