cmd/mbf: set window title
Test / Hakurei (race detector) (push) Successful in 6m57s
Test / Sandbox (push) Successful in 3m8s
Test / Sandbox (race detector) (push) Successful in 5m46s
Test / ShareFS (push) Successful in 7m26s
Test / Create distribution (push) Successful in 50s
Test / Hakurei (push) Successful in 2m54s
Test / Flake checks (push) Successful in 1m9s
Test / Hakurei (race detector) (push) Successful in 6m57s
Test / Sandbox (push) Successful in 3m8s
Test / Sandbox (race detector) (push) Successful in 5m46s
Test / ShareFS (push) Successful in 7m26s
Test / Create distribution (push) Successful in 50s
Test / Hakurei (push) Successful in 2m54s
Test / Flake checks (push) Successful in 1m9s
This displays ongoing and complete cures via the notify channel. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"hakurei.app/check"
|
"hakurei.app/check"
|
||||||
@@ -38,18 +39,32 @@ type cache struct {
|
|||||||
base, mirror string
|
base, mirror string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeTitle sets title of the terminal connected to [message.Msg].
|
||||||
|
func writeTitle(msg message.Msg, s string) {
|
||||||
|
msg.Suspend()
|
||||||
|
w := msg.GetLogger().Writer()
|
||||||
|
_, _ = w.Write([]byte("\x1b]0;" + s + "\a"))
|
||||||
|
msg.Resume()
|
||||||
|
}
|
||||||
|
|
||||||
// open opens the underlying [pkg.Cache].
|
// open opens the underlying [pkg.Cache].
|
||||||
func (cache *cache) open() (err error) {
|
func (cache *cache) open() (err error) {
|
||||||
if cache.c != nil {
|
if cache.c != nil {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hostname string
|
||||||
|
if hostname, err = os.Hostname(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var base *check.Absolute
|
var base *check.Absolute
|
||||||
if cache.base, err = filepath.Abs(cache.base); err != nil {
|
if cache.base, err = filepath.Abs(cache.base); err != nil {
|
||||||
return
|
return
|
||||||
} else if base, err = check.NewAbs(cache.base); err != nil {
|
} else if base, err = check.NewAbs(cache.base); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var notify chan bool
|
||||||
|
|
||||||
if cache.idle {
|
if cache.idle {
|
||||||
cache.attr.Flags |= pkg.CSchedIdle
|
cache.attr.Flags |= pkg.CSchedIdle
|
||||||
@@ -65,6 +80,8 @@ func (cache *cache) open() (err error) {
|
|||||||
}
|
}
|
||||||
if cache.color {
|
if cache.color {
|
||||||
cache.attr.Flags |= pkg.CColourOutput
|
cache.attr.Flags |= pkg.CColourOutput
|
||||||
|
notify = make(chan bool, 1<<12)
|
||||||
|
cache.attr.Notify = notify
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -109,6 +126,29 @@ func (cache *cache) open() (err error) {
|
|||||||
cache.c.SetExternal(r)
|
cache.c.SetExternal(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cache.attr.Notify != nil {
|
||||||
|
cache.msg.Suspend()
|
||||||
|
_, _ = cache.msg.GetLogger().Writer().Write([]byte("\x1b[22;0t"))
|
||||||
|
cache.msg.Resume()
|
||||||
|
|
||||||
|
prefix := hostname + ": mbf "
|
||||||
|
go func() {
|
||||||
|
var n, nc uint64
|
||||||
|
for enter := range notify {
|
||||||
|
if enter {
|
||||||
|
n++
|
||||||
|
nc++
|
||||||
|
} else {
|
||||||
|
nc--
|
||||||
|
}
|
||||||
|
|
||||||
|
writeTitle(cache.msg, prefix+
|
||||||
|
"("+strconv.FormatUint(nc, 10)+
|
||||||
|
" of "+strconv.FormatUint(n, 10)+")")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
if cache.qemu != nil {
|
if cache.qemu != nil {
|
||||||
var pathname *check.Absolute
|
var pathname *check.Absolute
|
||||||
pathname, _, err = cache.c.Cure(cache.qemu)
|
pathname, _, err = cache.c.Cure(cache.qemu)
|
||||||
@@ -129,6 +169,11 @@ func (cache *cache) open() (err error) {
|
|||||||
func (cache *cache) Close() {
|
func (cache *cache) Close() {
|
||||||
if cache.c != nil {
|
if cache.c != nil {
|
||||||
cache.c.Close()
|
cache.c.Close()
|
||||||
|
if cache.attr.Notify != nil {
|
||||||
|
cache.msg.Suspend()
|
||||||
|
_, _ = cache.msg.GetLogger().Writer().Write([]byte("\x1b[23;0t"))
|
||||||
|
cache.msg.Resume()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user