]> Sergey Matveev's repositories - vors.git/blob - cmd/client/gui.go
aed177b4870144459ec9c1d2f0e12bf34c5729165519463b91241436ffa0af6f
[vors.git] / cmd / client / gui.go
1 // VoRS -- Vo(IP) Really Simple
2 // Copyright (C) 2024 Sergey Matveev <stargrave@stargrave.org>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, version 3 of the License.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU Affero General Public License for more details.
12 //
13 // You should have received a copy of the GNU Affero General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 package main
17
18 import (
19         "fmt"
20         "sort"
21
22         "github.com/jroimartin/gocui"
23 )
24
25 var (
26         GUI       *gocui.Gui
27         GUIReady  bool
28         GUIReadyC = make(chan struct{})
29         GUIMaxY   int
30 )
31
32 func guiQuit(gui *gocui.Gui, v *gocui.View) error {
33         Finish <- struct{}{}
34         return gocui.ErrQuit
35 }
36
37 func mute(gui *gocui.Gui, v *gocui.View) error {
38         Muted = !Muted
39         return nil
40 }
41
42 func guiLayout(gui *gocui.Gui) error {
43         var maxX int
44         maxX, GUIMaxY = gui.Size()
45         prevY := 0
46         v, err := gui.SetView("logs", 0, prevY, maxX-1, prevY+10+2)
47         prevY += 10 + 2
48         if err != nil {
49                 if err != gocui.ErrUnknownView {
50                         return err
51                 }
52                 v.Title = fmt.Sprintf("Logs name=%s room=%s", *Name, *Room)
53                 v.Autoscroll = true
54         }
55         sids := make([]int, 0, len(Streams))
56         for sid := range Streams {
57                 sids = append(sids, int(sid))
58         }
59         sort.Ints(sids)
60         var stream *Stream
61         for _, sid := range sids {
62                 stream = Streams[byte(sid)]
63                 v, err = gui.SetView(stream.name, 0, prevY, maxX/2-1, prevY+2)
64                 if err != nil {
65                         if err != gocui.ErrUnknownView {
66                                 return err
67                         }
68                         v.Title = stream.name
69                 }
70                 _, err = gui.SetView(stream.name+"-vol", maxX/2, prevY, maxX-1, prevY+2)
71                 prevY += 3
72                 if err != nil {
73                         if err != gocui.ErrUnknownView {
74                                 return err
75                         }
76                 }
77         }
78         if !GUIReady {
79                 close(GUIReadyC)
80                 GUIReady = true
81                 gui.SetCurrentView(*Name)
82         }
83         return nil
84 }