From c87f831015e395ccd2968ba457ceec3e43046d15 Mon Sep 17 00:00:00 2001 From: benoit Date: Thu, 2 Dec 2021 15:18:19 +0100 Subject: [PATCH] Fix scrolling when wrapping is involved 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. --- pgactivity/colors.py | 89 ++++++++++++++++++++++++++++++++++++++------ pgactivity/views.py | 16 ++++---- tests/test_ui.txt | 2 - tests/test_views.txt | 30 --------------- 4 files changed, 85 insertions(+), 52 deletions(-) diff --git a/pgactivity/colors.py b/pgactivity/colors.py index 47e84190a..284c22d9b 100644 --- a/pgactivity/colors.py +++ b/pgactivity/colors.py @@ -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", }, } diff --git a/pgactivity/views.py b/pgactivity/views.py index 5a47821b3..9963142ce 100644 --- a/pgactivity/views.py +++ b/pgactivity/views.py @@ -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" diff --git a/tests/test_ui.txt b/tests/test_ui.txt index eca49b681..bcfb3b08b 100644 --- a/tests/test_ui.txt +++ b/tests/test_ui.txt @@ -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' @@ -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' diff --git a/tests/test_views.txt b/tests/test_views.txt index 1b0e568fe..65c3af8a0 100644 --- a/tests/test_views.txt +++ b/tests/test_views.txt @@ -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() @@ -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_*() --------------------