summaryrefslogtreecommitdiff
path: root/terminal/terminal.h
blob: 06b8f5a89dbb1e99143acca51655c1b70b7d0a78 (plain)
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
#ifndef TERMINAL_H
#define TERMINAL_H

#include <stdint.h>
#include <stdbool.h>


// 
// Terminal emulator implementing (a subset) of console codes of the
// linux console (see man 4 console_codes)
//
//  1. pass a term_out and term_in struct to terminal_init(..).
//  2. use the terminal_kb function for terminal/user input (eg. keyboard).
//  3. use the terminal_put function for input from the host/programms.
//
//	    
//
//			    _____________
//	terminal_put()----> |		| ----> (term_out_struct)
//			    | TERMINAL  |
//	(term_in_struct)<---|___________| <---- terminal_kb()
//
//
// OTHER REQUIREMENTS
//
// Your also need to provide some memory allocation 
//
// * uint32_t kballoc(uint32_t bloks); // block wise in-kernel allocation
//

typedef struct term_out_struct
{

    void (*put_char)(uint8_t c,uint8_t color_fg, uint8_t color_bg, uint32_t x, uint32_t y);
    void (*update_cursor)(uint32_t col,uint32_t row);

}term_out;

typedef struct term_in_struct
{

    void (*put_char)(uint8_t c);

}term_in;

typedef struct terminal_tty_struct
{
    uint8_t fg;
    uint8_t bg;

    bool set_buff;
    bool set_lfnl;
    bool set_echo;

    uint32_t width;
    uint32_t height;
    uint32_t x;
    uint32_t y;
    uint32_t *data; // screen data
    uint8_t *command; // command line / also holds npar for escape sequences somewhere
    int32_t command_l; // command line length

    uint8_t escaping; // escaping mode?
    uint8_t npar; // npar pos 

    term_out *screen;
    term_in *input;

    bool reverse_video;

}terminal_tty;

terminal_tty terminal_init(term_out *screen,term_in *input);
bool terminal_put(terminal_tty *tty, uint8_t c);
void terminal_kb(terminal_tty *tty, uint8_t c);


#endif