Skip to content

Commit 28f9c46

Browse files
committed
UTF-8!!!
1 parent c0deb31 commit 28f9c46

File tree

19 files changed

+552
-718
lines changed

19 files changed

+552
-718
lines changed

Buffer.c

Lines changed: 111 additions & 123 deletions
Large diffs are not rendered by default.

CRT.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void CRT_parseTerminalFile(char* term) {
131131
if (!fd) {
132132
Display_printAt(0,0,"Warning: could not parse terminal rules file terminals/%s", term);
133133
Display_printAt(1,0,"Press any key.");
134-
Display_getch();
134+
CRT_readKey();
135135
return;
136136
}
137137
while (!feof(fd)) {
@@ -465,7 +465,8 @@ void CRT_done() {
465465
int CRT_readKey() {
466466
//nocbreak();
467467
//cbreak();
468-
int ret = Display_getch();
468+
bool code;
469+
int ret = Display_getch(&code);
469470
//if (CRT_delay)
470471
// halfdelay(CRT_delay);
471472
return ret;
@@ -482,12 +483,12 @@ void CRT_handleSIGTERM(int signal) {
482483
exit(0);
483484
}
484485

485-
int CRT_getCharacter() {
486+
int CRT_getCharacter(bool* code) {
486487
Display_refresh();
487-
int ch = Display_getch();
488+
int ch = Display_getch(code);
488489
#if defined __linux || defined __CYGWIN__
489-
if (ch == KEY_LEFT || ch == KEY_RIGHT || ch == KEY_UP || ch == KEY_DOWN
490-
|| ch == KEY_HOME || ch == KEY_END || ch == KEY_IC || ch == KEY_DC || ch == '\t') {
490+
if ((*code && (ch == KEY_LEFT || ch == KEY_RIGHT || ch == KEY_UP || ch == KEY_DOWN
491+
|| ch == KEY_HOME || ch == KEY_END || ch == KEY_IC || ch == KEY_DC)) || (!*code && ch == '\t')) {
491492
#ifndef __CYGWIN__
492493
unsigned char modifiers = 6;
493494
#else

Clipboard.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void Clipboard_delete(Clipboard* this) {
2626
free(this);
2727
}
2828

29-
char* Clipboard_get(Clipboard* this, int* textLen) {
29+
Text Clipboard_get(Clipboard* this) {
3030
if (this->disk) {
3131
FILE* fd = fopen(this->clipFileName, "r");
3232
if (fd) {
@@ -36,25 +36,22 @@ char* Clipboard_get(Clipboard* this, int* textLen) {
3636
while (!feof(fd)) {
3737
if (size - len < 100) {
3838
size = len + 100;
39-
out = realloc(out, size);
39+
out = realloc(out, size+1);
4040
}
4141
char* walk = out + len;
4242
int amt = fread(walk, 1, 100, fd);
4343
len += amt;
4444
}
45+
out[len] = '\0';
4546
fclose(fd);
46-
if (textLen)
47-
*textLen = len;
48-
return out;
47+
return Text_new(out);
4948
}
5049
this->disk = false;
5150
}
5251
if (this->text) {
53-
if (textLen)
54-
*textLen = this->len;
55-
return strdup(this->text);
52+
return Text_new(strdup(this->text));
5653
}
57-
return NULL;
54+
return Text_null();
5855
}
5956

6057
void Clipboard_set(Clipboard* this, char* text, int len) {

Display.c

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ static Hashtable* Display_terminalSequences;
4444
#define HAVE_CURSES 1
4545
#else
4646
47-
typedef unsigned long chtype;
48-
4947
#define OK 0
5048
#define ERR -1
5149
@@ -388,30 +386,44 @@ void Display_getyx(int* y, int* x) {
388386
}
389387
#endif
390388

391-
#if HAVE_CURSES
392-
#define Display_getch getch
393-
#else
394-
int Display_getch() {
395-
char sequence[11] = { 0 };
396-
int ch = getchar();
397-
sequence[0] = ch;
398-
if (ch == 27) {
399-
for (int i = 1; i <= 10; i++) {
400-
struct pollfd pfd = { .fd = 0, .events = POLLIN, .revents = 0 };
401-
int any = poll(&pfd, 1, 30);
402-
if (any > 0) {
403-
sequence[i] = getchar();
404-
} else {
405-
break;
389+
int Display_getch(bool* code) {
390+
#if HAVE_CURSES
391+
#if HAVE_NCURSESW_CURSES_H
392+
wint_t ch;
393+
int isCode = get_wch(&ch);
394+
*code = (isCode == KEY_CODE_YES || isCode == ERR);
395+
if (isCode == ERR) return ERR;
396+
return ch;
397+
#else
398+
int ch = getch();
399+
*code = (ch > 0xff || ch == ERR);
400+
return ch;
401+
#endif
402+
#else
403+
char sequence[11] = { 0 };
404+
// TODO: UTF-8 loop
405+
int ch = getchar();
406+
sequence[0] = ch;
407+
if (ch == 27) {
408+
for (int i = 1; i <= 10; i++) {
409+
struct pollfd pfd = { .fd = 0, .events = POLLIN, .revents = 0 };
410+
int any = poll(&pfd, 1, 30);
411+
if (any > 0) {
412+
sequence[i] = getchar();
413+
} else {
414+
break;
415+
}
406416
}
407417
}
408-
}
409-
int keynum = (int) Hashtable_getString(Display_terminalSequences, sequence);
410-
if (keynum)
411-
return keynum;
412-
return ch;
418+
int keynum = (int) Hashtable_getString(Display_terminalSequences, sequence);
419+
if (keynum) {
420+
*code = true;
421+
return keynum;
422+
}
423+
*code = false;
424+
return ch;
425+
#endif
413426
}
414-
#endif
415427

416428
#if HAVE_CURSES
417429
#define Display_defineKey define_key
@@ -504,7 +516,7 @@ bool Display_init(char* term) {
504516
void Display_done() {
505517
curs_set(1);
506518
endwin();
507-
delscreen(CRT_term);
519+
//delscreen(CRT_term);
508520
}
509521
#else
510522
void Display_done() {

0 commit comments

Comments
 (0)