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

Disable animated output when tty is not found #26

Merged
Merged
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
24 changes: 17 additions & 7 deletions internal/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type model struct {
validator *canaryv1.Validator
configPath string
err error
tty bool
}

func (m model) Init() tea.Cmd {
Expand Down Expand Up @@ -171,7 +172,11 @@ func (m model) View() string {
} else {
s += fmt.Sprintf("Validating %s against %s\n", highlightStyle(m.image), highlightStyle(m.validator.Name))
if !m.containerStarted {
s += fmt.Sprintf("%s Starting container\n", m.spinner.View())
if m.tty {
s += fmt.Sprintf("%s Starting container\n", m.spinner.View())
} else {
s += "Starting container\n"
}
} else {
if m.debug {
// TODO cache this status call to avoid hammering it
Expand All @@ -186,7 +191,9 @@ func (m model) View() string {
s += "Leaving container running for debugging...\n"
}
} else {
s += m.progress.View() + "\n"
if m.tty {
s += m.progress.View() + "\n"
}
}
}
}
Expand All @@ -210,6 +217,13 @@ func (m model) Passed() bool {
}

func Validate(image string, configPath string, cmd *cobra.Command, debug bool) (bool, error) {
var tty io.Reader
isTty := true
tty, err := os.Open("/dev/tty")
if err != nil {
tty = bufio.NewReader(os.Stdin)
isTty = false
}
m := model{
sub: make(chan checkResult),
configPath: configPath,
Expand All @@ -219,11 +233,7 @@ func Validate(image string, configPath string, cmd *cobra.Command, debug bool) (
allChecksPassed: true,
debug: debug,
image: image,
}
var tty io.Reader
tty, err := os.Open("/dev/tty")
if err != nil {
tty = bufio.NewReader(os.Stdin)
tty: isTty,
}
p := tea.NewProgram(m, tea.WithInput(tty), tea.WithOutput(cmd.OutOrStderr()))
out, err := p.StartReturningModel()
Expand Down