-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay-cli.c
95 lines (79 loc) · 2.18 KB
/
display-cli.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
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (C) 2018, Jason Parker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/lamprey.h"
#include "include/controller.h"
#include "include/display.h"
void hl_cli_init(int argc, char **argv) {
printf("CLI Initialized.\n");
}
void hl_cli_output_controller(struct controller *controller) {
char pressed[256] = {0};
struct hl_skin *skinActive = NULL;
if (!controller) {
return;
}
for (int i = 0; i < hl_skin_count; i++) {
if (!strcmp(hl_settings->skin->name, hl_skins[i]->name)) {
skinActive = hl_skins[i];
break;
}
}
if (!skinActive) {
return;
}
for (int i = 0; i < controller->button_count; i++) {
struct button_state *button = controller->buttons[i];
if (button->value) {
for (int j = 0; j < skinActive->button_count; j++) {
if (!strstr(pressed, skinActive->buttons[j]->cli_char)) {
strcat(pressed, skinActive->buttons[j]->cli_char);
}
}
for (int j = 0; j < skinActive->axis_count; j++) {
if (!strstr(pressed, skinActive->axes[j]->cli_char)) {
strcat(pressed, skinActive->axes[j]->cli_char);
}
}
}
}
printf("\n");
for (int i = 0; i < sizeof(skinActive->cli_layout); i++) {
char layout_char[5];
char *ptr = layout_char;
*ptr = skinActive->cli_layout[i];
/* Deal with UTF-8 characters. */
while ((skinActive->cli_layout[i + 1] & 0xC0) == 0x80) {
*++ptr = skinActive->cli_layout[++i];
}
*++ptr = '\0';
if (strlen(layout_char) == 0) {
break;
}
if (strstr(pressed, layout_char)) {
#if defined(_WIN32)
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO console;
WORD attr;
GetConsoleScreenBufferInfo(handle, &console);
attr = console.wAttributes;
SetConsoleTextAttribute(handle, FOREGROUND_RED);
printf("%s", layout_char);
SetConsoleTextAttribute(handle, attr);
#else
printf("\e[31m%s\e[39m", layout_char);
#endif
} else {
printf("%s", layout_char);
}
}
printf("\n");
}