- get rid of control chars in source files (ESC and CTRL-L)

- fix Home and End keys
- simplify code
- add different strings for Ctrl-arrows, allows to map them to previous/next-word (PuTTY and others have actually several codes depending on mods & ALT, mode & CTRL and even mods & CTRL|ALT, might be even better...).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25391 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-05-09 02:22:37 +00:00
parent f7cc12b389
commit 85b80c5229
4 changed files with 63 additions and 56 deletions

View File

@ -72,7 +72,7 @@ CodeConv::ConvertFromInternal(const char *src, int32 srclen, char *dst, int codi
// system api for code conversion... check if this (which looks a lot like a workaround) // system api for code conversion... check if this (which looks a lot like a workaround)
// applies to haiku, and if not, get rid of this class and just use the system api directly. // applies to haiku, and if not, get rid of this class and just use the system api directly.
if (coding == B_EUC_CONVERSION && state != 0) { if (coding == B_EUC_CONVERSION && state != 0) {
const char *end_of_jis = "(B"; const char *end_of_jis = "\033(B";
strncpy((char *)dst + dstlen, end_of_jis, 3); strncpy((char *)dst + dstlen, end_of_jis, 3);
dstlen += 3; dstlen += 3;
} }

View File

@ -1483,26 +1483,28 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
// Terminal filters RET, ENTER, F1...F12, and ARROW key code. // Terminal filters RET, ENTER, F1...F12, and ARROW key code.
// TODO: Cleanup // TODO: Cleanup
if (numBytes == 1) { if (numBytes == 1) {
const char *toWrite = NULL;
switch (*bytes) { switch (*bytes) {
case B_RETURN: case B_RETURN:
if (rawChar == B_RETURN) { if (rawChar == B_RETURN)
char c = 0x0d; toWrite = "\r";
fShell->Write(&c, 1);
return;
}
break; break;
case B_LEFT_ARROW: case B_LEFT_ARROW:
if (rawChar == B_LEFT_ARROW) { if (rawChar == B_LEFT_ARROW) {
fShell->Write(LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE) - 1); if (mod & B_CONTROL_KEY)
return; toWrite = CTRL_LEFT_ARROW_KEY_CODE;
else
toWrite = LEFT_ARROW_KEY_CODE;
} }
break; break;
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
if (rawChar == B_RIGHT_ARROW) { if (rawChar == B_RIGHT_ARROW) {
fShell->Write(RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE) - 1); if (mod & B_CONTROL_KEY)
return; toWrite = CTRL_RIGHT_ARROW_KEY_CODE;
else
toWrite = RIGHT_ARROW_KEY_CODE;
} }
break; break;
@ -1515,8 +1517,10 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
return; return;
} }
if (rawChar == B_UP_ARROW) { if (rawChar == B_UP_ARROW) {
fShell->Write(UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE) - 1); if (mod & B_CONTROL_KEY)
return; toWrite = CTRL_UP_ARROW_KEY_CODE;
else
toWrite = UP_ARROW_KEY_CODE;
} }
break; break;
@ -1528,30 +1532,26 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
} }
if (rawChar == B_DOWN_ARROW) { if (rawChar == B_DOWN_ARROW) {
fShell->Write(DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE) - 1); if (mod & B_CONTROL_KEY)
return; toWrite = CTRL_DOWN_ARROW_KEY_CODE;
else
toWrite = DOWN_ARROW_KEY_CODE;
} }
break; break;
case B_INSERT: case B_INSERT:
if (rawChar == B_INSERT) { if (rawChar == B_INSERT)
fShell->Write(INSERT_KEY_CODE, sizeof(INSERT_KEY_CODE) - 1); toWrite = INSERT_KEY_CODE;
return;
}
break; break;
case B_HOME: case B_HOME:
if (rawChar == B_HOME) { if (rawChar == B_HOME)
fShell->Write(HOME_KEY_CODE, sizeof(HOME_KEY_CODE) - 1); toWrite = HOME_KEY_CODE;
return;
}
break; break;
case B_END: case B_END:
if (rawChar == B_END) { if (rawChar == B_END)
fShell->Write(END_KEY_CODE, sizeof(END_KEY_CODE) - 1); toWrite = END_KEY_CODE;
return;
}
break; break;
case B_PAGE_UP: case B_PAGE_UP:
@ -1562,10 +1562,8 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
} }
return; return;
} }
if (rawChar == B_PAGE_UP) { if (rawChar == B_PAGE_UP)
fShell->Write(PAGE_UP_KEY_CODE, sizeof(PAGE_UP_KEY_CODE) - 1); toWrite = PAGE_UP_KEY_CODE;
return;
}
break; break;
case B_PAGE_DOWN: case B_PAGE_DOWN:
@ -1575,10 +1573,8 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
return; return;
} }
if (rawChar == B_PAGE_DOWN) { if (rawChar == B_PAGE_DOWN)
fShell->Write(PAGE_DOWN_KEY_CODE, sizeof(PAGE_DOWN_KEY_CODE) - 1); toWrite = PAGE_DOWN_KEY_CODE;
return;
}
break; break;
case B_FUNCTION_KEY: case B_FUNCTION_KEY:
@ -1593,6 +1589,10 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
default: default:
break; break;
} }
if (toWrite) {
fShell->Write(toWrite, strlen(toWrite));
return;
}
} else { } else {
// input multibyte character // input multibyte character
if (fEncoding != M_UTF8) { if (fEncoding != M_UTF8) {
@ -1636,7 +1636,7 @@ void
TermView::MessageReceived(BMessage *msg) TermView::MessageReceived(BMessage *msg)
{ {
entry_ref ref; entry_ref ref;
char *ctrl_l = " "; char *ctrl_l = "\x0c";
// first check for any dropped message // first check for any dropped message
if (msg->WasDropped()) { if (msg->WasDropped()) {

View File

@ -48,16 +48,16 @@ F12_KEY,
char *function_key_char_table [] = char *function_key_char_table [] =
{ {
"[11~", "\033[11~",
"[12~", "\033[12~",
"[13~", "\033[13~",
"[14~", "\033[14~",
"[15~", "\033[15~",
"[16~", "\033[16~",
"[17~", "\033[17~",
"[18~", "\033[18~",
"[19~", "\033[19~",
"[20~", "\033[20~",
"[21~", "\033[21~",
"[22~", "\033[22~",
}; };

View File

@ -65,16 +65,23 @@
#define LEFT_ARROW_KEY_CODE "" #define LEFT_ARROW_KEY_CODE "\033[D"
#define RIGHT_ARROW_KEY_CODE "" #define RIGHT_ARROW_KEY_CODE "\033[C"
#define UP_ARROW_KEY_CODE "" #define UP_ARROW_KEY_CODE "\033[A"
#define DOWN_ARROW_KEY_CODE "" #define DOWN_ARROW_KEY_CODE "\033[B"
#define HOME_KEY_CODE "[@" #define CTRL_LEFT_ARROW_KEY_CODE "\033[5D"
#define INSERT_KEY_CODE "[2~" #define CTRL_RIGHT_ARROW_KEY_CODE "\033[5C"
#define END_KEY_CODE "[[" #define CTRL_UP_ARROW_KEY_CODE "\033[5A"
#define PAGE_UP_KEY_CODE "[5~" #define CTRL_DOWN_ARROW_KEY_CODE "\033[5B"
#define PAGE_DOWN_KEY_CODE "[6~"
//#define HOME_KEY_CODE "\033[@"
#define HOME_KEY_CODE "\033[1~"
#define INSERT_KEY_CODE "\033[2~"
//#define END_KEY_CODE "\033[["
#define END_KEY_CODE "\033[4~"
#define PAGE_UP_KEY_CODE "\033[5~"
#define PAGE_DOWN_KEY_CODE "\033[6~"
//#define IS_DOWN_KEY(x) (info.key_states[(x) / 8] & key_state_table[(x) % 8]) //#define IS_DOWN_KEY(x) (info.key_states[(x) / 8] & key_state_table[(x) % 8])
#define IS_DOWN_KEY(x) \ #define IS_DOWN_KEY(x) \