Backport and modify canvas customization from rtorrent-ps
Closed this issue · 3 comments
Backport and modify canvas customization from rtorrent-ps
.
A. Tasks:
Make all the columns configurable on the extended canvas except for Name and Tracker Domain columns:
- backport original canvas customization from rtorrent-ps
- add new commands
- add a multi-method for column rendering:
ui.column.render
- call those methods, order is determined by keys in the map as usual
- keys in the map encode sorting + length + column title:
sort:len:title
- chop rendered column title and contents to the specified length
- make chopping of columns UTF8-aware:
u8_chop
internal method - make x-position of columns dynamic in the code (advance by header length)
- refactor existing complicated columns into commands, to make everything configurable (
d.ui.‹name›
) except for Name and Tracker Domain column - create built-in default columns without having the need of any config file change, they can be:
- disabled via config or on-the-fly
- overridden via config or on-the-fly
- modify built-in colouring to work with certain columns
- keep track all the positions of all the columns all the time
- based on the label of columns, only these columns are colored:
⚑
,⣿
,☯
,⌬ ≀∆
,⌬ ≀∇
- coloring of other built-in/custom columns aren't supported
- keep applying color to the fixed Name and Tracker Domain columns
B. Added commands:
Basic commands:
value=«number»[,«base»]
: converts a given number with the given base (or 10 as the default) to an integer valuestring.map=text,{from,to},…
for columns that can only have couple of fixed values, e.g. throttle, unsafe_data, etc.d.tracker_scrape.downloaded
scrape infod.tracker_scrape.complete
scrape infod.tracker_scrape.incomplete
scrape infod.parent_dir
to get the name of the parent directory of a downloadconvert.human_size
used in upload data, data size columnsconvert.magnitude
used in scrape columns
The following commands return pre-formatted text for coloring purposes:
d.ui.message
to return formatted text for message/tagged columnd.ui.completion
to return formatted text for completion columnd.ui.ratio
to return formatted text for ratio columnd.ui.uprate_tm
to return formatted text for uprate/last_active_time columnd.ui.downrate_tm
to return formatted text for downrate/completed_time column
Multi-commands:
ui.column.render
multi-command to hold column definitions, usage:- to define a new column: use a new label that hasn't been used yet!
method.set_key = ui.column.render, "230:1:◎", ((string.map, ((cat, ((d.custom,unsafe_data)))), {0, " "}, {1, "⊘"}, {2, "⊗"}))
- to disable a built-in default or custom column: use the same key of the column definition with no command defined
method.set_key = ui.column.render, "100:1:☢"
- to override a built-in default column: use the same key of the column definition with a new command
method.set_key = ui.column.render, "200:1:⊘", ((string.map, ((d.throttle_name)), {"", " "}, {NULL, "∞"}, {slowup, "⊼"}, {tardyup, "⊻"}))
- to define a new column: use a new label that hasn't been used yet!
event.view.hide
,event.view.show
multi commands to call them on view changes, usage:method.set_key = event.view.hide, ~log, ((print, ((ui.current_view)), " → ", ((argument.0))))
Refers to: pyroscope#60
See Dev notes below for further info.
Dev notes:
A. Tasks:
Make all the columns configurable on the extended canvas (except for Name and Tracker Domain columns):
- backport original canvas customization from rtorrent-ps
- add new commands
- add a multi-method for column rendering:
ui.column.render
- call those methods, order is determined by keys in the map as usual
- keys in the map encode sorting + length + column title:
sort:len:title
- chop rendered column title and contents to the specified length
- make chopping of columns UTF8-aware:
u8_chop
internal method - make x-position of columns dynamic in the code (advance by header length)
- refactor existing complicated columns into commands, to make everything configurable except for Name and Tracker Domain column
d.ui.‹name›
commands that require coloring support
- create built-in default columns without having the need of any config file change, they can be:
- disabled via config or on-the-fly
- overridden via config or on-the-fly
- modify built-in colouring to work with certain columns
- keep track all the positions of all the columns all the time
- based on the label of columns, only these are colored:
⚑
,⣿
,☯
,⌬ ≀∆
,⌬ ≀∇
- coloring of other built-in/custom columns aren't supported
- keep applying color to the fixed Name and Tracker Domain columns
B. Added commands:
Basic commands:
value=«number»[,«base»]
: converts a given number with the given base (or 10 as the default) to an integer valuestring.map=text,{from,to},…
for columns that can only have couple of fixed values, e.g. throttle, unsafe_data, etc.d.tracker_scrape.downloaded
scrape infod.tracker_scrape.complete
scrape infod.tracker_scrape.incomplete
scrape infod.parent_dir
to get the name of the parent directory of a downloadconvert.human_size
used in upload data, data size columnsconvert.magnitude
used in scrape columns
The following commands return pre-formatted text for coloring purposes:
d.ui.message
to return formatted text for message/tagged columnd.ui.completion
to return formatted text for completion columnd.ui.ratio
to return formatted text for ratio columnd.ui.uprate_tm
to return formatted text for uprate/last_active_time columnd.ui.downrate_tm
to return formatted text for downrate/completed_time column
Multi-commands:
ui.column.render
multi-command to hold column definitions, usage:- define a new column:
method.set_key = ui.column.render, "230:1:◎", ((string.map, ((cat, ((d.custom,unsafe_data)))), {0, " "}, {1, "⊘"}, {2, "⊗"}))
- disable an built-in default or custom column:
method.set_key = ui.column.render, "100:1:☢"
- override an built-in default column:
method.set_key = ui.column.render, "200:1:⊘", ((string.map, ((d.throttle_name)), {"", " "}, {NULL, "∞"}, {slowup, "⊼"}, {tardyup, "⊻"}))
- define a new column:
event.view.hide
,event.view.show
multi commands to call them on view changes, usage:method.set_key = event.view.hide, ~log, ((print, ((ui.current_view)), " → ", ((argument.0))))
C. About coloring columns
a. Theory
That was the tricky part. Initially I wanted to modify the render_columns
method to do coloring there but I realized that later they will be overridden.
So the idea is to track all the positions of all the columns all the time in render_columns using a simple map for this:
- we use the label of the columns (from the column definition) as key in the map, e.g.
☢
- they are unique anyway, since we have the in-built default columns
- after that we just check whether the given label is available (column is visible)
- we have to empty this map all the time: columns can be removed on the fly
b. Limitations
- user created custom columns can't be colorized
- funky coloring effects can happen if a user overrides a colored column or create a new one with the same label
D. Replacing couple of glyphs
I had to (!) replace these glyphs ⚡ ⌚
with these ones ⋮ ⌬
on my setup.
That's actually a concerning issue.
It's a bug in PuTTY/KiTTY v0.70 (v0.69 works fine), I reported the bug to the PuTTY team.
The point is that with the wrong reported width, label rendering was off.
Since this issue doesn't relate to the actual chars, that means any user can experience such rendering problems with any (?) multibyte chars and we can't really do much about it, only telling them to change those and recompile the client.
E. Other small changes
a. column rendering changes
- header text is also chopped by the length defined in the header
- user can enter more chars than the specified length otherwise and it'd cause wrong label rendering
- column labels and their values are updated to the proper length to not to confuse users
b. fixing rendering issue with name column
- if the width of the canvas (terminal) was smaller then the width of defined columns then the name of download overwrote all the other info in the same line
- this fixes it
c. changing width of couple of old columns
- the following column widths are now
2
instead of1
(due to how chopping works)
d. fixing old coloring issue
- characters in tracker labels were colored (due to the colored columns) if canvas was small
- this commit fixes it, by
- modifying
decorate_download_title
method - and moving the calling of
decorate_download_title
method to the end of the coloring section
- modifying
- this commit fixes it, by
- this line isn't needed since it's overridden by this
BTW, using #L links with "master" is pretty useless, since lines changeover time. #L only makes sense with SHAs.
Sorry about the confusion, you're right, sometimes I'm in a rush (especially when I have to deal with documentation :) ). Fixed now.