Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl TextModeColor {

/// Sets the foreground color given the specified `foreground`.
pub fn set_foreground(&mut self, foreground: Color16) {
self.0 = foreground as u8;
self.0 = (foreground as u8) | (self.0 & 0xF0);
}
}

Expand Down Expand Up @@ -133,6 +133,14 @@ mod test {
assert_eq!(color.0 & 0x0F, Color16::Red as u8);
}

#[test]
fn test_set_foreground_keep_background() {
let mut color = TextModeColor::new(Color16::Yellow, Color16::White);
color.set_foreground(Color16::Red);
assert_eq!(color.0 & 0x0F, Color16::Red as u8);
assert_eq!(color.0 >> 4, Color16::White as u8); // Background unaffected
}

#[test]
fn test_set_background() {
let mut color = TextModeColor::new(Color16::Yellow, Color16::Black);
Expand Down