Skip to content

Commit

Permalink
Fix scrolling when wrapping is involved
Browse files Browse the repository at this point in the history
With a wrapped display mode the current display is bugged. If some
queries are wrapped before the line we put the focus on. It's possible
that the said line is out of the screen.

With this patch, the line with the focus is the always the first one.

When a the focus is on a selected line, the text is now bold with a
lighter brand of cyan. It is otherwise difficult to see if the first
ligne of the display is selected since it always has the focus.
  • Loading branch information
blogh committed Dec 13, 2021
1 parent 9954775 commit c87f831
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 52 deletions.
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", "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"},
"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"
},
"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", "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"},
"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"
},
"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
... 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

0 comments on commit c87f831

Please sign in to comment.