Skip to content

Commit

Permalink
refactor: set_color_mode => get_color_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bconn98 committed Jul 10, 2024
1 parent e6f0127 commit cfe8960
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions src/encode/writer/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use once_cell::sync::OnceCell;

static COLOR_MODE: OnceCell<ColorMode> = OnceCell::new();

fn set_color_mode(
fn get_color_mode(
no_color: Result<String, env::VarError>,
clicolor_force: Result<String, env::VarError>,
clicolor: Result<String, env::VarError>,
Expand Down Expand Up @@ -129,7 +129,7 @@ mod imp {
self,
writer::{
ansi::AnsiWriter,
console::{set_color_mode, ColorMode, COLOR_MODE},
console::{get_color_mode, ColorMode, COLOR_MODE},
},
Style,
},
Expand All @@ -145,7 +145,7 @@ mod imp {
let no_color = env::var("NO_COLOR");
let clicolor_force = env::var("CLICOLOR_FORCE");
let clicolor = env::var("CLICOLOR");
set_color_mode(no_color, clicolor_force, clicolor)
get_color_mode(no_color, clicolor_force, clicolor)
};
match COLOR_MODE.get_or_init(|| color_mode_init) {
ColorMode::Auto => {
Expand All @@ -166,7 +166,7 @@ mod imp {
let no_color = env::var("NO_COLOR");
let clicolor_force = env::var("CLICOLOR_FORCE");
let clicolor = env::var("CLICOLOR");
set_color_mode(no_color, clicolor_force, clicolor)
get_color_mode(no_color, clicolor_force, clicolor)
};
match COLOR_MODE.get_or_init(|| color_mode_init) {
ColorMode::Auto => {
Expand Down Expand Up @@ -252,7 +252,7 @@ mod imp {
use crate::{
encode::{
self,
writer::console::{set_color_mode, ColorMode, COLOR_MODE},
writer::console::{get_color_mode, ColorMode, COLOR_MODE},
Color, Style,
},
priv_io::{StdWriter, StdWriterLock},
Expand Down Expand Up @@ -352,7 +352,7 @@ mod imp {
let no_color = env::var("NO_COLOR");
let clicolor_force = env::var("CLICOLOR_FORCE");
let clicolor = env::var("CLICOLOR");
set_color_mode(no_color, clicolor_force, clicolor)
get_color_mode(no_color, clicolor_force, clicolor)
};
match COLOR_MODE.get_or_init(|| color_mode_init) {
ColorMode::Auto | ColorMode::Always => Some(writer),
Expand Down Expand Up @@ -385,7 +385,7 @@ mod imp {
let no_color = env::var("NO_COLOR");
let clicolor_force = env::var("CLICOLOR_FORCE");
let clicolor = env::var("CLICOLOR");
set_color_mode(no_color, clicolor_force, clicolor)
get_color_mode(no_color, clicolor_force, clicolor)
};
match COLOR_MODE.get_or_init(|| color_mode_init) {
ColorMode::Auto | ColorMode::Always => Some(writer),
Expand Down Expand Up @@ -478,12 +478,12 @@ mod test {

w.write(b"normal ").unwrap();
w.set_style(
Style::new()
.text(Color::Red)
.background(Color::Blue)
.intense(true),
)
.unwrap();
Style::new()
.text(Color::Red)
.background(Color::Blue)
.intense(true),
)
.unwrap();
w.write_all(b"styled").unwrap();
w.set_style(&Style::new().text(Color::Green).intense(false))
.unwrap();
Expand All @@ -501,7 +501,7 @@ mod test {

let color_mode: OnceCell<ColorMode> = OnceCell::new();
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Auto
);
}
Expand All @@ -515,7 +515,7 @@ mod test {

let mut color_mode: OnceCell<ColorMode> = OnceCell::new();
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Never
);

Expand All @@ -525,7 +525,7 @@ mod test {

let _ = color_mode.take(); // Clear the owned value
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Never
);
}
Expand All @@ -539,7 +539,7 @@ mod test {

let mut color_mode: OnceCell<ColorMode> = OnceCell::new();
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Always
);

Expand All @@ -552,7 +552,7 @@ mod test {

let _ = color_mode.take(); // Clear the owned value
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Always
);

Expand All @@ -562,7 +562,7 @@ mod test {

let _ = color_mode.take(); // Clear the owned value
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Always
);
}
Expand All @@ -576,7 +576,7 @@ mod test {

let mut color_mode: OnceCell<ColorMode> = OnceCell::new();
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Auto
);

Expand All @@ -586,7 +586,7 @@ mod test {

let _ = color_mode.take(); // Clear the owned value
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Never
);

Expand All @@ -597,7 +597,7 @@ mod test {

let _ = color_mode.take(); // Clear the owned value
assert_eq!(
color_mode.get_or_init(|| set_color_mode(no_color, clicolor_force, clicolor)),
color_mode.get_or_init(|| get_color_mode(no_color, clicolor_force, clicolor)),
&ColorMode::Auto
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
//! For more examples see the [examples](https://github.com/estk/log4rs/tree/main/examples).
//!

#![allow(where_clauses_object_safety, clippy::manual_non_exhaustive)]
#![allow(clippy::manual_non_exhaustive)]
#![warn(missing_docs)]

use std::{
Expand Down

0 comments on commit cfe8960

Please sign in to comment.