Ai
1 Star 0 Fork 0

长阳/go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bar.go 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
package s
import "fmt"
var (
BAR = Dict[Str, int]{}
)
func (self Str) BarPrint(tag Str) Str {
rw.Lock()
line, ok := BAR[tag]
if !ok {
line = BAR.Len() + 1
BAR[tag] = BAR.Len() + 1
}
rw.Unlock()
// fmt.Println("row :", line)
Str("").ANSISave().ANSICursor(line, 0).ANSIClearThisLine().A(self.Strip()).ANSIRestore().Print()
return self
}
/* BarShowSize
use {key} {speed} {size}
example : Str("[{key}] : speed : {speed} | size : {size} "
*/
func (self Str) BarShowSize(tag Str, usedSec float64, size int64, finish bool, allSize ...int64) Str {
c := "B"
cp := "B"
cf := float64(size)
speedSize := cf / usedSec
if size > 1024*1024*1024 {
c = "GB"
cf = cf / (1024 * 1024 * 1024)
// fmt.Println(c, cf)
} else if size > 1024*1024 {
c = "MB"
cf = cf / (1024 * 1024)
// fmt.Println(c, cf)
} else if size > 1024 {
c = "KB"
cf = cf / 1024
// fmt.Println(c, cf)
}
if speedSize > 1024*1024*1024 {
cp = "GB"
speedSize = speedSize / (1024 * 1024 * 1024)
// fmt.Println(c, cf)
} else if speedSize > 1024*1024 {
cp = "MB"
speedSize = speedSize / (1024 * 1024)
// fmt.Println(c, cf)
} else if speedSize > 1024 {
cp = "KB"
speedSize = speedSize / 1024
// fmt.Println(c, cf)
}
SizeStr := fmt.Sprintf("%.2f%s", cf, c)
speedStr := fmt.Sprintf("%.2f%s/sec", speedSize, cp)
// self.Strip().ANSISelected() + Str(
if !self.Has("{") {
self = Str("[{key}]").ANSIBold()
self += Str("| speed: {speed} | size: {size} ").ANSIGreen().ANSIItalic()
self += Str("| used: {time}s ").ANSIYellow().ANSIUnderline()
}
if self.Has("{key}") {
self = self.Format(Dict[Str, any]{
"key": tag,
})
}
if self.Has("{speed}") {
self = self.Format(Dict[Str, any]{
"speed": speedStr,
})
}
if self.Has("{size}") {
self = self.Format(Dict[Str, any]{
"size": SizeStr,
})
}
if self.Has("{time}") {
self = self.Format(Dict[Str, any]{
"time": fmt.Sprintf("%.2f", usedSec),
})
}
if allSize != nil && size > 0 {
per := float64(size*100) / float64(allSize[0])
self = Sprintf("(%%%.2f) - ", per).ANSIGreen() + self
}
if finish {
self = Str("(finish) - ").ANSIGreen().ANSIBold().ANSIItalic().ANSIBlink() + self
}
return self.BarPrint(tag)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dark.H/go-utils.git
git@gitee.com:dark.H/go-utils.git
dark.H
go-utils
go-utils
v1.3.4

搜索帮助