1
0
forked from x/icebergs

opt toast icon

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-08 12:42:49 +08:00
parent a69a06dc5e
commit 2832fe1819
5 changed files with 28 additions and 24 deletions

View File

@ -151,18 +151,21 @@ func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
}
func GoToast(m *ice.Message, title string, cb func(toast func(name string, count, total int)) []string) *ice.Message {
_total := 0
icon := "🕑"
toast := func(name string, count, total int) {
kit.If(total == 0, func() { total = 1 })
Toast(m,
kit.Format("%s %s/%s", name, strings.TrimSuffix(kit.FmtSize(int64(count)), "B"), strings.TrimSuffix(kit.FmtSize(int64(total)), "B")),
kit.Format("%s %d%%", kit.Select(m.ActionKey(), title), count*100/total), "3000", count*100/total,
kit.Format("%s %s %s/%s", icon, kit.JoinWord(m.ActionKey(), name), strings.TrimSuffix(kit.FmtSize(int64(count)), "B"), strings.TrimSuffix(kit.FmtSize(int64(total)), "B")),
kit.Format("%s %d%%", kit.Select(m.ActionKey(), title), count*100/total), m.OptionDefault(ice.TOAST_DURATION, "30000"), count*100/total,
)
_total = total
}
if list := cb(toast); len(list) > 0 {
Toast(m, strings.Join(list, lex.NL), ice.FAILURE, "30s")
} else {
toast(kit.JoinWord(m.ActionKey(), ice.SUCCESS, "✅"), _total, _total)
m.Option(ice.TOAST_DURATION, "3000")
icon = "✅"
toast(ice.SUCCESS, _total, _total)
}
return m
}

View File

@ -243,6 +243,7 @@ const ( // MSG
YAC_STACK = "yac.stack"
SSH_ALIAS = "ssh.alias"
SSH_TARGET = "ssh.target"
TOAST_DURATION = "toast.duration"
)
const ( // RENDER
RENDER_BUTTON = "_button"

View File

@ -109,7 +109,7 @@ func _repos_each(m *ice.Message, title string, cb func(*git.Repository, ice.Maps
web.GoToast(m, kit.Select(m.CommandKey(), title), func(toast func(string, int, int)) (list []string) {
count, total := 0, msg.Length()
msg.Table(func(value ice.Maps) {
toast(kit.JoinWord(m.ActionKey(), value[REPOS]), count, total)
toast(value[REPOS], count, total)
if err := cb(_repos_open(m, value[REPOS]), value); err != nil && err != git.NoErrAlreadyUpToDate {
web.Toast(m, err.Error(), "error: "+value[REPOS], "", "3s").Sleep3s()
list = append(list, value[REPOS])

View File

@ -292,8 +292,8 @@ func PushShell(m *ice.Message, cmds []string, cb func(string)) {
defer lock.Lock()()
list = append(list, []string{cmd})
})
m.Sleep3s()
fmt.Fprintln(w, cli.EXIT)
defer fmt.Fprintln(w, cli.EXIT)
m.Sleep(m.OptionDefault("interval", "3s"))
})
kit.For(r, func(res []byte) {
m.Debug("res %v", string(res))

View File

@ -221,7 +221,7 @@ func (s relay) Install(m *ice.Message, arg ...string) {
}
func (s relay) Upgrade(m *ice.Message, arg ...string) {
if len(arg) == 0 && m.Option(MACHINE) == "" {
m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0")
m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0", "interval", "10s")
s.ForFlow(m)
} else {
s.shell(m, m.Template(UPGRADE_SH), arg...)