cfonts --gradient producing error with more than three colors

オープン
#52 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
cli

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
192
フォーク
12
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

frostming/python-cfonts のほかの issue

frostming/python-cfonts の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。