From 19b468ea247213ddf51ab015a7969e8b9bf98aa8 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 17 Jan 2008 15:29:27 +0000 Subject: [PATCH] * 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 --- src/system/kernel/debug/debug.cpp | 49 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index d29df43c98..c7d812af41 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -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)