Skip to content
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

Fix scrolling when wrapping is involved #257

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 78 additions & 11 deletions pgactivity/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,142 @@


FIELD_BY_MODE = {
"pid": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"pid": {
"default": "cyan",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"database": {
"default": "black_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"application_name": {
"default": "black_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"user": {
"default": "black_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"client": {
"default": "cyan",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"cpu": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"mem": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"read": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"write": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"time_red": {
"default": "red",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"client": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"cpu": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"mem": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"read": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"write": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"time_red": {"default": "red", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"time_yellow": {
"default": "yellow",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"time_green": {
"default": "green",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"wait_green": {
"default": "green_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"wait_red": {
"default": "red_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"state_default": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"state_yellow": {
"default": "yellow",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"state_green": {
"default": "green",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"state_red": {
"default": "red",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"query": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"relation": {
"default": "cyan",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"type": {
"default": "normal",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"state_red": {"default": "red", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"query": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"relation": {"default": "cyan", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"type": {"default": "normal", "cursor": "cyan_reverse", "yellow": "yellow_bold"},
"mode_yellow": {
"default": "yellow_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
"mode_red": {
"default": "red_bold",
"cursor": "cyan_reverse",
"cursor_selected": "cyan3_reverse_bold",
"yellow": "yellow_bold",
},
}
Expand Down
16 changes: 7 additions & 9 deletions pgactivity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,16 @@ def cell(

focused, pinned = processes.focused, processes.pinned

# Scrolling is handeled here. we just have to manage the start position of the display.
# the length is managed by @limit. we try to have a 5 line leeway at the bottom of the
# page to increase readability.
position = processes.position()
start = 0
bottom = int(maxlines // 5)
if position is not None and position >= maxlines - bottom:
start = position - maxlines + 1 + bottom
# Scrolling is handeled here. The first line we display is always the one
# with the focus. This choice was made to make it easier to manage the non
# truncated modes. The length is managed by the decorator @limit.
start = processes.position()

for process in processes[start:]:

if process.pid == focused:
if process.pid == focused and process.pid in pinned:
color_type = "cursor_selected"
elif process.pid == focused:
color_type = "cursor"
elif process.pid in pinned:
color_type = "yellow"
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ PostgreSQL ... - test - postgres@127.0.0.1:.../tests - Ref.: 2s
Size: 106.07M - 0B/s ⋅ TPS: 0 ⋅ Active connections: 2 ⋅ Duration mode: query
RUNNING QUERIES
PID DATABASE state Query
... tests idle in trans SELECT 43
... tests idle in trans UPDATE t SET s = 'blocking'
... tests active UPDATE t SET s = 'waiting'
<BLANKLINE>
Expand All @@ -996,7 +995,6 @@ PostgreSQL ... - test - postgres@127.0.0.1:.../tests - Ref.: 2s
Size: 106.07M - 0B/s ⋅ TPS: 0 ⋅ Active connections: 2 ⋅ Duration mode: query
RUNNING QUERIES
PID DATABASE state Query
... tests idle in trans SELECT 43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes in tests? Is it related to the scrolling issue mentioned in my other comment?

Copy link
Collaborator Author

@blogh blogh Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the line is outside the screen.

... tests idle in trans UPDATE t SET s = 'blocking'
... tests active UPDATE t SET s = 'waiting'
<BLANKLINE>
Expand Down
30 changes: 0 additions & 30 deletions tests/test_views.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@ Tests scrolling in processes_rows()
9
>>> lc = line_counter(5)
>>> processes_rows(term, ui, sproc, lc.value, width=200, lines_counter=lc)
6 pgbench active SELECT 6
7 pgbench active SELECT 7
8 pgbench active SELECT 8
9 pgbench active SELECT 9
>>> _ = sproc.focus_next()
>>> sproc.position()
Expand All @@ -394,33 +391,6 @@ Tests scrolling in processes_rows()
2 pgbench active SELECT 2
3 pgbench active SELECT 3
4 pgbench active SELECT 4
>>> for x in range(9):
... _ = sproc.focus_next()
>>> sproc.position()
9

We never put the focus on the lower 1/5th of the screen.
For 5 display lines, the focus will be on the 4th .

>>> lc = line_counter(5)
>>> processes_rows(term, ui, sproc, lc.value, width=200, lines_counter=lc)
6 pgbench active SELECT 6
7 pgbench active SELECT 7
8 pgbench active SELECT 8
9 pgbench active SELECT 9

For 10 display lines, it should be at 8th line.

>>> lc = line_counter(10)
>>> processes_rows(term, ui, sproc, lc.value, width=200, lines_counter=lc)
2 pgbench active SELECT 2
3 pgbench active SELECT 3
4 pgbench active SELECT 4
5 pgbench active SELECT 5
6 pgbench active SELECT 6
7 pgbench active SELECT 7
8 pgbench active SELECT 8
9 pgbench active SELECT 9

Tests for footer_*()
--------------------
Expand Down