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

fix: wait for goland terminal size #1028

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion signals_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func (p *Program) listenForResize(done chan struct{}) {
case <-sig:
}

p.checkResize()
p.checkResize(false)
}
}
4 changes: 2 additions & 2 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (p *Program) handleResize() chan struct{} {

if p.ttyOutput != nil {
// Get the initial terminal size and send it to the program.
go p.checkResize()
go p.checkResize(true)

// Listen for window resizes.
go p.listenForResize(ch)
Expand Down Expand Up @@ -686,7 +686,7 @@ func (p *Program) RestoreTerminal() error {
// process was at the foreground, in which case we may not have received
// SIGWINCH. Detect any size change now and propagate the new size as
// needed.
go p.checkResize()
go p.checkResize(false)

return nil
}
Expand Down
33 changes: 32 additions & 1 deletion tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"errors"
"fmt"
"io"
"os"
"time"

"github.com/charmbracelet/x/term"
Expand Down Expand Up @@ -92,12 +93,42 @@

// checkResize detects the current size of the output and informs the program
// via a WindowSizeMsg.
func (p *Program) checkResize() {
func (p *Program) checkResize(first bool) {
if p.ttyOutput == nil {
// can't query window size
return
}

if first {

Check failure on line 102 in tty.go

View workflow job for this annotation

GitHub Actions / lint-soft

`if first` has complex nested blocks (complexity: 5) (nestif)
// JetBrains terminal (JediTerm) don't answer real size until approx. 400ms.
// In other words, we have no choice but to try hard again and again...
if _, ok := os.LookupEnv("IDEA_INITIAL_DIRECTORY"); ok {
var w, h int
var err error
for i := 0; i < 60; i++ {
time.Sleep(time.Millisecond * 10)

Check failure on line 109 in tty.go

View workflow job for this annotation

GitHub Actions / lint-soft

Magic number: 10, in <argument> detected (gomnd)
w, h, err = term.GetSize(p.ttyOutput.Fd())
if err != nil {
select {
case <-p.ctx.Done():
case p.errs <- err:
}

return
}
if w != 0 || h != 0 {
break
}
}
p.Send(WindowSizeMsg{
Width: w,
Height: h,
})

return
}
}

w, h, err := term.GetSize(p.ttyOutput.Fd())
if err != nil {
select {
Expand Down
Loading