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

Backport and modify canvas customization from rtorrent-ps #119

Closed
chros73 opened this issue Mar 18, 2018 · 3 comments
Closed

Backport and modify canvas customization from rtorrent-ps #119

chros73 opened this issue Mar 18, 2018 · 3 comments

Comments

@chros73
Copy link
Owner

chros73 commented Mar 18, 2018

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 value
  • string.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 info
  • d.tracker_scrape.complete scrape info
  • d.tracker_scrape.incomplete scrape info
  • d.parent_dir to get the name of the parent directory of a download
  • convert.human_size used in upload data, data size columns
  • convert.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 column
  • d.ui.completion to return formatted text for completion column
  • d.ui.ratio to return formatted text for ratio column
  • d.ui.uprate_tm to return formatted text for uprate/last_active_time column
  • d.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, "⊻"}))
  • 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.

chros73 pushed a commit that referenced this issue Apr 2, 2018
chros73 pushed a commit that referenced this issue Apr 2, 2018
@chros73 chros73 changed the title Backport canvas customization from rtorrent-ps Backport and modify canvas customization from rtorrent-ps Apr 2, 2018
@chros73 chros73 added this to the 1.6.3-0.9.7 milestone Apr 3, 2018
chros73 pushed a commit that referenced this issue Apr 3, 2018
@chros73
Copy link
Owner Author

chros73 commented Apr 5, 2018

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 value
  • string.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 info
  • d.tracker_scrape.complete scrape info
  • d.tracker_scrape.incomplete scrape info
  • d.parent_dir to get the name of the parent directory of a download
  • convert.human_size used in upload data, data size columns
  • convert.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 column
  • d.ui.completion to return formatted text for completion column
  • d.ui.ratio to return formatted text for ratio column
  • d.ui.uprate_tm to return formatted text for uprate/last_active_time column
  • d.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, "⊻"}))
  • 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

c. changing width of couple of old columns

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
  • this line isn't needed since it's overridden by this

@pyroscope
Copy link

BTW, using #L links with "master" is pretty useless, since lines changeover time. #L only makes sense with SHAs.

@chros73
Copy link
Owner Author

chros73 commented May 28, 2018

Sorry about the confusion, you're right, sometimes I'm in a rush (especially when I have to deal with documentation :) ). Fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants