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 6984d81 commit 09acb26
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
@@ -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
Expand Up @@ -241,10 +241,7 @@ func (b *BubbleProgress) tickSpeed() tea.Cmd {

func (b *BubbleProgress) start() {
b.prog = progress.New(progress.WithDefaultGradient())
b.tea = tea.NewProgram(b,
tea.WithInput(safeguardBubbletea964(b.InOrStdin())),
tea.WithOutput(b.OutOrStdout()),
)
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
Expand Up @@ -78,10 +78,7 @@ func (b *BubbleSpinner) start() {
spinner.WithSpinner(spinner.Meter),
spinner.WithStyle(spinnerStyle()),
)
b.tea = tea.NewProgram(b,
tea.WithInput(safeguardBubbletea964(b.InOrStdin())),
tea.WithOutput(b.OutOrStdout()),
)
b.tea = tea.NewProgram(b, ioProgramOptions(b.InputOutput)...)
b.quitChan = make(chan struct{})
go func() {
t := b.tea
Expand Down

0 comments on commit 09acb26

Please sign in to comment.