cfonts --gradient producing error with more than three colors

Aperta
#52 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Reproduce the reported command cfonts "$(hostname)" --font "block" --gradient red,"#f80",green,blue --transition-gradient, then read cfonts/colors.py around get_gradient and cfonts/core.py around paint_gradient. Done means four or more gradient colors no longer trigger the reported AssertionError while the existing three-color behavior remains working.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
Python
Stelle
192
Fork
12
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di frostming/python-cfonts

Tutte le issue di frostming/python-cfonts

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.