-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminalio.c
85 lines (68 loc) · 1.65 KB
/
terminalio.c
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
/*
* terminalio.c
*
* Author: Peter Sutton
*/
#include "terminalio.h"
#include <stdio.h>
#include <stdint.h>
#include <avr/pgmspace.h>
void move_terminal_cursor(int x, int y) {
printf_P(PSTR("\x1b[%d;%dH"), y, x);
}
void normal_display_mode(void) {
printf_P(PSTR("\x1b[0m"));
}
void reverse_video(void) {
printf_P(PSTR("\x1b[7m"));
}
void clear_terminal(void) {
printf_P(PSTR("\x1b[2J"));
}
void clear_to_end_of_line(void) {
printf_P(PSTR("\x1b[K"));
}
void set_display_attribute(DisplayParameter parameter) {
printf_P(PSTR("\x1b[%dm"), parameter);
}
void hide_cursor() {
printf_P(PSTR("\x1b[?25l"));
}
void show_cursor() {
printf_P(PSTR("\x1b[?25h"));
}
void enable_scrolling_for_whole_display(void) {
printf_P(PSTR("\x1b[r"));
}
void set_scroll_region(int8_t y1, int8_t y2) {
printf_P(PSTR("\x1b[%d;%dr"), y1, y2);
}
void scroll_down(void) {
printf_P(PSTR("\x1bM")); // ESC-M
}
void scroll_up(void) {
printf_P(PSTR("\x1b\x44")); // ESC-D
}
void draw_horizontal_line(int8_t y, int8_t start_x, int8_t end_x) {
move_terminal_cursor(start_x, y);
reverse_video();
for (int8_t i = start_x; i <= end_x; i++) {
printf(" "); /* No need to use printf_P - printing
* a single character gets optimised
* to a putchar call
*/
}
normal_display_mode();
}
void draw_vertical_line(int8_t x, int8_t start_y, int8_t end_y) {
move_terminal_cursor(x, start_y);
reverse_video();
for(int8_t i = start_y; i < end_y; i++) {
printf(" ");
/* Move down one and back to the left one */
printf_P(PSTR("\x1b[B\x1b[D"));
}
printf(" ");
normal_display_mode();
}
//////////////////////////////////EXTRA FUNCTIONS/////////////////////////////