diff --git a/examples/colors.rs b/examples/colors.rs new file mode 100644 index 0000000..7985421 --- /dev/null +++ b/examples/colors.rs @@ -0,0 +1,30 @@ +extern crate cursive; + +use cursive::Cursive; +use cursive::theme::{ColorStyle, Color}; +use cursive::view::Boxable; +use cursive::views::Canvas; + +fn main() { + let mut siv = Cursive::new(); + + siv.add_layer(Canvas::new(()) + .with_draw(|printer, _| for x in 0..20 { + for y in 0..10 { + printer.with_color(ColorStyle::Custom { + front: Color::Rgb(x * 12, + y * 25, + (x + 2 * y) * 6), + back: Color::Rgb(255 - x * 12, + 255 - y * 25, + 128 + (40 - x - 2 * y) * 3), + }, + |printer| { printer.print((x, y), "+"); }); + } + }) + .fixed_size((20, 10))); + + siv.add_global_callback('q', |s| s.quit()); + + siv.run(); +} diff --git a/src/backend/blt.rs b/src/backend/blt.rs index 7f56a21..a097d88 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -55,6 +55,7 @@ impl backend::Backend for Concrete { } fn clear(&self, color: Color) { + terminal::set_background(colour_to_blt_colour(color)); terminal::clear(None); } @@ -134,11 +135,11 @@ fn blt_keycode_to_ev(kc: KeyCode, shift: bool, ctrl: bool) -> Event { KeyCode::F1 | KeyCode::F2 | KeyCode::F3 | KeyCode::F4 | KeyCode::F5 | KeyCode::F6 | KeyCode::F7 | KeyCode::F8 | KeyCode::F9 | KeyCode::F10 | KeyCode::F11 | KeyCode::F12 | - KeyCode::NumEnter | KeyCode::Enter | KeyCode::Escape | KeyCode::Backspace | - KeyCode::Tab | KeyCode::Pause | KeyCode::Insert | KeyCode::Home | - KeyCode::PageUp | KeyCode::Delete | KeyCode::End | - KeyCode::PageDown | KeyCode::Right | KeyCode::Left | - KeyCode::Down | KeyCode::Up => { + KeyCode::NumEnter | KeyCode::Enter | KeyCode::Escape | + KeyCode::Backspace | KeyCode::Tab | KeyCode::Pause | + KeyCode::Insert | KeyCode::Home | KeyCode::PageUp | + KeyCode::Delete | KeyCode::End | KeyCode::PageDown | + KeyCode::Right | KeyCode::Left | KeyCode::Down | KeyCode::Up => { match (shift, ctrl) { (true, true) => Event::CtrlShift(blt_keycode_to_key(kc)), (true, false) => Event::Shift(blt_keycode_to_key(kc)), @@ -162,10 +163,9 @@ fn blt_keycode_to_ev(kc: KeyCode, shift: bool, ctrl: bool) -> Event { KeyCode::Apostrophe | KeyCode::Comma | KeyCode::Period | KeyCode::Slash | KeyCode::Space | KeyCode::NumDivide | KeyCode::NumMultiply | KeyCode::NumMinus | KeyCode::NumPlus | - KeyCode::NumPeriod | KeyCode::Num1 | - KeyCode::Num2 | KeyCode::Num3 | KeyCode::Num4 | KeyCode::Num5 | - KeyCode::Num6 | KeyCode::Num7 | KeyCode::Num8 | KeyCode::Num9 | - KeyCode::Num0 => { + KeyCode::NumPeriod | KeyCode::Num1 | KeyCode::Num2 | + KeyCode::Num3 | KeyCode::Num4 | KeyCode::Num5 | KeyCode::Num6 | + KeyCode::Num7 | KeyCode::Num8 | KeyCode::Num9 | KeyCode::Num0 => { if ctrl { Event::CtrlChar(blt_keycode_to_char(kc, shift)) } else { @@ -240,7 +240,10 @@ fn blt_keycode_to_char(kc: KeyCode, shift: bool) -> char { KeyCode::Num8 => '8', KeyCode::Num9 => '9', KeyCode::Num0 => '0', - _ => { println_stderr!("{:?}", kc); unreachable!() }, + _ => { + println_stderr!("{:?}", kc); + unreachable!() + } } } diff --git a/src/vec.rs b/src/vec.rs index 4a8c316..83aa383 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -114,6 +114,11 @@ impl From<(u32, u32)> for XY { } } +impl From<(u8, u8)> for XY { + fn from((x, y): (u8, u8)) -> Self { + (x as usize, y as usize).into() + } +} impl, O: Into>> Add for XY { type Output = Self;