diff --git a/pgactivity/colors.py b/pgactivity/colors.py index 47e84190..d6466a6c 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", + "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", }, } diff --git a/pgactivity/views.py b/pgactivity/views.py index 5a47821b..9963142c 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 eca49b68..bcfb3b08 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 1b0e568f..65c3af8a 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_*() --------------------