python-cfonts icon indicating copy to clipboard operation
python-cfonts copied to clipboard

cfonts --gradient producing error with more than three colors

Open averyfreeman opened this issue 11 months ago • 0 comments

Hi, I have an interesting environment in which to debug because I'm sharing $HOME folders between two systems, one using Fedora 41 with the original cfonts program, and one running python-cfonts on Debian 13 (testing/trixie) installed with pipx.

Each system that has a clone of $HOME or $ZSH folder runs a pretty_hostname function to announce where I am.

TL;DR - python-cfonts --gradient [colors] appears to error when given more than 3 colors. When I reduce the number of colors to 3, gradient appears as normal

environment information for Debian machine:

❯ which python3 && python3 --version
/usr/bin/python3
Python 3.13.2

❯ which pipx && pipx --version      
/usr/bin/pipx
1.7.1

❯ uname -rv  
6.12.12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.12-1 (2025-02-02)

Login banner argument:

cfonts "$(hostname)" --font "block" --gradient red,"#f80",green,blue --transition-gradient

The gradient colors are actually from an example pulled from the Fedora cfonts package documentation /usr/share/doc/cfonts/README.md line 356

 355   │ ```sh
 356   │ $ cfonts "text" --gradient red,"#f80",green,blue --transition-gradient
 357   │ ```

Error output:

Traceback (most recent call last):
  File "/home/avery/.local/bin/cfonts", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/avery/.local/share/pipx/venvs/python-cfonts/lib/python3.13/site-packages/cfonts/cli.py", line 169, in main
    say(args.text, **options)
    ~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/avery/.local/share/pipx/venvs/python-cfonts/lib/python3.13/site-packages/cfonts/core.py", line 373, in say
    write = render(text, **options)
  File "/home/avery/.local/share/pipx/venvs/python-cfonts/lib/python3.13/site-packages/cfonts/core.py", line 336, in render
    output = paint_gradient(
        output,
    ...<5 lines>...
        transition,
    )
  File "/home/avery/.local/share/pipx/venvs/python-cfonts/lib/python3.13/site-packages/cfonts/core.py", line 221, in paint_gradient
    styles = pen.get_gradient(gradient, max_index - min_index + 1, transition)
  File "/home/avery/.local/share/pipx/venvs/python-cfonts/lib/python3.13/site-packages/cfonts/colors.py", line 179, in get_gradient
    assert sum(color_steps) == steps - 1
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

I see this assert sum(color_steps) == steps - 1 statement at cfonts/colors.py line 169.

I am figuring something's up with my syntax, even though it's pulled straight from the original cfonts README.md. In an attempt to diagnose my syntax, I've tried using the following alterations:

  • wrapping only #f80 with double quotes (default)
  • wrapping only #f80 with single quotes
  • making #f80 #F80
  • wrapping all colors with single and double quotes
  • wrapping only the #f80 with single and double quotes
  • wrapping each color in single quotes and all colors with double quotes

Let me know if you have any ideas, I can try poking around at stuff.

PS: removing one of the colors of the gradient as workaround (no rush).

averyfreeman avatar Mar 07 '25 19:03 averyfreeman