All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cli_ansi.h
1#pragma once
2
3#include <furi.h>
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9// text styling
10
11#define ANSI_RESET "\e[0m"
12#define ANSI_BOLD "\e[1m"
13#define ANSI_FAINT "\e[2m"
14#define ANSI_INVERT "\e[7m"
15
16#define ANSI_FG_BLACK "\e[30m"
17#define ANSI_FG_RED "\e[31m"
18#define ANSI_FG_GREEN "\e[32m"
19#define ANSI_FG_YELLOW "\e[33m"
20#define ANSI_FG_BLUE "\e[34m"
21#define ANSI_FG_MAGENTA "\e[35m"
22#define ANSI_FG_CYAN "\e[36m"
23#define ANSI_FG_WHITE "\e[37m"
24#define ANSI_FG_BR_BLACK "\e[90m"
25#define ANSI_FG_BR_RED "\e[91m"
26#define ANSI_FG_BR_GREEN "\e[92m"
27#define ANSI_FG_BR_YELLOW "\e[93m"
28#define ANSI_FG_BR_BLUE "\e[94m"
29#define ANSI_FG_BR_MAGENTA "\e[95m"
30#define ANSI_FG_BR_CYAN "\e[96m"
31#define ANSI_FG_BR_WHITE "\e[97m"
32
33#define ANSI_BG_BLACK "\e[40m"
34#define ANSI_BG_RED "\e[41m"
35#define ANSI_BG_GREEN "\e[42m"
36#define ANSI_BG_YELLOW "\e[43m"
37#define ANSI_BG_BLUE "\e[44m"
38#define ANSI_BG_MAGENTA "\e[45m"
39#define ANSI_BG_CYAN "\e[46m"
40#define ANSI_BG_WHITE "\e[47m"
41#define ANSI_BG_BR_BLACK "\e[100m"
42#define ANSI_BG_BR_RED "\e[101m"
43#define ANSI_BG_BR_GREEN "\e[102m"
44#define ANSI_BG_BR_YELLOW "\e[103m"
45#define ANSI_BG_BR_BLUE "\e[104m"
46#define ANSI_BG_BR_MAGENTA "\e[105m"
47#define ANSI_BG_BR_CYAN "\e[106m"
48#define ANSI_BG_BR_WHITE "\e[107m"
49
50#define ANSI_FLIPPER_BRAND_ORANGE "\e[38;2;255;130;0m"
51
52// cursor positioning
53
54#define ANSI_CURSOR_UP_BY(rows) "\e[" rows "A"
55#define ANSI_CURSOR_DOWN_BY(rows) "\e[" rows "B"
56#define ANSI_CURSOR_RIGHT_BY(cols) "\e[" cols "C"
57#define ANSI_CURSOR_LEFT_BY(cols) "\e[" cols "D"
58#define ANSI_CURSOR_DOWN_BY_AND_FIRST_COLUMN(rows) "\e[" rows "E"
59#define ANSI_CURSOR_UP_BY_AND_FIRST_COLUMN(rows) "\e[" rows "F"
60#define ANSI_CURSOR_HOR_POS(pos) "\e[" pos "G"
61#define ANSI_CURSOR_POS(row, col) "\e[" row ";" col "H"
62
63// erasing
64
65#define ANSI_ERASE_FROM_CURSOR_TO_END "0"
66#define ANSI_ERASE_FROM_START_TO_CURSOR "1"
67#define ANSI_ERASE_ENTIRE "2"
68
69#define ANSI_ERASE_DISPLAY(portion) "\e[" portion "J"
70#define ANSI_ERASE_LINE(portion) "\e[" portion "K"
71#define ANSI_ERASE_SCROLLBACK_BUFFER ANSI_ERASE_DISPLAY("3")
72
73// misc
74
75#define ANSI_INSERT_MODE_ENABLE "\e[4h"
76#define ANSI_INSERT_MODE_DISABLE "\e[4l"
77
78typedef enum {
79 CliKeyUnrecognized = 0,
80
81 CliKeySOH = 0x01,
82 CliKeyETX = 0x03,
83 CliKeyEOT = 0x04,
84 CliKeyBell = 0x07,
85 CliKeyBackspace = 0x08,
86 CliKeyTab = 0x09,
87 CliKeyLF = 0x0A,
88 CliKeyFF = 0x0C,
89 CliKeyCR = 0x0D,
90 CliKeyETB = 0x17,
91 CliKeyEsc = 0x1B,
92 CliKeyUS = 0x1F,
93 CliKeySpace = 0x20,
94 CliKeyDEL = 0x7F,
95
96 CliKeySpecial = 0x80,
97 CliKeyLeft,
98 CliKeyRight,
99 CliKeyUp,
100 CliKeyDown,
101 CliKeyHome,
102 CliKeyEnd,
103} CliKey;
104
105typedef enum {
106 CliModKeyNo = 0,
107 CliModKeyAlt = 2,
108 CliModKeyCtrl = 4,
109 CliModKeyMeta = 8,
110} CliModKey;
111
112typedef struct {
113 CliModKey modifiers;
114 CliKey key;
116
117typedef struct CliAnsiParser CliAnsiParser;
118
119typedef struct {
120 bool is_done;
121 CliKeyCombo result;
123
127CliAnsiParser* cli_ansi_parser_alloc(void);
128
132void cli_ansi_parser_free(CliAnsiParser* parser);
133
137CliAnsiParserResult cli_ansi_parser_feed(CliAnsiParser* parser, char c);
138
149CliAnsiParserResult cli_ansi_parser_feed_timeout(CliAnsiParser* parser);
150
151#ifdef __cplusplus
152}
153#endif
Definition cli_ansi.c:12
Definition cli_ansi.h:119
Definition cli_ansi.h:112