-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm.c
54 lines (49 loc) · 1.28 KB
/
term.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
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "colors.h"
#include "utils.h"
#define TERM_BUFFER 5
int term_line_index = 0;
char term_lines[TERM_BUFFER][50] = {0};
static int last_line_hightlight = 2 * 1e6;
static int hightlighting = 0;
void add_term_line(const char *format, ...)
{
if (term_line_index == TERM_BUFFER - 1)
{
for (int i = 0; i < TERM_BUFFER - 1; i++)
{
strcpy(term_lines[i], term_lines[i + 1]);
}
term_line_index -= 1;
}
va_list va;
va_start(va, format);
vsnprintf(term_lines[term_line_index++], 50, format, va);
va_end(va);
}
int is_last(int i)
{
return (i == TERM_BUFFER - 1 || !*term_lines[i + 1]);
}
void render_term(WINDOW *win, int delta_us)
{
for (int i = 0; i < TERM_BUFFER && *term_lines[i]; i++)
{
if (is_last(i) && i != hightlighting)
{
last_line_hightlight = 2 * 1e6;
hightlighting = i;
}
if (is_last(i) && last_line_hightlight)
{
timer_update(&last_line_hightlight, delta_us);
wattrset(win, COLOR_PAIR(Culur_Default_Green));
}
else
wattrset(win, COLOR_PAIR(Culur_Default));
mvwprintw(win, i, 0, "%s", term_lines[i]);
}
}