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

color formating of the output #558

Open
lorcat opened this issue Sep 21, 2022 · 4 comments
Open

color formating of the output #558

lorcat opened this issue Sep 21, 2022 · 4 comments

Comments

@lorcat
Copy link

lorcat commented Sep 21, 2022

Hi! Many thanks for qtconsole. Myself and our users are using it almost every day.
There is one thing I would like to ask, maybe there is a way, but I could not find it in documentation.

I would like to have a control of custom color text output of the commands. If in linux terminal one could use special \e[1;31m
In qtconsole I do not see a simple way. Could someone guide me here?

@ccordoba12
Copy link
Collaborator

Hey @lorcat, thanks for reporting. I don't understand what you mean by this

I would like to have a control of custom color text output of the commands

Could you post a screenshot to better understand your point?

@wmvanvliet
Copy link
Contributor

wmvanvliet commented Sep 23, 2022

This is how I understood the question:

In the terminal, one can use the special ANSI color codes (e.g. \e[1;31m) to set the current color of the text. You can use this to add colors to your text output. Does QtConsole support ANSI?

I think QtConsole does support ANSI codes to some degree. For example, this works:

print("\033[1;32;40m Bright Green  \n")

To work more easily with colors, python ships with the colorama module. Try this:

import colorama
from colorama import Fore
# strip=False disables some windows specific conversion that qtconsole doesn't support
colorama.init(strip=False)
print(Fore.GREEN + 'This text is in green')

@lorcat
Copy link
Author

lorcat commented Sep 23, 2022

Hi! Sorry for the late response. Yes, the question would be - is there a way to control color output of the text within the qtconsole similar to what is done in linux terminal.

I see that stuff output within logging.error() or warning is highlighted in red, info() comes in blue.

Can we control individual colors like here:
pic

@jsbautista
Copy link
Contributor

The output behavior in qtconsole depends on the selected syntax style. To ensure consistent parsing and formatting of output, you can generate output via the print function. For example, you can format your text with ANSI escape codes like this:
python:
print('\033[1;33m This is an example of green text.')

image

This method allows you to control the appearance of the text in the console.

Additionally, various PRs have been developed, for example to achieve the correct yellow color with ansi codes
(Change ANSI color code 3 mapping from brown to gold and set bold format processing enabled by default by jsbautista · Pull Request #611 · jupyter/qtconsole (github.com))

image

and to further expand the color standardization when selecting a style in qtconsole(Use selected syntax style for tracebacks and improve ANSI color codes support by jsbautista · Pull Request #608 · jupyter/qtconsole (github.com)).

AfterQtConsole
AfterQtConsolea

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

No branches or pull requests

4 participants