Skip to content

Commit

Permalink
Don't pass stdin/stdout to bubbletea
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Mar 27, 2024
1 parent fbd71a8 commit 6be0936
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
35 changes: 35 additions & 0 deletions pkg/output/tui/io.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tui

import (
"os"

tea "github.com/charmbracelet/bubbletea"
"knative.dev/client-pkg/pkg/output"
)

func ioProgramOptions(io output.InputOutput) []tea.ProgramOption {
opts := make([]tea.ProgramOption, 0, 2)
if io.InOrStdin() != nil && io.InOrStdin() != os.Stdin {
opts = append(opts, tea.WithInput(safeguardBubbletea964(io.InOrStdin())))
}
if io.OutOrStdout() != nil && io.OutOrStdout() != os.Stdout {
opts = append(opts, tea.WithOutput(io.OutOrStdout()))
}
return opts
}
5 changes: 1 addition & 4 deletions pkg/output/tui/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ func (b *BubbleProgress) tickSpeed() tea.Cmd {
func (b *BubbleProgress) start() {
b.prog = progress.New(progress.WithDefaultGradient())
out := b.OutOrStdout()
b.tea = tea.NewProgram(b,
tea.WithInput(safeguardBubbletea964(b.InOrStdin())),
tea.WithOutput(out),
)
b.tea = tea.NewProgram(b, ioProgramOptions(b.InputOutput)...)
b.quitChan = make(chan struct{})
go func() {
t := b.tea
Expand Down
5 changes: 1 addition & 4 deletions pkg/output/tui/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func (b *BubbleSpinner) start() {
spinner.WithStyle(spinnerStyle()),
)
out := b.OutOrStdout()
b.tea = tea.NewProgram(b,
tea.WithInput(safeguardBubbletea964(b.InOrStdin())),
tea.WithOutput(out),
)
b.tea = tea.NewProgram(b, ioProgramOptions(b.InputOutput)...)
b.quitChan = make(chan struct{})
go func() {
t := b.tea
Expand Down

0 comments on commit 6be0936

Please sign in to comment.