ibigio / shell-ai

A delightfully minimal, yet remarkably powerful AI Shell Assistant.
GNU General Public License v3.0
266 stars 25 forks source link

Fix buggy output on narrow terminals #10

Closed ibigio closed 1 year ago

ibigio commented 1 year ago

Context

On a narrow terminal window where rendered output wraps to the line below, sometimes output jumps around and creates "sticky" artifacts that end up in the terminal output.

https://github.com/ibigio/shell-ai/assets/25421602/d0e1d9cd-37ad-4006-8ea5-5ad4d894d627

Given that this only occurs on narrows terminal windows where lines wrap around I'm guessing this might be an issue how BubbleTea handles rapid updates to the rendered markdown output. Also going to try validating that there's no rogue tea.Print or actual prints messing things up.

Task

Find root cause of jumpy output and fix, so it is stable and leaves no artifacts.

ibigio commented 1 year ago

Findings

When BubbleTea has to render lines longer than the terminal length (and the terminal does the line wrapping) it sometimes bugs out and renders incorrectly. This happens both with markdown formatted and plaintext output.

Solution

Since we only ever render wide markdown formatted code, limit the width of the resulting code to the terminal width (plus some buffer). This gets rid of the permanent output artifacts in the terminal (still some flashing, but that's inherent to BubbleTea). Fixed: 93dde89edbe7818f2fdfedc3527a585359