castlecore/
functions.rs

1/// Test function for soon updates
2use std::io::stdout;
3use crossterm::{
4    execute,
5    cursor::{SavePosition, RestorePosition, MoveTo},
6    style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}
7};
8
9/// Print char at current position 
10pub fn printch(x: u16, y: u16, symbol: &char) {
11
12    let _ = execute!(
13        stdout(),
14
15        SavePosition,
16        MoveTo(x, y),
17        Print(symbol),
18        RestorePosition,
19    );
20}
21
22/// Print text at current position
23pub fn printmsg(x: u16, y: u16, msg: &str) {
24
25    let _ = execute!(
26        stdout(),
27
28        SavePosition,
29        MoveTo(x, y),
30        Print(msg),
31        RestorePosition
32        );
33}
34
35/// Print "Powered by CastleCore"
36pub fn print_hello() { 
37
38    set_color(Color::Black, Color::Red);
39    Print(" Powered by ");
40
41    set_color(Color::Red, Color::Black);
42    Print(" CastleCore ");
43
44    reset_color();
45}
46
47/// Print movable "Powered by CastleCore"
48pub fn mv_print_hello(x: u16, y: u16) { 
49
50    set_color(Color::Black, Color::White);
51    printmsg(x, y, " Powered by ");
52
53    set_color(Color::White, Color::Black);
54    printmsg(x + 12, y, " CastleCore ");
55
56    reset_color();
57}
58
59/// Set Foreground and Background color
60pub fn set_color(fg_color: Color, bg_color: Color) {
61
62    let _ = execute!(   // Need to rewrite " let _ = "
63        stdout(),
64        SetForegroundColor(fg_color),
65        SetBackgroundColor(bg_color)); 
66}
67
68/// Reset colors
69pub fn reset_color() {
70
71    let _ = execute!(   // Need to rewrite " let _ = "
72        stdout(),
73        ResetColor);
74}