From d91b29158fa3b6bac18aea78e31a800b2d90ad493b7710fc3a4e7ad6c83df93c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 28 Apr 2024 18:20:19 +0300 Subject: [PATCH] Silencing of the peer --- cmd/client/gui.go | 21 +++++++++------------ cmd/client/main.go | 30 ++++++++++++++++++++++-------- cmd/client/stats.go | 7 +++++-- doc/features.texi | 2 ++ internal/colours.go | 8 +++++--- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/cmd/client/gui.go b/cmd/client/gui.go index 4f4051c..34f1370 100644 --- a/cmd/client/gui.go +++ b/cmd/client/gui.go @@ -32,16 +32,6 @@ var ( CurrentView = 0 ) -func guiQuit(gui *gocui.Gui, v *gocui.View) error { - Finish <- struct{}{} - return gocui.ErrQuit -} - -func mute(gui *gocui.Gui, v *gocui.View) error { - muteToggle() - return nil -} - func tabHandle(gui *gocui.Gui, v *gocui.View) error { sids := make([]int, 0, len(Streams)+1) sids = append(sids, -1) @@ -106,9 +96,8 @@ func guiLayout(gui *gocui.Gui) error { sids = append(sids, int(sid)) } sort.Ints(sids) - var stream *Stream for _, sid := range sids { - stream = Streams[byte(sid)] + stream := Streams[byte(sid)] v, err = gui.SetView(stream.name, 0, prevY, maxX/2-1, prevY+2) if err != nil { if err != gocui.ErrUnknownView { @@ -118,6 +107,14 @@ func guiLayout(gui *gocui.Gui) error { v.Title = ">" + stream.name + "<" } else { v.Title = stream.name + if err := GUI.SetKeybinding( + stream.name, gocui.KeyEnter, gocui.ModNone, func(*gocui.Gui, *gocui.View) error { + stream.silenced = !stream.silenced + return nil + }, + ); err != nil { + return err + } } } _, err = gui.SetView(stream.name+"-vol", maxX/2, prevY, maxX-1, prevY+2) diff --git a/cmd/client/main.go b/cmd/client/main.go index 620dee6..f485d51 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -42,12 +42,13 @@ import ( ) type Stream struct { - name string - ctr uint32 - actr uint32 - muted bool - in chan []byte - stats *Stats + name string + ctr uint32 + actr uint32 + muted bool + silenced bool + in chan []byte + stats *Stats } var ( @@ -315,10 +316,20 @@ func main() { if err := GUI.SetKeybinding("", gocui.KeyTab, gocui.ModNone, tabHandle); err != nil { log.Fatal(err) } - if err := GUI.SetKeybinding("", gocui.KeyF1, gocui.ModNone, mute); err != nil { + if err := GUI.SetKeybinding("", gocui.KeyF1, gocui.ModNone, + func(gui *gocui.Gui, v *gocui.View) error { + muteToggle() + return nil + }, + ); err != nil { log.Fatal(err) } - if err := GUI.SetKeybinding("", gocui.KeyF10, gocui.ModNone, guiQuit); err != nil { + if err := GUI.SetKeybinding("", gocui.KeyF10, gocui.ModNone, + func(gui *gocui.Gui, v *gocui.View) error { + Finish <- struct{}{} + return gocui.ErrQuit + }, + ); err != nil { log.Fatal(err) } @@ -425,6 +436,9 @@ func main() { if !ok { break } + if stream.silenced { + continue + } if _, err = io.Copy(player, bytes.NewReader(pcmbuf)); err != nil { log.Println("play:", err) diff --git a/cmd/client/stats.go b/cmd/client/stats.go index d157f44..985c3ae 100644 --- a/cmd/client/stats.go +++ b/cmd/client/stats.go @@ -75,12 +75,15 @@ func statsDrawer(s *Stream) { if s.name == *Name && Muted { l += " | " + vors.CRed + "MUTE" + vors.CReset } else { - if s.muted { - l += " | " + vors.CRed + "MUTE" + vors.CReset + if s.silenced { + l += " | " + vors.CMagenta + "SILENT" + vors.CReset } if s.stats.last.Add(vors.ScreenRefresh).After(now) { l += " | " + vors.CGreen + "TALK" + vors.CReset } + if s.muted { + l += " | " + vors.CRed + "MUTE" + vors.CReset + } } v, err = GUI.View(s.name) if err == nil { diff --git a/doc/features.texi b/doc/features.texi index 279c121..8608dc6 100644 --- a/doc/features.texi +++ b/doc/features.texi @@ -21,6 +21,8 @@ server's public key knowledge. @item Rooms, optionally password protected. Peers are able to broadcast text message to everyone in the room. +@item Ability to silence specified peer in the room. + @item Fancy TUI client with mute-toggle ability by external utilities. @end itemize diff --git a/internal/colours.go b/internal/colours.go index 707ce81..b5153af 100644 --- a/internal/colours.go +++ b/internal/colours.go @@ -7,9 +7,10 @@ import ( ) var ( - CGreen string - CRed string - CReset string + CGreen string + CRed string + CMagenta string + CReset string ) func init() { @@ -17,5 +18,6 @@ func init() { t := term.NewTerminal(&b, "") CGreen = string(t.Escape.Green) CRed = string(t.Escape.Red) + CMagenta = string(t.Escape.Magenta) CReset = string(t.Escape.Reset) } -- 2.48.1