* TermView::KeyDown(): We were writing to the TTY even when the user

pressed a shortcut that should result in a terminal action
  (e.g. Shift-Left/Right -- Shift-Left generated a Ctrl-\).
* Removed spaces at the end of lines.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26509 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-07-19 16:12:32 +00:00
parent 2fc7e292e5
commit 552580cd28
+132 -127
View File
@@ -1154,131 +1154,8 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
_ActivateCursor(true);
// Terminal filters RET, ENTER, F1...F12, and ARROW key code.
if (numBytes == 1) {
const char *toWrite = NULL;
switch (*bytes) {
case B_RETURN:
if (rawChar == B_RETURN)
toWrite = "\r";
break;
case B_DELETE:
toWrite = DELETE_KEY_CODE;
break;
case B_BACKSPACE:
// Translate only the actual backspace key to the backspace
// code. CTRL-H shall just be echoed.
if (!((mod & B_CONTROL_KEY) && rawChar == 'h'))
toWrite = BACKSPACE_KEY_CODE;
break;
case B_LEFT_ARROW:
if (rawChar == B_LEFT_ARROW) {
if (mod & B_SHIFT_KEY) {
BMessage message(MSG_PREVIOUS_TAB);
message.AddPointer("termView", this);
Window()->PostMessage(&message);
} else if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY)) {
toWrite = CTRL_LEFT_ARROW_KEY_CODE;
} else
toWrite = LEFT_ARROW_KEY_CODE;
}
break;
case B_RIGHT_ARROW:
if (rawChar == B_RIGHT_ARROW) {
if (mod & B_SHIFT_KEY) {
BMessage message(MSG_NEXT_TAB);
message.AddPointer("termView", this);
Window()->PostMessage(&message);
} else if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY)) {
toWrite = CTRL_RIGHT_ARROW_KEY_CODE;
} else
toWrite = RIGHT_ARROW_KEY_CODE;
}
break;
case B_UP_ARROW:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset - fFontHeight, true);
return;
}
if (rawChar == B_UP_ARROW) {
if (mod & B_CONTROL_KEY)
toWrite = CTRL_UP_ARROW_KEY_CODE;
else
toWrite = UP_ARROW_KEY_CODE;
}
break;
case B_DOWN_ARROW:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset + fFontHeight, true);
return;
}
if (rawChar == B_DOWN_ARROW) {
if (mod & B_CONTROL_KEY)
toWrite = CTRL_DOWN_ARROW_KEY_CODE;
else
toWrite = DOWN_ARROW_KEY_CODE;
}
break;
case B_INSERT:
if (rawChar == B_INSERT)
toWrite = INSERT_KEY_CODE;
break;
case B_HOME:
if (rawChar == B_HOME)
toWrite = HOME_KEY_CODE;
break;
case B_END:
if (rawChar == B_END)
toWrite = END_KEY_CODE;
break;
case B_PAGE_UP:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset - fFontHeight * fTermRows, true);
return;
}
if (rawChar == B_PAGE_UP)
toWrite = PAGE_UP_KEY_CODE;
break;
case B_PAGE_DOWN:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset + fFontHeight * fTermRows, true);
return;
}
if (rawChar == B_PAGE_DOWN)
toWrite = PAGE_DOWN_KEY_CODE;
break;
case B_FUNCTION_KEY:
for (int32 i = 0; i < 12; i++) {
if (key == function_keycode_table[i]) {
fShell->Write(function_key_char_table[i], 5);
return;
}
}
break;
default:
break;
}
if (toWrite) {
_ScrollTo(0, true);
fShell->Write(toWrite, strlen(toWrite));
return;
}
} else {
// input multibyte character
// handle multi-byte chars
if (numBytes > 1) {
if (fEncoding != M_UTF8) {
char destBuffer[16];
int cnum = CodeConv::ConvertFromInternal(bytes, numBytes,
@@ -1287,10 +1164,138 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
fShell->Write(destBuffer, cnum);
return;
}
_ScrollTo(0, true);
fShell->Write(bytes, numBytes);
return;
}
_ScrollTo(0, true);
fShell->Write(bytes, numBytes);
// Terminal filters RET, ENTER, F1...F12, and ARROW key code.
const char *toWrite = NULL;
int32 toWriteLen = -1;
switch (*bytes) {
case B_RETURN:
if (rawChar == B_RETURN)
toWrite = "\r";
break;
case B_DELETE:
toWrite = DELETE_KEY_CODE;
break;
case B_BACKSPACE:
// Translate only the actual backspace key to the backspace
// code. CTRL-H shall just be echoed.
if (!((mod & B_CONTROL_KEY) && rawChar == 'h'))
toWrite = BACKSPACE_KEY_CODE;
break;
case B_LEFT_ARROW:
if (rawChar == B_LEFT_ARROW) {
if (mod & B_SHIFT_KEY) {
BMessage message(MSG_PREVIOUS_TAB);
message.AddPointer("termView", this);
Window()->PostMessage(&message);
} else if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY)) {
toWrite = CTRL_LEFT_ARROW_KEY_CODE;
} else
toWrite = LEFT_ARROW_KEY_CODE;
}
break;
case B_RIGHT_ARROW:
if (rawChar == B_RIGHT_ARROW) {
if (mod & B_SHIFT_KEY) {
BMessage message(MSG_NEXT_TAB);
message.AddPointer("termView", this);
Window()->PostMessage(&message);
} else if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY)) {
toWrite = CTRL_RIGHT_ARROW_KEY_CODE;
} else
toWrite = RIGHT_ARROW_KEY_CODE;
}
break;
case B_UP_ARROW:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset - fFontHeight, true);
return;
}
if (rawChar == B_UP_ARROW) {
if (mod & B_CONTROL_KEY)
toWrite = CTRL_UP_ARROW_KEY_CODE;
else
toWrite = UP_ARROW_KEY_CODE;
}
break;
case B_DOWN_ARROW:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset + fFontHeight, true);
return;
}
if (rawChar == B_DOWN_ARROW) {
if (mod & B_CONTROL_KEY)
toWrite = CTRL_DOWN_ARROW_KEY_CODE;
else
toWrite = DOWN_ARROW_KEY_CODE;
}
break;
case B_INSERT:
if (rawChar == B_INSERT)
toWrite = INSERT_KEY_CODE;
break;
case B_HOME:
if (rawChar == B_HOME)
toWrite = HOME_KEY_CODE;
break;
case B_END:
if (rawChar == B_END)
toWrite = END_KEY_CODE;
break;
case B_PAGE_UP:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset - fFontHeight * fTermRows, true);
return;
}
if (rawChar == B_PAGE_UP)
toWrite = PAGE_UP_KEY_CODE;
break;
case B_PAGE_DOWN:
if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset + fFontHeight * fTermRows, true);
return;
}
if (rawChar == B_PAGE_DOWN)
toWrite = PAGE_DOWN_KEY_CODE;
break;
case B_FUNCTION_KEY:
for (int32 i = 0; i < 12; i++) {
if (key == function_keycode_table[i]) {
fShell->Write(function_key_char_table[i], 5);
return;
}
}
break;
default:
toWrite = bytes;
toWriteLen = 1;
break;
}
if (toWrite) {
_ScrollTo(0, true);
fShell->Write(toWrite, toWriteLen < 0 ? strlen(toWrite) : toWriteLen);
}
}