go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cli/progress/multiprogress_mock.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package progress 5 6 import ( 7 "fmt" 8 "io" 9 10 tea "github.com/charmbracelet/bubbletea" 11 ) 12 13 // This way we get the output without having a tty. 14 func newMultiProgressMockProgram(elements map[string]string, orderedKeys []string, input io.Reader, output io.Writer) (*tea.Program, error) { 15 if len(elements) != len(orderedKeys) { 16 return nil, fmt.Errorf("number of elements and orderedKeys must be equal") 17 } 18 m := newMultiProgress(elements) 19 m.orderedKeys = orderedKeys 20 m.maxItemsToShow = defaultProgressNumAssets 21 return tea.NewProgram(m, tea.WithInput(input), tea.WithOutput(output)), nil 22 } 23 24 func newMultiProgressBarsMock(elements map[string]string, orderedKeys []string, input io.Reader, output io.Writer) (*multiProgressBars, error) { 25 program, err := newMultiProgressMockProgram(elements, orderedKeys, input, output) 26 if err != nil { 27 return nil, err 28 } 29 return &multiProgressBars{program: program}, nil 30 }