github.com/oam-dev/kubevela@v1.9.11/references/cli/print.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cli 18 19 import ( 20 "time" 21 22 "github.com/briandowns/spinner" 23 "github.com/fatih/color" 24 "github.com/gosuri/uitable" 25 "github.com/kyokomi/emoji" 26 ) 27 28 // colors used in vela cmd for printing 29 var ( 30 red = color.New(color.FgRed) 31 green = color.New(color.FgGreen) 32 yellow = color.New(color.FgYellow) 33 white = color.New(color.Bold, color.FgWhite) 34 ) 35 36 // emoji used in vela cmd for printing 37 var ( 38 emojiSucceed = emoji.Sprint(":check_mark_button:") 39 emojiFail = emoji.Sprint(":cross_mark:") 40 emojiExecuting = emoji.Sprint(":hourglass:") 41 emojiSkip = emoji.Sprint(":no_entry:") 42 ) 43 44 // newUITable creates a new table with fixed MaxColWidth 45 func newUITable() *uitable.Table { 46 t := uitable.New() 47 t.MaxColWidth = 60 48 t.Wrap = true 49 return t 50 } 51 52 func newTrackingSpinnerWithDelay(suffix string, interval time.Duration) *spinner.Spinner { 53 suffixColor := color.New(color.Bold, color.FgWhite) 54 return spinner.New( 55 spinner.CharSets[14], 56 interval, 57 spinner.WithColor("white"), 58 spinner.WithHiddenCursor(true), 59 spinner.WithSuffix(suffixColor.Sprintf(" %s", suffix))) 60 } 61 62 func newTrackingSpinner(suffix string) *spinner.Spinner { 63 return newTrackingSpinnerWithDelay(suffix, 500*time.Millisecond) 64 } 65 66 func applySpinnerNewSuffix(s *spinner.Spinner, suffix string) { 67 suffixColor := color.New(color.Bold, color.FgGreen) 68 s.Suffix = suffixColor.Sprintf(" %s", suffix) 69 }