Commit c4779f35 authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Tomaz Canabrava
Browse files

Add scroll to previous/next prompt

When using semantic shell integration (OSC 133), ctrl+shift+PgUp/Down
scrolls up down to the next prompt.
parent cfaf997e
......@@ -185,10 +185,12 @@ key Space +Control : "\x00"
# The scroll* operations refer to the history buffer.
key Up +Shift-AppScreen : scrollLineUp
key PgUp +Shift-AppScreen : scrollPageUp
key PgUp +Shift-Ctrl-AppScreen : scrollPageUp
key Home +Shift-AppScreen : scrollUpToTop
key Down +Shift-AppScreen : scrollLineDown
key PgDown +Shift-AppScreen : scrollPageDown
key PgDown +Shift-Ctrl-AppScreen : scrollPageDown
key End +Shift-AppScreen : scrollDownToBottom
key PgUp +Shift+Ctrl-AppScreen : scrollPromptUp
key PgDown +Shift+Ctrl-AppScreen : scrollDownPrompt
......@@ -117,9 +117,11 @@ key Space +Control : "\x00"
# some of keys are used by konsole.
key Up +Shift : scrollLineUp
key PgUp +Shift : scrollPageUp
key PgUp +Shift-Ctrl : scrollPageUp
key Down +Shift : scrollLineDown
key PgDown +Shift : scrollPageDown
key PgDown +Shift-Ctrl : scrollPageDown
key PgUp +Shift+Ctrl : scrollPromptUp
key PgDown +Shift+Ctrl : scrollPromptDown
#----------------------------------------------------------
......
......@@ -188,10 +188,12 @@ key Space +Control : "\x00"
# The scroll* operations refer to the history buffer.
key Up +Shift-AppScreen : scrollLineUp
key PgUp +Shift-AppScreen : scrollPageUp
key PgUp +Shift-Ctrl-AppScreen : scrollPageUp
key Home +Shift-AppScreen : scrollUpToTop
key Down +Shift-AppScreen : scrollLineDown
key Down +Shift-Ctrl-AppScreen : scrollLineDown
key PgDown +Shift-AppScreen : scrollPageDown
key End +Shift-AppScreen : scrollDownToBottom
key PgUp +Shift+Ctrl-AppScreen : scrollPromptUp
key Down +Shift+Ctrl-AppScreen : scrollPromptDown
......@@ -100,9 +100,11 @@ key Space +Control : "\x00"
#key Left +Shift : prevSession
#key Right +Shift : nextSession
key Up +Shift : scrollLineUp
key PgUp +Shift : scrollPageUp
key PgUp +Shift-Ctrl : scrollPageUp
key Down +Shift : scrollLineDown
key PgDown +Shift : scrollPageDown
key PgDown +Shift-Ctrl : scrollPageDown
#key Insert+Shift : emitSelection
key PgUp +Shift+Ctrl : scrollPromptUp
key PgDown +Shift+Ctrl : scrollPromptDown
# keypad characters are not offered differently by Qt.
......@@ -1232,8 +1232,6 @@ void Screen::clearImage(int loca, int loce, char c, bool resetLineRendition)
const bool isDefaultCh = (clearCh == Screen::DefaultChar);
for (int y = topLine; y <= bottomLine; ++y) {
_lineProperties[y] = 0;
const int endCol = (y == bottomLine) ? loce % _columns : _columns - 1;
const int startCol = (y == topLine) ? loca % _columns : 0;
......
......@@ -231,12 +231,36 @@ void ScreenWindow::scrollBy(RelativeScrollMode mode, int amount, bool fullPage)
{
if (mode == ScrollLines) {
scrollTo(currentLine() + amount);
} else if (mode == ScrollPages) {
} else if (mode == ScrollPages || (mode == ScrollPrompts && !_screen->hasRepl())) {
if (fullPage) {
scrollTo(currentLine() + amount * (windowLines()));
} else {
scrollTo(currentLine() + amount * (windowLines() / 2));
}
} else if (mode == ScrollPrompts) {
int i = currentLine();
if (amount < 0) {
QVector<LineProperty> properties = _screen->getLineProperties(0, currentLine());
while (i > 0 && amount < 0) {
i--;
if ((properties[i] & LINE_PROMPT_START) != 0) {
if (++amount == 0) {
break;
}
}
}
} else if (amount > 0) {
QVector<LineProperty> properties = _screen->getLineProperties(currentLine(), _screen->getHistLines());
while (i < _screen->getHistLines() && amount > 0) {
i++;
if ((properties[i - currentLine()] & LINE_PROMPT_START) != 0) {
if (--amount == 0) {
break;
}
}
}
}
scrollTo(i);
}
}
......
......@@ -183,6 +183,10 @@ public:
* one page is windowLines() lines
*/
ScrollPages,
/** Scroll by prompt (when using semantic shell integration)
* scrolls up/down until the given number of new prompts appear.
*/
ScrollPrompts,
};
/**
......
......@@ -2157,7 +2157,6 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
// look up key binding
if (_keyTranslator != nullptr) {
KeyboardTranslator::Entry entry = _keyTranslator->findEntry(event->key(), modifiers, states);
// send result to terminal
QByteArray textToSend;
......@@ -2193,6 +2192,10 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
currentView->scrollScreenWindow(ScreenWindow::ScrollLines, -currentView->screenWindow()->currentLine());
} else if ((entry.command() & KeyboardTranslator::ScrollDownToBottomCommand) != 0) {
currentView->scrollScreenWindow(ScreenWindow::ScrollLines, lineCount());
} else if ((entry.command() & KeyboardTranslator::ScrollPromptUpCommand) != 0) {
currentView->scrollScreenWindow(ScreenWindow::ScrollPrompts, -1);
} else if ((entry.command() & KeyboardTranslator::ScrollPromptDownCommand) != 0) {
currentView->scrollScreenWindow(ScreenWindow::ScrollPrompts, 1);
}
}
} else if (!entry.text().isEmpty()) {
......
......@@ -262,6 +262,10 @@ QString KeyboardTranslator::Entry::resultToString(bool expandWildCards, Qt::Keyb
return QStringLiteral("ScrollUpToTop");
} else if (_command == ScrollDownToBottomCommand) {
return QStringLiteral("ScrollDownToBottom");
} else if (_command == ScrollPromptUpCommand) {
return QStringLiteral("ScrollPromptUp");
} else if (_command == ScrollPromptDownCommand) {
return QStringLiteral("ScrollPromptDown");
}
return QString();
......
......@@ -95,8 +95,12 @@ public:
ScrollUpToTopCommand = 32,
/** Scroll the terminal display down to the end of history */
ScrollDownToBottomCommand = 64,
/** Scroll the terminal display up to the next prompt */
ScrollPromptUpCommand = 128,
/** Scroll the terminal display down to the next prompt */
ScrollPromptDownCommand = 256,
/** Echos the operating system specific erase character. */
EraseCommand = 256,
EraseCommand = 512,
};
Q_DECLARE_FLAGS(Commands, Command)
......
......@@ -122,6 +122,10 @@ bool KeyboardTranslatorReader::parseAsCommand(const QString &text, KeyboardTrans
command = KeyboardTranslator::ScrollUpToTopCommand;
} else if (text.compare(QLatin1String("scrolldowntobottom"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollDownToBottomCommand;
} else if (text.compare(QLatin1String("scrollpromptup"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollPromptUpCommand;
} else if (text.compare(QLatin1String("scrollpromptdown"), Qt::CaseInsensitive) == 0) {
command = KeyboardTranslator::ScrollPromptDownCommand;
} else {
return false;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment