-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using a new progress bar SDK to sealer scp
Signed-off-by: Lancelot <[email protected]>
- Loading branch information
1 parent
70a4c9f
commit 1885b96
Showing
26 changed files
with
1,867 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright © 2023 Alibaba Group Holding Ltd. | ||
// | ||
// 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 progressbar | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/schollz/progressbar/v3" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type EasyProgressUtil struct { | ||
progressbar.ProgressBar | ||
} | ||
|
||
var ( | ||
width = 50 | ||
optionEnableColorCodes = progressbar.OptionEnableColorCodes(true) | ||
optionSetWidth = progressbar.OptionSetWidth(width) | ||
optionSetTheme = progressbar.OptionSetTheme(progressbar.Theme{ | ||
Saucer: "=", | ||
SaucerHead: ">", | ||
SaucerPadding: " ", | ||
BarStart: "[", | ||
BarEnd: "]", | ||
}) | ||
) | ||
|
||
func NewEasyProgressUtil(total int, describe string) *EasyProgressUtil { | ||
return &EasyProgressUtil{ | ||
*progressbar.NewOptions(total, | ||
optionEnableColorCodes, | ||
optionSetWidth, | ||
optionSetTheme, | ||
progressbar.OptionSetDescription(describe), | ||
// after finish, print a new line | ||
progressbar.OptionOnCompletion(func() { | ||
fmt.Println() | ||
}), | ||
), | ||
} | ||
} | ||
|
||
// increment add 1 to progress bar | ||
func (epu *EasyProgressUtil) Increment() { | ||
if err := epu.Add(1); err != nil { | ||
logrus.Errorf("failed to increment progress bar, err: %s", err) | ||
} | ||
} | ||
|
||
// fail print error message | ||
func (epu *EasyProgressUtil) Fail(err error) { | ||
if err != nil { | ||
epu.Describe(err.Error()) | ||
} | ||
} | ||
|
||
// setTotal set total num of progress bar | ||
func (epu *EasyProgressUtil) SetTotal(num int) { | ||
if num > epu.GetMax() { | ||
epu.ChangeMax(num) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.