Custerm Python Library

I recently created a Python library for terminal output. It includes a special color syntax and supports markdown. You can use it by running pip install custerm. When I initially uploaded it, I made a mistake by not linking a GitHub repository or including a README with some basic documentation. However, here’s a brief “list” of things you can do with it:

Input:

from custerm.ansi import Color
from custerm import Terminal

Terminal.print(
    '__underline__\n\n- list\n- list\n\n**bold**',
    markdown=True
)

Output:

Image

Also supports code blocks.

Input:

from custerm.ansi import Color
from custerm import Terminal

Terminal.print(
    '[GREEN]Custerm[/GREEN] [YELLOW]Test Colors[/YELLOW]',
    markdown=False
)

Output:

Image

Supported Colors:

ANSI_BLACK
ANSI_RED
ANSI_GREEN
ANSI_YELLOW
ANSI_BLUE
ANSI_MAGENTA
ANSI_CYAN
ANSI_WHITE
ANSI_BRIGHT_BLACK
ANSI_BRIGHT_RED
ANSI_BRIGHT_GREEN
ANSI_BRIGHT_YELLOW
ANSI_BRIGHT_BLUE
ANSI_BRIGHT_MAGENTA
ANSI_BRIGHT_CYAN
ANSI_BRIGHT_WHITE

(You don’t need to include ansi, as it’s auto-included when colors are applied.)

6 Likes

as far as markdown goes, this is great! Having used FORE has been a hassle for my students because they don’t recognize they need to reset the color to another color if they change it. This way, they could just close it each line they are done with it, along with a host of other features!

I have not had much experience with installing “unsupported” libraries on replit however. Is there a way to get your library on replit/do I do it like normal?

Thanks!

4 Likes

In the Shell tab, run either poetry add custerm or pip install custerm. poetry is the Replit package manager and should add stuff to your Repl’s config files. pip of course is the Python package manager and also works.

4 Likes

Seems like a cool library! Nice job!

3 Likes

Perfect, thats what I thought. I’ll have to tinker around with it when I get a chance… Honestly should be putting together a slidedeck for my upcoming computer hardware unit, but this seemed more interesting lol

Thanks!

2 Likes

Yes! This automatically resets the colors afterward. This fixes the issue of colors accidentally being used throughout the entire print, even though you didn’t want them. This is why [COLOR]test[/COLOR]. The [/COLOR] signifies the end of the color and also instructs it to reset the colors afterward, so after that syntax, it will automatically print the rest with the colors reset.

1 Like

Well, UPM is, but UPM just uses poetry,

which uses pip.

2 Likes

Does this come with a way to escape some characters while rendering others?

2 Likes

Escape what types of characters? I can update this while making sure to actually link my GitHub repo and include some minimal documentation.

2 Likes

I mean like I want to say **abc** instead of making some bold text

3 Likes

Yeah, you would just do markdown=False.

I just read it again. Currently, you can use markdown=False, but that disables all rendering. You asked if there’s a way to disable some types while enabling the rest. I can work on this; maybe something like this:

from custerm import Terminal

Terminal.print(
    '**allowed**\n\n__disallowed__',
    markdown=True,
    allowed=['bold'],
    disabled=['underline']
)

By default, if allowed and disabled are empty, it will allow all types of markdown.

1 Like

it would be better, more efficient, and easier to add escape sequences such as ~to escape any char if its escapable and ~~ to escape the tilde. Instead of filtering types bc you could also want to mix-n-match double stars and literal double stars.

3 Likes

~~ is markdown for strikethrough. If strikethrough is possible with ANSI sequences that might not work.

2 Likes

Why not just \ to escape? Am I missing something?

\033[9m, not widely supported though, not sure if it works on Replit

1 Like

\ is already an escape code so itl be confusing to have to say \\\ or use \\ in strings. or if its not an escape code you can do it but why confuse yourself?

4 Likes

How do i get this on replit and is there a way that i can add custom colors?

1 Like

Ah, I don’t remember if I uploaded it with this function, but in the ansi color class, I created separate functions for custom colors. However, I might’ve removed them upon release.

2 Likes

oh, i have this one function that basically allows custom colors using rgb but idk if it can support ur code

this is the function:

def rgbCol(r, g, b):
  return f"\033[38;2;{r};{g};{b}m"
1 Like

Yeah, it had a function that was similar, but it was a bit more detailed and supported some
better colors and styles. However, I just checked, and it looks like I removed it upon release. But, I mean, custerm has special color syntax if you didn’t see: [COLOR]text[/COLOR] (/COLOR signifies the end of the text with the designated color, which, in return, will reset it afterwards). But, I mean, you should still be able to use that function similarly to something like: Terminal.print(f'{rgbCol(255,0,0)}'), while still maintaining the original color syntax. Yeah, it should work perfectly fine.

1 Like