mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
Utilities: Add half-page scrolling + number modifiers to 'less'
- 'u' and 'd' now scroll up and down half a page - Typing a number followed by 'j', 'k', 'return', 'up' or 'down' will scroll that many lines in the appropriate direction - Typing a number followed by 'g' or 'G' will scroll directly to the line corresponding to that number
This commit is contained in:
parent
a071dba1ef
commit
e9bd81a6a0
1 changed files with 60 additions and 15 deletions
|
@ -158,9 +158,30 @@ public:
|
||||||
|
|
||||||
void bottom()
|
void bottom()
|
||||||
{
|
{
|
||||||
|
while (read_line())
|
||||||
|
;
|
||||||
down_n(m_lines.size() - m_line);
|
down_n(m_lines.size() - m_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void up_half_page()
|
||||||
|
{
|
||||||
|
up_n(m_height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void down_half_page()
|
||||||
|
{
|
||||||
|
down_n(m_height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void go_to_line(size_t line_num)
|
||||||
|
{
|
||||||
|
if (line_num < m_line) {
|
||||||
|
up_n(m_line - line_num);
|
||||||
|
} else {
|
||||||
|
down_n(line_num - m_line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
while (m_lines.size() < m_height) {
|
while (m_lines.size() < m_height) {
|
||||||
|
@ -371,22 +392,46 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
pager.init();
|
pager.init();
|
||||||
|
|
||||||
|
StringBuilder modifier_buffer = StringBuilder(10);
|
||||||
for (String sequence;; sequence = get_key_sequence()) {
|
for (String sequence;; sequence = get_key_sequence()) {
|
||||||
if (sequence == "" || sequence == "q") {
|
if (sequence.to_uint().has_value()) {
|
||||||
break;
|
modifier_buffer.append(sequence);
|
||||||
} else if (sequence == "j" || sequence == "\e[B" || sequence == "\n") {
|
} else {
|
||||||
pager.down();
|
if (sequence == "" || sequence == "q") {
|
||||||
} else if (sequence == "k" || sequence == "\e[A") {
|
break;
|
||||||
if (!emulate_more)
|
} else if (sequence == "j" || sequence == "\e[B" || sequence == "\n") {
|
||||||
pager.up();
|
if (!modifier_buffer.is_empty())
|
||||||
} else if (sequence == "g") {
|
pager.down_n(modifier_buffer.build().to_uint().value_or(1));
|
||||||
pager.top();
|
else
|
||||||
} else if (sequence == "G") {
|
pager.down();
|
||||||
pager.bottom();
|
} else if (sequence == "k" || sequence == "\e[A") {
|
||||||
} else if (sequence == " " || sequence == "\e[6~") {
|
if (!emulate_more) {
|
||||||
pager.down_page();
|
if (!modifier_buffer.is_empty())
|
||||||
} else if (sequence == "\e[5~") {
|
pager.up_n(modifier_buffer.build().to_uint().value_or(1));
|
||||||
pager.up_page();
|
else
|
||||||
|
pager.up();
|
||||||
|
}
|
||||||
|
} else if (sequence == "g") {
|
||||||
|
if (!modifier_buffer.is_empty())
|
||||||
|
pager.go_to_line(modifier_buffer.build().to_uint().value());
|
||||||
|
else
|
||||||
|
pager.top();
|
||||||
|
} else if (sequence == "G") {
|
||||||
|
if (!modifier_buffer.is_empty())
|
||||||
|
pager.go_to_line(modifier_buffer.build().to_uint().value());
|
||||||
|
else
|
||||||
|
pager.bottom();
|
||||||
|
} else if (sequence == " " || sequence == "\e[6~") {
|
||||||
|
pager.down_page();
|
||||||
|
} else if (sequence == "\e[5~") {
|
||||||
|
pager.up_page();
|
||||||
|
} else if (sequence == "d") {
|
||||||
|
pager.down_half_page();
|
||||||
|
} else if (sequence == "u") {
|
||||||
|
pager.up_half_page();
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier_buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quit_at_eof && pager.at_end())
|
if (quit_at_eof && pager.at_end())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue