Fix missing last line when getting output of the running command

This commit is contained in:
pagedown 2022-07-02 12:33:58 +08:00
parent 4ed413eaa7
commit 6c80cd040c
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
2 changed files with 15 additions and 7 deletions

View File

@ -2828,7 +2828,7 @@ find_cmd_output(Screen *self, OutputOffset *oo, index_type start_screen_y, unsig
if (found_next_prompt) { if (found_next_prompt) {
oo->num_lines = end >= start ? end - start : 0; oo->num_lines = end >= start ? end - start : 0;
} else if (found_output) { } else if (found_output) {
end = direction < 0 ? init_y : downward_limit; end = (direction < 0 ? MIN(init_y, downward_limit) : downward_limit) + 1;
oo->num_lines = end >= start ? end - start : 0; oo->num_lines = end >= start ? end - start : 0;
} else return false; } else return false;
oo->start = start; oo->start = start;

View File

@ -1031,7 +1031,7 @@ class TestScreen(BaseTest):
s.draw('abcd'), s.index(), s.carriage_return() s.draw('abcd'), s.index(), s.carriage_return()
s.draw('12'), s.index(), s.carriage_return() s.draw('12'), s.index(), s.carriage_return()
self.ae(fco(), '') self.ae(fco(), '')
self.ae(lco(), 'abcd\n12') self.ae(lco(), 'abcd\n12\n')
s = self.create_screen() s = self.create_screen()
mark_prompt(), s.draw('$ 0') mark_prompt(), s.draw('$ 0')
s.carriage_return(), s.index() s.carriage_return(), s.index()
@ -1061,12 +1061,12 @@ class TestScreen(BaseTest):
# last cmd output # last cmd output
# test: find upwards # test: find upwards
self.ae(s.scrolled_by, 0) self.ae(s.scrolled_by, 0)
self.ae(lco(), '0x\n1x') self.ae(lco(), '0x\n1x\n')
# get output after scroll up # get output after scroll up
s.scroll_to_prompt() s.scroll_to_prompt()
self.ae(s.scrolled_by, 4) self.ae(s.scrolled_by, 4)
self.ae(str(s.visual_line(0)), '$ 0') self.ae(str(s.visual_line(0)), '$ 0')
self.ae(lco(), '0x\n1x') self.ae(lco(), '0x\n1x\n')
# first cmd output on screen # first cmd output on screen
# test: find around # test: find around
@ -1074,11 +1074,11 @@ class TestScreen(BaseTest):
s.scroll(2, False) s.scroll(2, False)
self.ae(s.scrolled_by, 2) self.ae(s.scrolled_by, 2)
self.ae(str(s.visual_line(0)), '1') self.ae(str(s.visual_line(0)), '1')
self.ae(fco(), '0x\n1x') self.ae(fco(), '0x\n1x\n')
# test: find downwards # test: find downwards
s.scroll(2, False) s.scroll(2, False)
self.ae(str(s.visual_line(0)), '$ 1') self.ae(str(s.visual_line(0)), '$ 1')
self.ae(fco(), '0x\n1x') self.ae(fco(), '0x\n1x\n')
# resize # resize
# get last cmd output with continued output mark # get last cmd output with continued output mark
@ -1086,13 +1086,21 @@ class TestScreen(BaseTest):
s.resize(4, 5) s.resize(4, 5)
s.scroll_to_prompt(-4) s.scroll_to_prompt(-4)
self.ae(str(s.visual_line(0)), '$ 0') self.ae(str(s.visual_line(0)), '$ 0')
self.ae(lco(), '0long_line\n0l\n1l') self.ae(lco(), '0long_line\n0l\n1l\n')
# last visited cmd output # last visited cmd output
self.ae(lvco(), '0\n1\n2') self.ae(lvco(), '0\n1\n2')
s.scroll_to_prompt(1) s.scroll_to_prompt(1)
self.ae(lvco(), '0x\n1x') self.ae(lvco(), '0x\n1x')
# last command output without line break
s = self.create_screen(cols=10, lines=3)
draw_prompt('p1')
mark_output(), s.draw('running')
self.ae(lco(), 'running')
s.index(), s.carriage_return()
self.ae(lco(), 'running\n')
# last command output from pager history # last command output from pager history
s = self.create_screen() s = self.create_screen()
draw_prompt('p1') draw_prompt('p1')