* Cursor up/down stop before empty (i.e. unused) history lines, now.
* Added support for page up/down (works like in bash). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23588 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
20fb39b662
commit
19b468ea24
@ -404,8 +404,12 @@ read_line(char *buffer, int32 maxLength,
|
||||
|
||||
// clear the history again if we're in the current line again
|
||||
// (the buffer we get just is the current line buffer)
|
||||
if (historyLine == sCurrentLine)
|
||||
if (historyLine == sCurrentLine) {
|
||||
sLineBuffer[historyLine][0] = '\0';
|
||||
} else if (sLineBuffer[historyLine][0] == '\0') {
|
||||
// empty history lines are unused -- so bail out
|
||||
break;
|
||||
}
|
||||
|
||||
// swap the current line with something from the history
|
||||
if (position > 0)
|
||||
@ -417,6 +421,46 @@ read_line(char *buffer, int32 maxLength,
|
||||
currentHistoryLine = historyLine;
|
||||
break;
|
||||
}
|
||||
case '5': // if "5~", it's PAGE UP
|
||||
case '6': // if "6~", it's PAGE DOWN
|
||||
{
|
||||
if (readChar() != '~')
|
||||
break;
|
||||
|
||||
// PAGE UP: search backward, PAGE DOWN: forward
|
||||
int32 searchDirection = (c == '5' ? -1 : 1);
|
||||
|
||||
bool found = false;
|
||||
int32 historyLine = currentHistoryLine;
|
||||
do {
|
||||
historyLine = (historyLine + searchDirection
|
||||
+ HISTORY_SIZE) % HISTORY_SIZE;
|
||||
if (historyLine == sCurrentLine)
|
||||
break;
|
||||
|
||||
if (strncmp(sLineBuffer[historyLine], buffer,
|
||||
position) == 0) {
|
||||
found = true;
|
||||
}
|
||||
} while (!found);
|
||||
|
||||
// bail out, if we've found nothing or hit an empty
|
||||
// (i.e. unused) history line
|
||||
if (!found || strlen(sLineBuffer[historyLine]) == 0)
|
||||
break;
|
||||
|
||||
// found a suitable line -- replace the current buffer
|
||||
// content with it
|
||||
strcpy(buffer, sLineBuffer[historyLine]);
|
||||
length = strlen(buffer);
|
||||
kprintf("%s\x1b[K", buffer + position);
|
||||
// print the line and clear the rest
|
||||
kprintf("\x1b[%ldD", length - position);
|
||||
// reposition cursor
|
||||
currentHistoryLine = historyLine;
|
||||
|
||||
break;
|
||||
}
|
||||
case 'H': // home
|
||||
{
|
||||
if (position > 0) {
|
||||
@ -435,8 +479,7 @@ read_line(char *buffer, int32 maxLength,
|
||||
}
|
||||
case '3': // if "3~", it's DEL
|
||||
{
|
||||
c = readChar();
|
||||
if (c != '~')
|
||||
if (readChar() != '~')
|
||||
break;
|
||||
|
||||
if (position < length)
|
||||
|
Loading…
Reference in New Issue
Block a user