Skip to content

Potential for ANSI colours to remain active #488

Closed

Description

@d7919

In _step of logger, the colour remains active after the line is displayed, i.e. it is not reset.

return "| " + " | ".join([colour + cells[i] for i in range(len(cells))]) + " |"

If the user's function has any output or if the system displays any output this will inherit the colour of the last output. This can also potentially cause issues if the user kills the job mid-run leaving the colour code active.

Changing this line to

return "| " + " | ".join([colour + cells[i] + Fore.RESET for i in range(len(cells))]) + " |" 

is perhaps a bit "safer" and has the minor advantage of not colouring the | column separators.

On a side note, it would be helpful if the user could:

  1. Turn off the colouring (if capturing output the escape codes can enter the log file).
  2. Choose the two colours in use -- for me the default Black is unreadable due to the colour of my terminal background.

Activity

  1. t-muser commented on Jul 5, 2024

    @t-muser
    Member

    Hi @d7919,

    regarding the cause for the issue, good catch, this should indeed be fixed. Thanks for providing a PR!

    side note

    you raise some good points:

    Choose the two colours in use -- for me the default Black is unreadable due to the colour of my terminal background.

    I think it would make sense to replace Fore.BLACK with Fore.RESET in general. What do you think? This would probably alleviate the issue for most cases and be relatively low effort. However, if you feel strongly about making the ScreenLogger more flexible/customizable (turning colours off or using different colours), and are willing submit a PR for this, I will gladly review and merge it :)

  2. t-muser commented on Jul 10, 2024

    @t-muser
    Member

    I will close this for now

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions