Skip to content

Commit

Permalink
UTF-8!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Nov 28, 2012
1 parent c0deb31 commit 28f9c46
Show file tree
Hide file tree
Showing 19 changed files with 552 additions and 718 deletions.
234 changes: 111 additions & 123 deletions Buffer.c

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void CRT_parseTerminalFile(char* term) {
if (!fd) {
Display_printAt(0,0,"Warning: could not parse terminal rules file terminals/%s", term);
Display_printAt(1,0,"Press any key.");
Display_getch();
CRT_readKey();
return;
}
while (!feof(fd)) {
Expand Down Expand Up @@ -465,7 +465,8 @@ void CRT_done() {
int CRT_readKey() {
//nocbreak();
//cbreak();
int ret = Display_getch();
bool code;
int ret = Display_getch(&code);
//if (CRT_delay)
// halfdelay(CRT_delay);
return ret;
Expand All @@ -482,12 +483,12 @@ void CRT_handleSIGTERM(int signal) {
exit(0);
}

int CRT_getCharacter() {
int CRT_getCharacter(bool* code) {
Display_refresh();
int ch = Display_getch();
int ch = Display_getch(code);
#if defined __linux || defined __CYGWIN__
if (ch == KEY_LEFT || ch == KEY_RIGHT || ch == KEY_UP || ch == KEY_DOWN
|| ch == KEY_HOME || ch == KEY_END || ch == KEY_IC || ch == KEY_DC || ch == '\t') {
if ((*code && (ch == KEY_LEFT || ch == KEY_RIGHT || ch == KEY_UP || ch == KEY_DOWN
|| ch == KEY_HOME || ch == KEY_END || ch == KEY_IC || ch == KEY_DC)) || (!*code && ch == '\t')) {
#ifndef __CYGWIN__
unsigned char modifiers = 6;
#else
Expand Down
15 changes: 6 additions & 9 deletions Clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void Clipboard_delete(Clipboard* this) {
free(this);
}

char* Clipboard_get(Clipboard* this, int* textLen) {
Text Clipboard_get(Clipboard* this) {
if (this->disk) {
FILE* fd = fopen(this->clipFileName, "r");
if (fd) {
Expand All @@ -36,25 +36,22 @@ char* Clipboard_get(Clipboard* this, int* textLen) {
while (!feof(fd)) {
if (size - len < 100) {
size = len + 100;
out = realloc(out, size);
out = realloc(out, size+1);
}
char* walk = out + len;
int amt = fread(walk, 1, 100, fd);
len += amt;
}
out[len] = '\0';
fclose(fd);
if (textLen)
*textLen = len;
return out;
return Text_new(out);
}
this->disk = false;
}
if (this->text) {
if (textLen)
*textLen = this->len;
return strdup(this->text);
return Text_new(strdup(this->text));
}
return NULL;
return Text_null();
}

void Clipboard_set(Clipboard* this, char* text, int len) {
Expand Down
60 changes: 36 additions & 24 deletions Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ static Hashtable* Display_terminalSequences;
#define HAVE_CURSES 1
#else
typedef unsigned long chtype;
#define OK 0
#define ERR -1
Expand Down Expand Up @@ -388,30 +386,44 @@ void Display_getyx(int* y, int* x) {
}
#endif

#if HAVE_CURSES
#define Display_getch getch
#else
int Display_getch() {
char sequence[11] = { 0 };
int ch = getchar();
sequence[0] = ch;
if (ch == 27) {
for (int i = 1; i <= 10; i++) {
struct pollfd pfd = { .fd = 0, .events = POLLIN, .revents = 0 };
int any = poll(&pfd, 1, 30);
if (any > 0) {
sequence[i] = getchar();
} else {
break;
int Display_getch(bool* code) {
#if HAVE_CURSES
#if HAVE_NCURSESW_CURSES_H
wint_t ch;
int isCode = get_wch(&ch);
*code = (isCode == KEY_CODE_YES || isCode == ERR);
if (isCode == ERR) return ERR;
return ch;
#else
int ch = getch();
*code = (ch > 0xff || ch == ERR);
return ch;
#endif
#else
char sequence[11] = { 0 };
// TODO: UTF-8 loop
int ch = getchar();
sequence[0] = ch;
if (ch == 27) {
for (int i = 1; i <= 10; i++) {
struct pollfd pfd = { .fd = 0, .events = POLLIN, .revents = 0 };
int any = poll(&pfd, 1, 30);
if (any > 0) {
sequence[i] = getchar();
} else {
break;
}
}
}
}
int keynum = (int) Hashtable_getString(Display_terminalSequences, sequence);
if (keynum)
return keynum;
return ch;
int keynum = (int) Hashtable_getString(Display_terminalSequences, sequence);
if (keynum) {
*code = true;
return keynum;
}
*code = false;
return ch;
#endif
}
#endif

#if HAVE_CURSES
#define Display_defineKey define_key
Expand Down Expand Up @@ -504,7 +516,7 @@ bool Display_init(char* term) {
void Display_done() {
curs_set(1);
endwin();
delscreen(CRT_term);
//delscreen(CRT_term);
}
#else
void Display_done() {
Expand Down
Loading

0 comments on commit 28f9c46

Please sign in to comment.