mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 20:23:35 +00:00
Add colors example
This commit is contained in:
parent
88d3d81e88
commit
7a7ccbf45c
30
examples/colors.rs
Normal file
30
examples/colors.rs
Normal file
@ -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();
|
||||
}
|
@ -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!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,11 @@ impl From<(u32, u32)> for XY<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(u8, u8)> for XY<usize> {
|
||||
fn from((x, y): (u8, u8)) -> Self {
|
||||
(x as usize, y as usize).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Add<Output = T>, O: Into<XY<T>>> Add<O> for XY<T> {
|
||||
type Output = Self;
|
||||
|
Loading…
Reference in New Issue
Block a user