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"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"hakurei.app/check"
|
||||
@@ -38,18 +39,32 @@ type cache struct {
|
||||
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].
|
||||
func (cache *cache) open() (err error) {
|
||||
if cache.c != nil {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
|
||||
var hostname string
|
||||
if hostname, err = os.Hostname(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var base *check.Absolute
|
||||
if cache.base, err = filepath.Abs(cache.base); err != nil {
|
||||
return
|
||||
} else if base, err = check.NewAbs(cache.base); err != nil {
|
||||
return
|
||||
}
|
||||
var notify chan bool
|
||||
|
||||
if cache.idle {
|
||||
cache.attr.Flags |= pkg.CSchedIdle
|
||||
@@ -65,6 +80,8 @@ func (cache *cache) open() (err error) {
|
||||
}
|
||||
if cache.color {
|
||||
cache.attr.Flags |= pkg.CColourOutput
|
||||
notify = make(chan bool, 1<<12)
|
||||
cache.attr.Notify = notify
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
@@ -109,6 +126,29 @@ func (cache *cache) open() (err error) {
|
||||
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 {
|
||||
var pathname *check.Absolute
|
||||
pathname, _, err = cache.c.Cure(cache.qemu)
|
||||
@@ -129,6 +169,11 @@ func (cache *cache) open() (err error) {
|
||||
func (cache *cache) Close() {
|
||||
if cache.c != nil {
|
||||
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