-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.c
42 lines (29 loc) · 827 Bytes
/
console.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
#include <stdio.h>
#include "console.h"
#define BUFSIZE 30
int resize_console(int height, int width) {
int cx;
char cmd[BUFSIZE] = {0};
/* Resize console window */
cx = snprintf(cmd, BUFSIZE, "mode con cols=%d lines=%d", width, height);
if (cx < 0 || cx >= BUFSIZE) {
perror("Argument too long");
return 1;
}
system(cmd);
return 0;
}
void hide_cursor() {
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(hStdout, &info);
}
int set_pos(int x, int y) {
csbiInfo.dwCursorPosition.X = (SHORT) x;
csbiInfo.dwCursorPosition.Y = (SHORT) y;
return !SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
}
int set_textcolor(int color) {
return !SetConsoleTextAttribute(hStdout, (WORD) color);
}