Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exiting fullscreen glitch when also removing a line in output #1013

Open
applejag opened this issue May 10, 2024 · 2 comments
Open

Exiting fullscreen glitch when also removing a line in output #1013

applejag opened this issue May 10, 2024 · 2 comments
Labels

Comments

@applejag
Copy link

Describe the bug
When conditionally rendering a line if you're full screen, then when you exit full screen it clears too many lines and removes terminal output that isn't part of

Setup
Please complete the following information along with version numbers, if applicable.

  • OS: Linux, NixOS
  • Shell: tested and getting the same glitch in bash, zsh, fish, and pwsh
  • Terminal Emulator: only tested alacritty, kitty, and iterm
  • Terminal Multiplexer: tested both with and without tmux

To Reproduce
Steps to reproduce the behavior:

  1. Have some history in your terminal
  2. go run .
  3. click f to enter fullscreen and then again to exit fullscreen (doesn't have to be double clicked quickly. The glitch is not time sensitive at all actually)
  4. repeat step 3 and see how it clears 1 line at a time from your terminal history

Source Code

package main

import (
	"fmt"
	"os"

	tea "github.com/charmbracelet/bubbletea"
)

func main() {
	p := tea.NewProgram(model{})
	if _, err := p.Run(); err != nil {
		fmt.Printf("Alas, there's been an error: %v", err)
		os.Exit(1)
	}
}

type model struct {
	isFullscreen bool
}

func (m model) Init() tea.Cmd {
	return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {

		// These keys should exit the program.
		case "ctrl+c", "q":
			return m, tea.Quit

		// Toggle fullscreen
		case "f":
			m.isFullscreen = !m.isFullscreen
			if m.isFullscreen {
                return m, tea.EnterAltScreen
            } else {
                return m, tea.ExitAltScreen
			}
		}
	}
	return m, nil
}

func (m model) View() string {
	s := "Hello\n"

    if m.isFullscreen {
        s += "yay we're fullscreen\n"
    }

	s += "\nPress q to quit.\n"

	return s
}

Expected behavior
When exiting full screen mode, tea renders the view first before trying to figure out how many lines to clear.

Screenshots
When first just running the program:

image

After clicking f to enter fullscreen:

image

Then clicking f again to exit:

image

Doing that again, clicking f twice, results in another line removed:

image

Double clicking again:

image

And again:

image

Additional context
As a more real-life example, in my real program I have all the normal output, but then conditionally a status bar at the end.

When toggling fullscreen it will add a status line to my program saying "forcing fullscreen". Then if there are no other status messages, when I get out of full screen then the status line should also disappear, leading to the bug/glitch explained in this issue.

@semihbkgr
Copy link

semihbkgr commented May 15, 2024

Additionally, reversing the condition leaves more lines in the terminal after toggling the full screen. For example:

if !m.isFullscreen {
        s += "yay we're fullscreen\n"
}

keeps leftover lines in the terminal

@meowgorithm
Copy link
Member

Oof, wow, this is definitely a bug. Appreciate the report—we'll look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants