1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
/// Test function for soon updates
use std::io::stdout;
use crossterm::{
    execute,
    cursor::{SavePosition, RestorePosition, MoveTo},
    style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}
};

/// Print char on current position 
pub fn printch(x: u16, y: u16, msg: &char) -> std::io::Result<()> {

    execute!(
        stdout(),

        SavePosition,
        MoveTo(x, y),
        Print(msg),
        RestorePosition,
    )?;

    Ok(())
}

pub fn printmsg(x: u16, y: u16, msg: &str) -> std::io::Result<()> {

    execute!(
        stdout(),

        SavePosition,
        MoveTo(x, y),
        Print(msg),
        RestorePosition
        )?;

        Ok(())
}

/// Print "Powered by CastleCore"
pub fn print_hello() -> std::io::Result<()> { 

    set_color(Color::Black, Color::Red)?;
    Print(" Powered by ");

    set_color(Color::Red, Color::Black)?;
    Print(" CastleCore ");

    reset_color()?;

    Ok(())
}

/// Print movable "Powered by CastleCore"
pub fn mv_print_hello(x: u16, y: u16) -> std::io::Result<()> { 

    set_color(Color::Black, Color::White)?;
    printmsg(x, y, " Powered by ")?;

    set_color(Color::White, Color::Black)?;
    printmsg(x + 12, y, " CastleCore ")?;

    reset_color()?;

    Ok(())
}

/// Set Foreground and Background color
pub fn set_color(fg_color: Color, bg_color: Color) -> std::io::Result<()> {

    execute!(
        stdout(),
        SetForegroundColor(fg_color),
        SetBackgroundColor(bg_color))?; 

    Ok(())
}

/// Reset colors
pub fn reset_color() -> std::io::Result<()> {

    execute!(
        stdout(),
        ResetColor)?;

    Ok(())
}