cfonts --gradient producing error with more than three colors
还没有人认领这个 Issue。
评估
调研方向
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
#f80with double quotes (default) - wrapping only
#f80with single quotes - making
#f80#F80 - wrapping all colors with single and double quotes
- wrapping only the
#f80with 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
frostming/python-cfonts 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 20/100
frostming/python-cfonts#47 ·
查看 frostming/python-cfonts 的全部 Issue
相似的 Issue
-
Unknown stop ID in slow zone data crashes post formatting and skips the rest of that day's posts未关闭backend bug tm-new-volunteer
难度 2/5 1-3 小时 新手友好度 84/100
transitmatters/mbta-slow-zone-bot#81 · 1 条评论 ·
-
area:schema documentation
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
risk:high type:ci
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
spacetelescope/rdmt-spire#49 ·
维护者通常 1 天内回复