From b7aa91f08fc7058c24a207f8cf63ce0ff7b036ff Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 31 Jul 2026 14:00:08 +0900 Subject: [PATCH] cmd/mbf: set window title This displays ongoing and complete cures via the notify channel. Signed-off-by: Ophestra --- cmd/mbf/cache.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/cmd/mbf/cache.go b/cmd/mbf/cache.go index b4bc7126..5a4b9672 100644 --- a/cmd/mbf/cache.go +++ b/cmd/mbf/cache.go @@ -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() + } } }