1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 19:58:15 +03:00

use fancier colors in the widget example

This commit is contained in:
Wez Furlong 2018-07-28 13:21:56 -07:00
parent ed4810b2af
commit 3c8adfaf16
2 changed files with 21 additions and 3 deletions

View File

@ -6,7 +6,8 @@ extern crate termwiz;
use failure::Error;
use std::cell::Cell;
use termwiz::caps::Capabilities;
use termwiz::color::AnsiColor;
use termwiz::cell::AttributeChange;
use termwiz::color::{AnsiColor, ColorAttribute, RgbColor};
use termwiz::input::*;
use termwiz::surface::{Change, Surface};
use termwiz::terminal::buffered::BufferedTerminal;
@ -42,9 +43,20 @@ impl WidgetImpl for MainScreen {
}
fn render_to_surface(&self, surface: &mut Surface) {
surface.add_change(Change::ClearScreen(AnsiColor::Blue.into()));
surface.add_change(Change::ClearScreen(
ColorAttribute::TrueColorWithPaletteFallback(
RgbColor::new(0x31, 0x1B, 0x92),
AnsiColor::Black.into(),
),
));
surface.add_change(Change::Attribute(AttributeChange::Foreground(
ColorAttribute::TrueColorWithPaletteFallback(
RgbColor::new(0xB3, 0x88, 0xFF),
AnsiColor::Purple.into(),
),
)));
let dims = surface.dimensions();
surface.add_change(format!("surface size is {:?}\r\n", dims));
surface.add_change(format!("🤷 surface size is {:?}\r\n", dims));
surface.add_change(self.buf.clone());
// Allow the surface rendering code to figure out where the
// cursor ends up, then stash a copy of that information for

View File

@ -44,6 +44,12 @@ pub enum AnsiColor {
White,
}
impl From<AnsiColor> for u8 {
fn from(col: AnsiColor) -> u8 {
col as u8
}
}
/// Describes a color in the SRGB colorspace using red, green and blue
/// components in the range 0-255.
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash)]