forked from x/icebergs
add some
This commit is contained in:
parent
ca501f7a12
commit
038f419c8a
@ -9,7 +9,6 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/aaa"
|
"shylinux.com/x/icebergs/base/aaa"
|
||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
|
||||||
"shylinux.com/x/icebergs/base/log"
|
"shylinux.com/x/icebergs/base/log"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
@ -140,34 +139,40 @@ func Toast(m *ice.Message, text string, arg ...ice.Any) *ice.Message { // [title
|
|||||||
PushNoticeToast(m, text, arg)
|
PushNoticeToast(m, text, arg)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func toastContent(m *ice.Message, state string) string {
|
|
||||||
return kit.Join([]string{map[string]string{ice.PROCESS: "🕑", ice.FAILURE: "❌", ice.SUCCESS: "✅"}[state], state, m.ActionKey()}, " ")
|
var Icons = map[string]string{ice.PROCESS: "🕑", ice.FAILURE: "❌", ice.SUCCESS: "✅"}
|
||||||
|
|
||||||
|
func toastContent(m *ice.Message, state string, arg ...ice.Any) string {
|
||||||
|
return kit.JoinWord(kit.Simple(Icons[state], m.ActionKey(), state, arg)...)
|
||||||
|
}
|
||||||
|
func ToastSuccess(m *ice.Message, arg ...ice.Any) {
|
||||||
|
Toast(m, toastContent(m, ice.SUCCESS, arg...))
|
||||||
|
}
|
||||||
|
func ToastFailure(m *ice.Message, arg ...ice.Any) {
|
||||||
|
Toast(m, toastContent(m, ice.FAILURE, arg...), "", m.OptionDefault(ice.TOAST_DURATION, "3s")).Sleep(m.OptionDefault(ice.TOAST_DURATION, "3s"))
|
||||||
}
|
}
|
||||||
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, toastContent(m, ice.SUCCESS), arg...) }
|
|
||||||
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, toastContent(m, ice.FAILURE), arg...) }
|
|
||||||
func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
|
func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
|
||||||
kit.If(len(arg) == 0, func() { arg = kit.List("", "-1") })
|
Toast(m, toastContent(m, ice.PROCESS, arg...))
|
||||||
kit.If(len(arg) == 1, func() { arg = append(arg, "-1") })
|
return func() { Toast(m, toastContent(m, ice.SUCCESS, arg...)) }
|
||||||
Toast(m, toastContent(m, ice.PROCESS), arg...)
|
|
||||||
return func() { Toast(m, toastContent(m, ice.SUCCESS)) }
|
|
||||||
}
|
}
|
||||||
func GoToast(m *ice.Message, title string, cb func(toast func(name string, count, total int)) []string) *ice.Message {
|
func GoToast(m *ice.Message, title string, cb func(toast func(name string, count, total int)) []string) *ice.Message {
|
||||||
_total := 0
|
_total := 0
|
||||||
icon := "🕑"
|
icon := Icons[ice.PROCESS]
|
||||||
toast := func(name string, count, total int) {
|
toast := func(name string, count, total int) {
|
||||||
kit.If(total == 0, func() { total = 1 })
|
kit.If(total == 0, func() { total = 1 })
|
||||||
Toast(m,
|
Toast(m, 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 %s %s/%s", icon, kit.JoinWord(m.ActionKey(), name), strings.TrimSuffix(kit.FmtSize(int64(count)), "B"), strings.TrimSuffix(kit.FmtSize(int64(total)), "B")),
|
"", m.OptionDefault(ice.TOAST_DURATION, "30s"), count*100/total)
|
||||||
kit.Format("%s %d%%", kit.Select(m.ActionKey(), title), count*100/total), m.OptionDefault(ice.TOAST_DURATION, "30000"), count*100/total,
|
|
||||||
)
|
|
||||||
_total = total
|
_total = total
|
||||||
}
|
}
|
||||||
if list := cb(toast); len(list) > 0 {
|
if list := cb(toast); len(list) > 0 {
|
||||||
Toast(m, strings.Join(list, lex.NL), ice.FAILURE, "30s")
|
icon = Icons[ice.FAILURE]
|
||||||
|
m.Option(ice.TOAST_DURATION, "30s")
|
||||||
|
toast(kit.JoinWord(list...), len(list), _total)
|
||||||
} else {
|
} else {
|
||||||
m.Option(ice.TOAST_DURATION, "3000")
|
icon = Icons[ice.SUCCESS]
|
||||||
icon = "✅"
|
m.Option(ice.TOAST_DURATION, "3s")
|
||||||
toast(ice.SUCCESS, _total, _total)
|
toast(ice.SUCCESS, _total, _total)
|
||||||
}
|
}
|
||||||
|
m.Sleep(m.Option(ice.TOAST_DURATION))
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -175,9 +175,9 @@ func init() {
|
|||||||
cli.BUILD: {Name: "build link*", Hand: func(m *ice.Message, arg ...string) {
|
cli.BUILD: {Name: "build link*", Hand: func(m *ice.Message, arg ...string) {
|
||||||
web.PushStream(m)
|
web.PushStream(m)
|
||||||
if err := _install_build(m, arg...); m.Warn(err != "", err) {
|
if err := _install_build(m, arg...); m.Warn(err != "", err) {
|
||||||
web.ToastFailure(m, cli.BUILD, err)
|
web.ToastFailure(m, err)
|
||||||
} else {
|
} else {
|
||||||
web.ToastSuccess(m, cli.BUILD)
|
web.ToastSuccess(m)
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
cli.ORDER: {Name: "order link* path", Hand: func(m *ice.Message, arg ...string) { _install_order(m, arg...) }},
|
cli.ORDER: {Name: "order link* path", Hand: func(m *ice.Message, arg ...string) { _install_order(m, arg...) }},
|
||||||
|
@ -111,7 +111,7 @@ func _repos_each(m *ice.Message, title string, cb func(*git.Repository, ice.Maps
|
|||||||
msg.Table(func(value ice.Maps) {
|
msg.Table(func(value ice.Maps) {
|
||||||
toast(value[REPOS], count, total)
|
toast(value[REPOS], count, total)
|
||||||
if err := cb(_repos_open(m, value[REPOS]), value); err != nil && err != git.NoErrAlreadyUpToDate {
|
if err := cb(_repos_open(m, value[REPOS]), value); err != nil && err != git.NoErrAlreadyUpToDate {
|
||||||
web.Toast(m, err.Error(), "error: "+value[REPOS], "", "3s").Sleep3s()
|
web.ToastFailure(m, value[REPOS], err.Error())
|
||||||
list = append(list, value[REPOS])
|
list = append(list, value[REPOS])
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
@ -58,7 +58,8 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
INSTEADOF: {Name: "insteadof remote", Help: "代理", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, INSTEADOF, arg) }},
|
INSTEADOF: {Name: "insteadof remote", Help: "代理", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(REPOS, INSTEADOF, arg) }},
|
||||||
OAUTH: {Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
OAUTH: {Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.ProcessOpen(kit.MergeURL2(kit.Select(ice.Info.Make.Domain, m.Cmdx(REPOS, "remoteURL")), web.ChatCmdPath(m, web.TOKEN, "gen"), tcp.HOST, m.Option(ice.MSG_USERWEB)))
|
m.ProcessOpen(kit.MergeURL2(kit.Select(ice.Info.Make.Domain, m.Cmdx(REPOS, "remoteURL")), web.ChatCmdPath(m, web.TOKEN, "gen"),
|
||||||
|
mdb.TYPE, "web.code.git.status", tcp.HOST, m.Option(ice.MSG_USERWEB)))
|
||||||
}},
|
}},
|
||||||
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if !kit.IsIn(m.Option(mdb.TYPE), web.WORKER, web.SERVER) {
|
if !kit.IsIn(m.Option(mdb.TYPE), web.WORKER, web.SERVER) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user