-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement scroll up and down #103
base: master
Are you sure you want to change the base?
Changes from all commits
4a2dcb2
1da5b4a
f15ea30
97843a0
2e86d5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,6 +139,11 @@ def __init__(self, default): | |||||||||||||||||
def __missing__(self, key): | ||||||||||||||||||
return self.default | ||||||||||||||||||
|
||||||||||||||||||
def copy(self): | ||||||||||||||||||
new_static_default_dict = type(self)(self.default) | ||||||||||||||||||
new_static_default_dict.update(self) | ||||||||||||||||||
return new_static_default_dict | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
class Screen(object): | ||||||||||||||||||
""" | ||||||||||||||||||
|
@@ -1043,6 +1048,26 @@ def debug(self, *args, **kwargs): | |||||||||||||||||
By default is a noop. | ||||||||||||||||||
""" | ||||||||||||||||||
|
||||||||||||||||||
def scroll_up(self, lines): | ||||||||||||||||||
"""Scroll up `lines` lines.""" | ||||||||||||||||||
Comment on lines
+1051
to
+1052
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation states that a scroll with no parameters scrolls 1 line.
Suggested change
|
||||||||||||||||||
lines_to_scroll = range(self.margins.top, self.margins.bottom + 1) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should handle when margins is None.
Suggested change
|
||||||||||||||||||
for y in lines_to_scroll: | ||||||||||||||||||
if y + lines in set(lines_to_scroll): | ||||||||||||||||||
self.buffer[y] = self.buffer[y + lines].copy() | ||||||||||||||||||
else: | ||||||||||||||||||
self.buffer[y].clear() | ||||||||||||||||||
Comment on lines
+1055
to
+1058
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scrolling is similar to indexing multiple times, is it not? If we follow its example (and it may be more efficient) we can simply move the lines we want to move and pop the lines we want to erase, rather than copying and clearing the dictionaries. We can also improve efficiency by checking the bottom margin rather than creating a set to test for set inclusion.
Suggested change
|
||||||||||||||||||
self.dirty = set(lines_to_scroll) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should update the dirty set rather than replace it.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
def scroll_down(self, lines): | ||||||||||||||||||
"""Scroll down `lines` lines.""" | ||||||||||||||||||
lines_to_scroll = range(self.margins.bottom, self.margins.top - 1, -1) | ||||||||||||||||||
for y in lines_to_scroll: | ||||||||||||||||||
if y - lines in set(lines_to_scroll): | ||||||||||||||||||
self.buffer[y] = self.buffer[y - lines].copy() | ||||||||||||||||||
else: | ||||||||||||||||||
self.buffer[y].clear() | ||||||||||||||||||
self.dirty = set(lines_to_scroll) | ||||||||||||||||||
Comment on lines
+1061
to
+1069
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to scroll_up, this should also default to 1 line if the argument is unspecified. However, an argument of 0 is used to reset mouse tracking (may be xterm specific). In any case, if we get an argument of 0, we don't want to scroll at all. And if we don't get an argument we do want to scroll exactly 1 line. However, looking at the current implementation of Any other changes made to scroll_up should be appropriately mirrored here in scroll_down. |
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
class DiffScreen(Screen): | ||||||||||||||||||
""" | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the xterm documentation states that 'T' is the correct code for Scroll Down (SD), the xterm code is implemented to handle the incorrect code '^' and treats 'T' as either mouse tracking or SD (depending on the arguments).
I'm not sure how many (or if any) applications still use the incorrect code.