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

Colors + text styles on terminal output #10

Closed
urish opened this issue Jul 11, 2024 · 4 comments
Closed

Colors + text styles on terminal output #10

urish opened this issue Jul 11, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@urish
Copy link
Member

urish commented Jul 11, 2024

A bunch of useful functions that enable prettier terminal output. I propose to include those in the SDK, so projects can use colors / text styles in their output:

def bold(s):
    return f"\033[1m{s}\033[0m"

def underline(s):
    return f"\033[4m{s}\033[0m"

def inverse(s):
    return f"\033[7m{s}\033[0m"

def color(s, color, bright = True):
    COLORS = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
    code= str(COLORS.index(color))
    suffix = ";1" if bright else ""
    return f"\033[3{code}{suffix}m{s}\033[0m"

These functions can be chained to combine styles.

Usage examples:

print(f"I have to tell you something {bold('important')}!")
print(f"There was an {color('error', 'red')} in your input");
print(f"Here is how I combine {inverse(underline(color("multiple", "magenta")))} styles")
@urish urish added the enhancement New feature or request label Jul 11, 2024
@psychogenic
Copy link
Collaborator

Nice.
Including. Used in logging. Added a global flag to module to disable (for writing out clean files or whatever)
logout

@rtfb
Copy link

rtfb commented Sep 11, 2024

Hey @psychogenic, this commit (ccbc6fc) added the usage of colors, but didn't add anything to src/ttboard/util/. Did you forget to add a file?

@psychogenic
Copy link
Collaborator

Did you forget to add a file?

Durp, yes. Sorry about that.

It actually wound up getting submitted as part of a commit in the TT06 branch I'm working on, https://github.com/TinyTapeout/tt-micropython-firmware/blob/tt06/src/ttboard/util/colors.py

I'm getting ready to merge that all into main and don't wanna deal with the conflict of having it in both, so get it above if you need it right away.

@rtfb
Copy link

rtfb commented Sep 11, 2024

No worries, in my case I just commented out its usage. Good that it's coming in soon.

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

No branches or pull requests

3 participants