Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed input on wndows #181

Merged
merged 8 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 137 additions & 5 deletions cpp-terminal/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,144 @@

namespace Term {
enum Key {
BACKSPACE = 1000,
ENTER,
NO_KEY = -1,
// Begin ASCII
NUL = 0,
SOH = 1,
STX = 2,
ETX = 3,
EOT = 4,
ENQ = 5,
ACK = 6,
BEL = 7,
BS = 8,
BACKSPACE = 8,
HT = 9,
TAB = 9,
LF = 10,
ENTER = 10,
VT = 11,
FF = 12,
CR = 13,
SO = 14,
SI = 15,
DLE = 16,
DC1 = 17,
DC2 = 18,
DC3 = 19,
DC4 = 20,
NAK = 21,
SYN = 22,
ETB = 23,
CAN = 24,
EM = 25,
SUB = 26,
ESC = 27,
FS = 28,
GS = 29,
RS = 30,
US = 31,
SPACE = 32,
EXCLAMATION_MARK = 33,
QUOTE = 34,
HASH = 35,
DOLLAR = 36,
PERCENT = 37,
AMPERSAND = 38,
APOSTROPHE = 39,
OPEN_PARENTHESIS = 40,
CLOSE_PARENTHESIS = 41,
ASTERISK = 42,
PLUS = 43,
COMMA = 44,
HYPHEN = 45,
MINUS = 45,
PERIOD = 46,
SLASH = 47,
ZERO = 48,
ONE = 49,
TWO = 50,
THREE = 51,
FOUR = 52,
FIVE = 53,
SIX = 54,
SEVEN = 55,
EIGHT = 56,
NINE = 57,
COLON = 58,
SEMICOLON = 59,
LESS_THAN = 60,
OPEN_CHEVRON = 60,
EQUAL = 61,
GREATER_THAN = 62,
CLOSE_CHEVRON = 62,
QUESTION_MARK = 63,
AROBASE = 64,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
OPEN_BRACKET = 91,
BACKSLASH = 92,
CLOSE_BRACKET = 93,
CARET = 94,
UNDERSCORE = 95,
GRAVE_ACCENT = 96,
a = 97,
b = 98,
c = 99,
d = 100,
e = 101,
f = 102,
g = 103,
h = 104,
i = 105,
j = 106,
k = 107,
l = 108,
m = 109,
n = 110,
o = 111,
p = 112,
q = 113,
r = 114,
s = 115,
t = 116,
u = 117,
v = 118,
w = 119,
x = 120,
y = 121,
z = 122,
OPEN_BRACE = 123,
VERTICAL_BAR = 124,
CLOSE_BRACE = 125,
TILDE = 126,
DEL = 127,
// End ASCII
ALT_ENTER,
TAB,
ARROW_LEFT,
ARROW_RIGHT,
ARROW_UP,
Expand All @@ -16,13 +150,11 @@ enum Key {
CTRL_RIGHT,
CTRL_LEFT,
NUMERIC_5,
DEL,
HOME,
INSERT,
END,
PAGE_UP,
PAGE_DOWN,
ESC,
F1,
F2,
F3,
Expand Down
3 changes: 2 additions & 1 deletion cpp-terminal/private/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ Term::Private::BaseTerminal::BaseTerminal(bool enable_keyboard,
}
DWORD flags = dwOriginalInMode;
flags |= ENABLE_VIRTUAL_TERMINAL_INPUT;
flags &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
flags &=
~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
if (!SetConsoleMode(hin, flags)) {
throw std::runtime_error("SetConsoleMode() failed");
}
Expand Down
10 changes: 5 additions & 5 deletions cpp-terminal/prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ std::vector<std::string> Term::split(const std::string& s) {
return lines;
}

char32_t Term::U(const std::string& s) {
char32_t Term::UU(const std::string& s) {
std::u32string s2 = Private::utf8_to_utf32(s);
if (s2.size() != 1)
throw std::runtime_error("U(s): s not a codepoint.");
Expand All @@ -140,13 +140,13 @@ char32_t Term::U(const std::string& s) {
void Term::print_left_curly_bracket(Term::Window& scr, int x, int y1, int y2) {
int h = y2 - y1 + 1;
if (h == 1) {
scr.set_char(x, y1, U("]"));
scr.set_char(x, y1, UU("]"));
} else {
scr.set_char(x, y1, U("┐"));
scr.set_char(x, y1, UU("┐"));
for (int j = y1 + 1; j <= y2 - 1; j++) {
scr.set_char(x, j, U("│"));
scr.set_char(x, j, UU("│"));
}
scr.set_char(x, y2, U("┘"));
scr.set_char(x, y2, UU("┘"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp-terminal/prompt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::string concat(const std::vector<std::string>&);

std::vector<std::string> split(const std::string&);

char32_t U(const std::string&);
char32_t UU(const std::string&);

void print_left_curly_bracket(Term::Window&, int, int, int);

Expand Down
1 change: 0 additions & 1 deletion examples/kilo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ bool editorProcessKeypress() {
break;

case Key::BACKSPACE:
case Key::CTRL + 'h':
case Key::DEL:
if (c == Key::DEL)
editorMoveCursor(Key::ARROW_RIGHT);
Expand Down