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

chore(lint): wrap various TTY-related errors #777

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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
7 changes: 4 additions & 3 deletions tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"errors"
"fmt"
"io"
"os"
"time"
Expand All @@ -21,7 +22,7 @@
if p.console != nil {
err = p.console.SetRaw()
if err != nil {
return err
return fmt.Errorf("error entering raw mode: %w", err)
}
}

Expand All @@ -41,14 +42,14 @@
p.renderer.exitAltScreen()

// give the terminal a moment to catch up
time.Sleep(time.Millisecond * 10)

Check failure on line 45 in tty.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 10, in <argument> detected (gomnd)
}
}

if p.console != nil {
err := p.console.Reset()
if err != nil {
return err
return fmt.Errorf("error restoring terminal state: %w", err)
}
}

Expand All @@ -60,7 +61,7 @@
var err error
p.cancelReader, err = cancelreader.NewReader(p.input)
if err != nil {
return err
return fmt.Errorf("error creating cancelreader: %w", err)
}

p.readLoopDone = make(chan struct{})
Expand All @@ -86,7 +87,7 @@
func (p *Program) waitForReadLoop() {
select {
case <-p.readLoopDone:
case <-time.After(500 * time.Millisecond):

Check failure on line 90 in tty.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 500, in <argument> detected (gomnd)
// The read loop hangs, which means the input
// cancelReader's cancel function has returned true even
// though it was not able to cancel the read.
Expand Down
7 changes: 5 additions & 2 deletions tty_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tea

import (
"fmt"
"os"

"github.com/containerd/console"
Expand All @@ -28,15 +29,17 @@ func (p *Program) initInput() error {
// program exits.
func (p *Program) restoreInput() error {
if p.console != nil {
return p.console.Reset()
if err := p.console.Reset(); err != nil {
return fmt.Errorf("error restoring console: %w", err)
}
}
return nil
}

func openInputTTY() (*os.File, error) {
f, err := os.Open("/dev/tty")
if err != nil {
return nil, err
return nil, fmt.Errorf("could not open a new TTY: %w", err)
}
return f, nil
}
Loading