ChrisBuilds / terminaltexteffects

TerminalTextEffects (TTE) is a terminal visual effects engine, application, and Python library.

Home Page:https://chrisbuilds.github.io/terminaltexteffects/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Allow 1 row terminal dimension

v4u6h4n opened this issue · comments

Hey everyone, first of all, thankyou so much for making the coolest thing I've seen in a terminal in a long time. The gallery is stunning :-)

That aside, I'm haven't been able to have this print to a single row, due to a divide by zero error, and just wondering if a single row print could be implemented? I tried messing around with bottom: int = 1 in terminal.py but I think the effect is using row height and looking at the effects code was like reading gibberish, as I'm just starting out with python. Here's the error:

  File "/media/storage/Streaming/Software/scripts/dev/services/test.py", line 10, in <module>
    for frame in effect:
  File "/home/user/.venvs/lib/python3.12/site-packages/terminaltexteffects/engine/base_effect.py", line 88, in __iter__
    return self._iterator_cls(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venvs/lib/python3.12/site-packages/terminaltexteffects/effects/effect_slide.py", line 143, in __init__
    self._build()
  File "/home/user/.venvs/lib/python3.12/site-packages/terminaltexteffects/effects/effect_slide.py", line 147, in _build
    final_gradient_mapping = final_gradient.build_coordinate_color_mapping(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venvs/lib/python3.12/site-packages/terminaltexteffects/utils/graphics.py", line 180, in build_coordinate_color_mapping
    fraction = row_value / max_row
               ~~~~~~~~~~^~~~~~~~~
ZeroDivisionError: division by zero

Can you post the lines of your code in which you modify the effect.terminal_config or effect.effect_config? I'll get this fixed. Thanks.

Hey @ChrisBuilds thanks for the response :-)

I think the error will show up with any code where you specify the dimensions with terminal_dimensions, I started out with the example you have in the wiki and added the line:

from terminaltexteffects.effects.effect_slide import Slide

text = ("EXAMPLE" * 10 + "\n") * 10

effect = Slide(text)
effect.effect_config.merge = True
effect.terminal_config.terminal_dimensions = (50, 1)
with effect.terminal_output() as terminal:
    for frame in effect:
        terminal.print(frame)

I got the same result using --terminal-dimensions with the above values in the terminal. I found a hacky solution around it in the meantime by using print(frame.split('\n')[0], end='\r') lol

I've released the patch for this with 0.9.1. In addition to fixing the division by zero, the terminal_config.terminal_dimensions argument has been split into terminal_config.terminal_width and terminal_config.terminal_height args. This enables automatic detection of each dimension independent of the other. So for a single line of variable length, you can do the following:

from terminaltexteffects.effects.effect_slide import Slide

text = ("EXAMPLE" * 10 + "\n") * 10

effect = Slide(text)
effect.terminal_config.terminal_height = 1
with effect.terminal_output() as terminal:
    for frame in effect:
        terminal.print(frame)

In this example, the width is automatically detected and the height is manually set to 1. Let me know if this works for your use case. If you don't have any additional issue related to single line output, I will close this issue.

I just gave it a try and it appears to be working perfectly; thanks for the help with that :-)