-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(cli): add some colors
Showing
9 changed files
with
261 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use console::{Style, StyledObject}; | ||
|
||
pub struct Colors { | ||
version_text: Style, | ||
warning_text: Style, | ||
success_text: Style, | ||
info_text: Style, | ||
label: Style, | ||
} | ||
|
||
impl Default for Colors { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl Colors { | ||
pub fn new() -> Self { | ||
Self { | ||
version_text: Style::new().cyan(), | ||
warning_text: Style::new().yellow(), | ||
success_text: Style::new().green(), | ||
info_text: Style::new().blue(), | ||
label: Style::new().magenta(), | ||
} | ||
} | ||
|
||
pub fn version_text<D>(&self, val: D) -> StyledObject<D> { | ||
self.version_text.apply_to(val) | ||
} | ||
|
||
pub fn warning_text<D>(&self, val: D) -> StyledObject<D> { | ||
self.warning_text.apply_to(val) | ||
} | ||
|
||
pub fn success_text<D>(&self, val: D) -> StyledObject<D> { | ||
self.success_text.apply_to(val) | ||
} | ||
|
||
pub fn info_text<D>(&self, val: D) -> StyledObject<D> { | ||
self.info_text.apply_to(val) | ||
} | ||
|
||
pub fn label<D>(&self, val: D) -> StyledObject<D> { | ||
self.label.apply_to(val) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::sync::Arc; | ||
|
||
use console::StyledObject; | ||
use once_cell::sync::Lazy; | ||
|
||
use crate::colors::Colors; | ||
|
||
#[derive(Default)] | ||
pub struct Context { | ||
pub colors: Colors, | ||
} | ||
|
||
static STATIC_INSTANCE: Lazy<arc_swap::ArcSwap<Context>> = | ||
Lazy::new(|| arc_swap::ArcSwap::from_pointee(Context::default())); | ||
|
||
pub fn instance() -> Arc<Context> { | ||
STATIC_INSTANCE.load().clone() | ||
} | ||
|
||
impl Context { | ||
pub fn aikup_label(&self) -> StyledObject<&str> { | ||
self.colors.label("aikup:") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod cli; | ||
mod cmd; | ||
mod colors; | ||
mod ctx; | ||
mod utils; | ||
|
||
pub use cli::Cli; | ||
|