跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

progressbar.go

53 行 · 1.1 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package progressbar
5
6import (
7 "os"
8 "time"
9
10 "github.com/cheggaaa/pb/v3"
11 "github.com/mattn/go-isatty"
12 "github.com/sirupsen/logrus"
13)
14
15// ProgressBar adapts pb.ProgressBar to go-qcow2reader.convert.Updater interface.
16type ProgressBar struct {
17 *pb.ProgressBar
18}
19
20func (b *ProgressBar) Update(n int64) {
21 b.Add64(n)
22}
23
24func New(size int64) (*ProgressBar, error) {
25 bar := &ProgressBar{pb.New64(size)}
26
27 bar.Set(pb.Bytes, true)
28
29 if showProgress() {
30 bar.SetTemplateString(`{{counters . }} {{bar . | green }} {{percent .}} {{speed . "%s/s"}}`)
31 bar.SetRefreshRate(200 * time.Millisecond)
32 } else {
33 bar.Set(pb.Static, true)
34 }
35
36 bar.SetWidth(80)
37 if err := bar.Err(); err != nil {
38 return nil, err
39 }
40
41 return bar, nil
42}
43
44func showProgress() bool {
45 // Progress supports only text format fow now.
46 if _, ok := logrus.StandardLogger().Formatter.(*logrus.TextFormatter); !ok {
47 return false
48 }
49
50 // Both logrus and pb use stderr by default.
51 logFd := os.Stderr.Fd()
52 return isatty.IsTerminal(logFd) || isatty.IsCygwinTerminal(logFd)
53}