Skip to content

Commit

Permalink
Store reference of Shell
Browse files Browse the repository at this point in the history
  • Loading branch information
twe4ked committed May 21, 2020
1 parent a9f31fe commit 40177ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/component/cwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ fn short(
if underline_repo {
format!(
"{}{}{}",
style::Style::Underlined(*shell),
style::Style::Underlined(shell),
part,
style::Style::NoUnderline(*shell),
style::Style::NoUnderline(shell),
)
} else {
part.to_owned()
Expand Down
2 changes: 1 addition & 1 deletion src/component/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use crate::style::Style;
use crate::Shell;

pub fn display(shell: &Shell) -> Option<Component> {
Some(Component::ColorReset(Style::Reset(*shell).to_string()))
Some(Component::ColorReset(Style::Reset(shell).to_string()))
}
20 changes: 10 additions & 10 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use crate::Shell;

use std::fmt;

pub enum Style {
Color(Shell, CrosstermColor),
Reset(Shell),
Underlined(Shell),
NoUnderline(Shell),
pub enum Style<'a> {
Color(&'a Shell, CrosstermColor),
Reset(&'a Shell),
Underlined(&'a Shell),
NoUnderline(&'a Shell),
}

impl Style {
pub fn from_color_token(color: &Color, shell: &Shell) -> Self {
impl<'a> Style<'a> {
pub fn from_color_token(color: &Color, shell: &'a Shell) -> Self {
let color = match color {
Color::Black => CrosstermColor::Black,
Color::DarkGrey => CrosstermColor::DarkGrey,
Expand All @@ -32,11 +32,11 @@ impl Style {
Color::White => CrosstermColor::White,
};

Style::Color(*shell, color)
Style::Color(shell, color)
}
}

impl fmt::Display for Style {
impl fmt::Display for Style<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Style::Color(shell, color) => write(f, *shell, SetForegroundColor(*color)),
Expand All @@ -49,7 +49,7 @@ impl fmt::Display for Style {

// Include a string as a literal escape sequence. The string within the braces should not change
// the cursor position. Brace pairs can nest.
fn write<T>(f: &mut fmt::Formatter<'_>, shell: Shell, style: T) -> fmt::Result
fn write<T>(f: &mut fmt::Formatter<'_>, shell: &Shell, style: T) -> fmt::Result
where
T: fmt::Display,
{
Expand Down

0 comments on commit 40177ce

Please sign in to comment.