pub enum Modifier {
Coded(u8),
Colour(Colour),
None,
}Expand description
Variants§
Coded(u8)
Coded(u8) unwraps to \x1b[{x}m, where x is the code.
For example, Coded(0) (available as Modifier::END) clears all previously applied modifiers. When displayed, Modifier::Coded(31) writes \x1b[31m.
See https://prirai.github.io/blogs/ansi-esc/#colors-graphics-mode for a guide to available code
Colour(Colour)
Colour(Colour) unwraps to \x1b[38;2;{r};{g};{b}m, where (r, g, b) together represent a 24 bit RGB value
Not all terminals support RGB ANSI escape codes, in which case you will have to resort to Modifier::Coded for colours. Some Coded colours are available as constants, e.g. Modifier::RED
None
None unwraps to nothing. It does not change the current applied modifiers.
Implementations§
Source§impl Modifier
impl Modifier
Sourcepub const END: Self
pub const END: Self
An END code, which clears all previously applied modifiers. You should never have to use this yourself as View makes use of it between pixels where necessary
Sourcepub const fn from_rgb(r: u8, g: u8, b: u8) -> Self
pub const fn from_rgb(r: u8, g: u8, b: u8) -> Self
Create a Modifier::Colour from an RGB value
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
let mut pixel = Pixel::new(Vec2D::new(5, 9), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut draw_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
pixel.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the pixel position being printed would continue to increase without looping
pixel.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.wrapping_mode = WrappingMode::Panic;
view.draw(&pixel);
view.draw(&line);
view.draw(&rect);
view.wrapping_mode = WrappingMode::Wrap;
view.draw(&sprite);
draw_elapsed = now.elapsed();
let now = Instant::now();
let _ = view.display_render();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Drawing: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
draw_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Pixel position: {}", pixel.pos);
}
);
}