Various improvements in usage of Rich in Red #4726

Merged
Jackenmen merged 37 commits from V3/rich_improvements into V3/develop 2021-02-11 22:20:10 +01:00
Jackenmen commented 2021-01-12 13:14:43 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Will fix #4702 once this PR gets finished.

Done:

  • Add some flags to improve configurability
    • --rich-traceback-extra-lines which allows setting the number of additional lines of code before and after the executed line that should be shown in traceback generated by Rich (defaults to 0 which means showing only one line per stack level, similarly to regular Python tracebacks
    • --rich-traceback-show-locals which allows to enable showing local variables in tracebacks generated by Rich which can be useful when developing for Red
    • ???
  • Decide on the right colors for everything
    • [/] Make a syntax theme that doesn't look horrible while still being visible in most common terminals
      • this is debatable, but I think I mostly reached that goal
      • when we can, we just use the Monokai theme however, that's not possible for old Command Prompt and Mac OS's Terminal
    • Ensure all used colors are visible in most common terminals
      • Windows
        • CMD
        • [/] (not as important) PowerShell
      • Linux
        • tty console (the one you see on Linux installations without any graphical interface)
        • LXTerminal with Raspberry Pi OS's color scheme
        • (not as important) KDE Konsole
        • (not as important) Gnome Terminal with Ubuntu's color scheme
      • [/] Mac
        • [/] Terminal
  • Use Rich's default global console object instead of making one for the bot object
  • Bump Rich to the latest version
  • Disable indent guides in traceback (flare's suggestion)
  • Skip empty lines between stack levels in traceback rendering (makes the traceback take fewer rows in the terminal)
  • Use full width of the terminal when printing traceback (I think pretty much everyone has a problem with that, which is not surprising lol)
  • Disable syntax highlighting on the log messages (let's be honest, it's just too colorful and the highlighting isn't particularly great either...); tracebacks still have syntax highlighting
  • Make logger level bold, adjust various stuff about text formatting in loggers
  • Show only one line per stack level in tracebacks by default (made configurable with a --rich-traceback-extra-lines flag)
  • Prevent Rich's console output from being redirected in Dev cog
  • Remove usage of Colorama from our code base completely
  • Stop highlighting (bolding) (_) in Red-DiscordBot splash
  • Fix the first row being bolded in tables under the splash

Notes:
Bold on Windows isn't actually bold, Windows instead uses a different shade of the color when text is bolded.

### Type - [x] Bugfix - [x] Enhancement - [x] New feature ### Description of the changes Will fix #4702 once this PR gets finished. Done: - [x] Add some flags to improve configurability - [x] `--rich-traceback-extra-lines` which allows setting the number of additional lines of code before and after the executed line that should be shown in traceback generated by Rich (defaults to 0 which means showing only one line per stack level, similarly to regular Python tracebacks - [x] `--rich-traceback-show-locals` which allows to enable showing local variables in tracebacks generated by Rich which can be useful when developing for Red - [ ] ??? - [x] Decide on the right colors for everything - [/] Make a syntax theme that doesn't look horrible while still being visible in most common terminals - this is debatable, but I think I mostly reached that goal - when we can, we just use the Monokai theme however, that's not possible for old Command Prompt and Mac OS's Terminal - [x] Ensure all used colors are visible in most common terminals - [x] Windows - [x] CMD - [/] (not as important) PowerShell - [x] Linux - [x] tty console (the one you see on Linux installations without any graphical interface) - [x] LXTerminal with Raspberry Pi OS's color scheme - [x] (not as important) KDE Konsole - [x] (not as important) Gnome Terminal with Ubuntu's color scheme - [/] Mac - [/] Terminal - [x] Use Rich's default global console object instead of making one for the bot object - [x] Bump Rich to the latest version - [x] Fixed line pointer in tracebacks not rendering on the old Command Prompt (https://github.com/willmcgugan/rich/pull/911) - [x] Colors in the output from Rich can now be completely disabled with `NO_COLOR` environment variable - [x] Disable indent guides in traceback (flare's suggestion) - [x] Skip empty lines between stack levels in traceback rendering (makes the traceback take fewer rows in the terminal) - [x] Use full width of the terminal when printing traceback (I think pretty much everyone has a problem with that, which is not surprising lol) - [x] Disable syntax highlighting on the log messages (let's be honest, it's just too colorful and the highlighting isn't particularly great either...); tracebacks still have syntax highlighting - [x] Make logger level bold, adjust various stuff about text formatting in loggers - [x] Show only one line per stack level in tracebacks by default (made configurable with a `--rich-traceback-extra-lines` flag) - [x] Prevent Rich's console output from being redirected in Dev cog - [x] Remove usage of Colorama from our code base completely - [x] Stop highlighting (bolding) `(_)` in Red-DiscordBot splash - [x] Fix the first row being bolded in tables under the splash Notes: Bold on Windows isn't actually bold, Windows instead uses a different shade of the color when text is bolded.
Jackenmen commented 2021-01-15 00:25:52 +01:00 (Migrated from github.com)

Figuring out the right colors for everything in Rich so that it is all readable on the most common terminals (see the list in the issue description) is the only thing left to do here but it's also the most troublesome one. I'll be trying to look into it in the coming days, but I would appreciate all the help with figuring out something that looks acceptable and is not hard to see on different applications. Hopefully, we'll figure something out :/

Figuring out the *right* colors for everything in Rich so that it is all readable on the most common terminals (see the list in the issue description) is the only thing left to do here but it's also the most troublesome one. I'll be trying to look into it in the coming days, but I would appreciate all the help with figuring out something that looks acceptable and is not hard to see on different applications. Hopefully, we'll figure something out :/
Jackenmen commented 2021-01-17 11:25:02 +01:00 (Migrated from github.com)

I can't really test colors on Mac OS X so I would appreciate it if someone could run the bash script below.

Little code pieces for testing the standard 8 colors and their bright and bolded variants:
Unix:

#!/bin/bash

TEXT='gYw';

for i in {0..7}
do
    for option in '3' '9' '1;3'
    do
        echo -en "\033[$option${i}m$TEXT\033[0m    ";
    done
    echo;
done

Windows (should work on both CMD and PowerShell):

@echo off
set TEXT=gYw
for /F "delims=#" %%a in ('prompt #$E# ^& for %%a in ^(1^) do rem') do set "ESC=%%a"

for /L %%i in (0,1,7) do (
    for %%o IN ("3" "9" "1;3") do (
        cmd /C exit /b 27
        <nul (set /p z="%ESC%[%%~o%%im%TEXT%%ESC%[0m    ")
    )
    echo:
)
I can't really test colors on Mac OS X so I would appreciate it if someone could run the bash script below. **Little code pieces for testing the standard 8 colors and their bright and bolded variants:** Unix: ```bash #!/bin/bash TEXT='gYw'; for i in {0..7} do for option in '3' '9' '1;3' do echo -en "\033[$option${i}m$TEXT\033[0m "; done echo; done ``` Windows (should work on both CMD and PowerShell): ```bat @echo off set TEXT=gYw for /F "delims=#" %%a in ('prompt #$E# ^& for %%a in ^(1^) do rem') do set "ESC=%%a" for /L %%i in (0,1,7) do ( for %%o IN ("3" "9" "1;3") do ( cmd /C exit /b 27 <nul (set /p z="%ESC%[%%~o%%im%TEXT%%ESC%[0m ") ) echo: ) ```
Jackenmen commented 2021-01-17 11:48:57 +01:00 (Migrated from github.com)

Default color scheme screenshots

Most important terminals

Default color scheme screenshots
Windows - CMD:
image
Linux - tty console
image
Linux - LXTerminal with Raspberry Pi OS's color scheme
image
Mac - Terminal (Catalina)
image
Mac - Terminal (supposedly, Big Sur on dark mode)
image

Less important terminals

Windows - PowerShell:
image
Linux - LXTerminal with its default color scheme
image
Linux - KDE Konsole
image
Linux - Gnome Terminal with Ubuntu's color scheme
image
Linux - Gnome Terminal with its default color scheme
image
Linux - xterm
image

And last but not least...
Cool Retro Term! :D
image

Default color scheme screenshots <details> <summary>Most important terminals</summary> **Default color scheme screenshots** Windows - CMD: ![image](https://user-images.githubusercontent.com/6032823/104838051-c65ad380-58b8-11eb-81ba-6a57184f5618.png) Linux - tty console ![image](https://user-images.githubusercontent.com/6032823/104838208-b394ce80-58b9-11eb-995c-0113837196ce.png) Linux - LXTerminal with Raspberry Pi OS's color scheme ![image](https://user-images.githubusercontent.com/6032823/104839629-957f9c00-58c2-11eb-92cd-6684496ffba5.png) Mac - Terminal (Catalina) ![image](https://user-images.githubusercontent.com/6032823/104847252-3a0fd700-58df-11eb-9159-aaca0078aeb5.png) Mac - Terminal (supposedly, Big Sur on dark mode) ![image](https://user-images.githubusercontent.com/6032823/104838643-97def780-58bc-11eb-87e2-43529256e6f9.png) </details> <details> <summary>Less important terminals</summary> Windows - PowerShell: ![image](https://user-images.githubusercontent.com/6032823/104838063-d8d50d00-58b8-11eb-8121-ae6ffff3202f.png) Linux - LXTerminal with its default color scheme ![image](https://user-images.githubusercontent.com/6032823/104838723-176cc680-58bd-11eb-9341-9a4b624880e9.png) Linux - KDE Konsole ![image](https://user-images.githubusercontent.com/6032823/104838103-18035e00-58b9-11eb-9b63-1ec8529e488a.png) Linux - Gnome Terminal with Ubuntu's color scheme ![image](https://user-images.githubusercontent.com/6032823/104838444-42eeb180-58bb-11eb-9334-7db99b2ed2c0.png) Linux - Gnome Terminal with its default color scheme ![image](https://user-images.githubusercontent.com/6032823/104842843-b26a9e00-58c7-11eb-9982-d027fad1b828.png) Linux - xterm ![image](https://user-images.githubusercontent.com/6032823/104839135-8f3bf080-58bf-11eb-9cf8-4a3b907a3d15.png) </details> And last but not least... Cool Retro Term! :D ![image](https://user-images.githubusercontent.com/6032823/104842854-cadab880-58c7-11eb-8d1a-f249b349a513.png)
Jackenmen commented 2021-01-19 00:30:52 +01:00 (Migrated from github.com)

Here's a first take on the syntax theme colors...
Would love to hear some feedback, as I made those from scratch and I honestly don't know if these are any good, nor what should possibly be changed.

Most important terminals

Windows - CMD:
image
Linux - tty console:
image
Linux - LXTerminal with Raspberry Pi OS's color scheme:
image
Mac - Terminal:
image

Less important terminals

Windows - PowerShell:
image
Linux - LXTerminal with its default color scheme:
image
Linux - KDE Konsole:
image
Linux - Gnome Terminal with Ubuntu's color scheme:
image
Linux - Gnome Terminal with its default color scheme
image

Here's a first take on the syntax theme colors... Would love to hear some feedback, as I made those from scratch and I honestly don't know if these are any good, nor what should possibly be changed. <details> <summary>Most important terminals</summary> Windows - CMD: ![image](https://user-images.githubusercontent.com/6032823/104970624-69f8d080-59ec-11eb-8cbe-b8fbf429a25b.png) Linux - tty console: ![image](https://user-images.githubusercontent.com/6032823/104970666-9280ca80-59ec-11eb-9329-8d72264a5bce.png) Linux - LXTerminal with Raspberry Pi OS's color scheme: ![image](https://user-images.githubusercontent.com/6032823/104970683-a4626d80-59ec-11eb-8617-d25e44c5440f.png) Mac - Terminal: ![image](https://user-images.githubusercontent.com/6032823/104970764-dd024700-59ec-11eb-9b16-a625139ae99a.png) </details> <details> <summary>Less important terminals</summary> Windows - PowerShell: ![image](https://user-images.githubusercontent.com/6032823/104970825-11760300-59ed-11eb-9926-00afaf117f07.png) Linux - LXTerminal with its default color scheme: ![image](https://user-images.githubusercontent.com/6032823/104970838-22bf0f80-59ed-11eb-8396-19092839770c.png) Linux - KDE Konsole: ![image](https://user-images.githubusercontent.com/6032823/104970911-674aab00-59ed-11eb-906f-cc7c61d84015.png) Linux - Gnome Terminal with Ubuntu's color scheme: ![image](https://user-images.githubusercontent.com/6032823/104970850-2c487780-59ed-11eb-9ae2-44d3847dbd62.png) Linux - Gnome Terminal with its default color scheme ![image](https://user-images.githubusercontent.com/6032823/104970864-3bc7c080-59ed-11eb-80a5-2c3e76cd38f1.png) </details>
Drapersniper commented 2021-01-19 01:10:18 +01:00 (Migrated from github.com)

The bright cyan on mac default (white) is difficult to read and hard on the eye. Other than that everything else is looking good

The bright cyan on mac default (white) is difficult to read and hard on the eye. Other than that everything else is looking good
Jackenmen commented 2021-01-19 17:55:46 +01:00 (Migrated from github.com)

I made the proposed changes and here are screenshots of the updated color scheme on different terminals.

Most important terminals

Windows - CMD:
image
Linux - tty console:
image
Linux - LXTerminal with Raspberry Pi OS's color scheme:
image
Mac - Terminal:
image

Less important terminals

Windows - PowerShell:
image
Linux - LXTerminal with its default color scheme:
image
Linux - KDE Konsole:
image
Linux - Gnome Terminal with Ubuntu's color scheme:
image
Linux - Gnome Terminal with its default color scheme:
image
Linux - Cool Retro Term :D
image

If this looks alright, I'll proceed with getting screenshots of the whole Rich output on different terminals, including truecolor monokai color scheme on terminals that support it.

I made the proposed changes and here are screenshots of the updated color scheme on different terminals. <details> <summary>Most important terminals</summary> Windows - CMD: ![image](https://user-images.githubusercontent.com/6032823/105066566-387d1500-5a7f-11eb-9319-8db12d005711.png) Linux - tty console: ![image](https://user-images.githubusercontent.com/6032823/105066510-2a2ef900-5a7f-11eb-9fba-f7c42f22591c.png) Linux - LXTerminal with Raspberry Pi OS's color scheme: ![image](https://user-images.githubusercontent.com/6032823/105066428-184d5600-5a7f-11eb-9c08-18e322089f42.png) Mac - Terminal: ![image](https://user-images.githubusercontent.com/6032823/105066608-429f1380-5a7f-11eb-8d72-f7c635b219d9.png) </details> <details> <summary>Less important terminals</summary> Windows - PowerShell: ![image](https://user-images.githubusercontent.com/6032823/105066541-32873400-5a7f-11eb-8dd5-ac53ebad5794.png) Linux - LXTerminal with its default color scheme: ![image](https://user-images.githubusercontent.com/6032823/105066348-0c619400-5a7f-11eb-8c30-7aac79536ae3.png) Linux - KDE Konsole: ![image](https://user-images.githubusercontent.com/6032823/105066312-07044980-5a7f-11eb-9de5-f308daa8bb86.png) Linux - Gnome Terminal with Ubuntu's color scheme: ![image](https://user-images.githubusercontent.com/6032823/105066453-1c797380-5a7f-11eb-8315-d718870aca3b.png) Linux - Gnome Terminal with its default color scheme: ![image](https://user-images.githubusercontent.com/6032823/105066390-12f00b80-5a7f-11eb-8826-bfd6b862f170.png) Linux - Cool Retro Term :D ![image](https://user-images.githubusercontent.com/6032823/105066475-200cfa80-5a7f-11eb-98d8-b51288d74551.png) </details> If this looks alright, I'll proceed with getting screenshots of the whole Rich output on different terminals, including truecolor monokai color scheme on terminals that support it.
Jackenmen commented 2021-01-19 20:53:00 +01:00 (Migrated from github.com)

I prepared a script that produces output using our styles and Red-like messages which can be used to produce repeatable output without having to install Red in whole. I'll be checking this on all the different terminals which I've already been presenting above. If the used terminal supports true colors, the screenshots will be generated for both the true color variant and the standard 16 colors variant.

https://gist.github.com/jack1142/302f2f4650eab57776b528aae98219fb

I'll be coming with another update soon™

I prepared a script that produces output using our styles and Red-like messages which can be used to produce repeatable output without having to install Red in whole. I'll be checking this on all the different terminals which I've already been presenting above. If the used terminal supports true colors, the screenshots will be generated for both the true color variant and the standard 16 colors variant. https://gist.github.com/jack1142/302f2f4650eab57776b528aae98219fb I'll be coming with another update soon™
Jackenmen commented 2021-01-20 00:17:12 +01:00 (Migrated from github.com)

Alright, here it is... Red output with Rich tables, logging, colors on all terminals that I've been posting screenshots for before.

Most important terminals
  • Windows - CMD
    image
  • Linux - tty console
    image
  • Linux - LXTerminal with Raspberry Pi OS's color scheme
    • True color support enabled
      image
    • True color support disabled
      image
  • Mac - Terminal
    image
Less important terminals
  • Windows - PowerShell:
    image
  • Linux - LXTerminal with its default color scheme:
    • True color support enabled
      image
    • True color support disabled
      image
  • Linux - KDE Konsole:
    • True color support enabled
      image
    • True color support disabled
      image
  • Linux - Gnome Terminal with Ubuntu's color scheme:
    • True color support enabled
      image
    • True color support disabled
      image
  • Linux - Gnome Terminal with its default color scheme:
    • True color support enabled
      image
    • True color support disabled
      image
  • Linux - Cool Retro Term :D
    Screenshot from 2021-01-19 22-28-49
Alright, here it is... Red output with Rich tables, logging, colors on all terminals that I've been posting screenshots for before. <details> <summary>Most important terminals</summary> - Windows - CMD ![image](https://user-images.githubusercontent.com/6032823/105105260-0934cb00-5ab4-11eb-9ec3-1435851b5d32.png) - Linux - tty console ![image](https://user-images.githubusercontent.com/6032823/105105229-f4583780-5ab3-11eb-85a8-4ca704da2440.png) - Linux - LXTerminal with Raspberry Pi OS's color scheme - True color support enabled ![image](https://user-images.githubusercontent.com/6032823/105105091-af340580-5ab3-11eb-92f2-85c921b18cbf.png) - True color support disabled ![image](https://user-images.githubusercontent.com/6032823/105105120-bbb85e00-5ab3-11eb-9698-214143d25fad.png) - Mac - Terminal ![image](https://user-images.githubusercontent.com/6032823/105105138-c2df6c00-5ab3-11eb-9bf9-5dc109f08b2c.png) </details> <details> <summary>Less important terminals</summary> - Windows - PowerShell: ![image](https://user-images.githubusercontent.com/6032823/105105273-118d0600-5ab4-11eb-8787-819b8762db12.png) - Linux - LXTerminal with its default color scheme: - True color support enabled ![image](https://user-images.githubusercontent.com/6032823/105105324-31bcc500-5ab4-11eb-9a28-06e895a10db3.png) - True color support disabled ![image](https://user-images.githubusercontent.com/6032823/105105339-38e3d300-5ab4-11eb-818f-ab1711e7b17c.png) - Linux - KDE Konsole: - True color support enabled ![image](https://user-images.githubusercontent.com/6032823/105105379-48fbb280-5ab4-11eb-83f6-19414d9f1761.png) - True color support disabled ![image](https://user-images.githubusercontent.com/6032823/105105393-4e58fd00-5ab4-11eb-983b-d1868aac9542.png) - Linux - Gnome Terminal with Ubuntu's color scheme: - True color support enabled ![image](https://user-images.githubusercontent.com/6032823/105105449-64ff5400-5ab4-11eb-8313-c85693f926b7.png) - True color support disabled ![image](https://user-images.githubusercontent.com/6032823/105105480-6cbef880-5ab4-11eb-89ce-ff2a41c29ea3.png) - Linux - Gnome Terminal with its default color scheme: - True color support enabled ![image](https://user-images.githubusercontent.com/6032823/105105515-7fd1c880-5ab4-11eb-9497-32ca2a649936.png) - True color support disabled ![image](https://user-images.githubusercontent.com/6032823/105105522-84967c80-5ab4-11eb-9dbd-aacefae43440.png) - Linux - Cool Retro Term :D ![Screenshot from 2021-01-19 22-28-49](https://user-images.githubusercontent.com/6032823/105105536-8f511180-5ab4-11eb-973d-290cab4994b3.png) </details>
Jackenmen commented 2021-01-20 00:23:29 +01:00 (Migrated from github.com)

This should now be ready for review. PR description has been updated appropriately.

This should now be ready for review. PR description has been updated appropriately.
Flame442 commented 2021-02-01 23:59:54 +01:00 (Migrated from github.com)

Soft approve, I did not do a full review but this seems to work from my basic testing, and I like the changes.

Soft approve, I did not do a full review but this seems to work from my basic testing, and I like the changes.
TrustyJAID (Migrated from github.com) approved these changes 2021-02-11 22:16:01 +01:00
TrustyJAID (Migrated from github.com) left a comment

Looks good to me!

Looks good to me!
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!4726
No description provided.