1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-05 06:46:48 +00:00

moved code from pkg stew to tui type

This commit is contained in:
postmannen 2022-01-08 04:19:51 +01:00
parent af3895431e
commit 0e98ce7cfb
2 changed files with 28 additions and 13 deletions

View file

@ -60,6 +60,8 @@ type server struct {
metrics *metrics
// Version of package
version string
// tui client
tui *tui
}
// newServer will prepare and return a server type
@ -122,6 +124,17 @@ func NewServer(c *Configuration, version string) (*server, error) {
metrics := newMetrics(c.PromHostAndPort)
// Create the tui client structure if enabled.
var tuiClient *tui
if c.EnableTUI {
tuiClient, err = newTui()
if err != nil {
cancel()
return nil, err
}
}
s := &server{
ctx: ctx,
cancel: cancel,
@ -133,6 +146,7 @@ func NewServer(c *Configuration, version string) (*server, error) {
newMessagesCh: make(chan []subjectAndMessage),
metrics: metrics,
version: version,
tui: tuiClient,
}
// Create the default data folder for where subscribers should
@ -247,6 +261,16 @@ func (s *server) Start() {
go s.exposeDataFolder(s.ctx)
}
if s.configuration.EnableTUI {
go func() {
err := s.tui.Start()
if err != nil {
log.Printf("%v\n", err)
os.Exit(1)
}
}()
}
// Start the processing of new messages from an input channel.
// NB: We might need to create a sub context for the ringbuffer here
// so we can cancel this context last, and not use the server.

17
tui.go
View file

@ -3,7 +3,6 @@ package steward
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"log"
"os"
@ -16,19 +15,11 @@ import (
"github.com/rivo/tview"
)
type Stew struct {
type tui struct {
}
func NewStew() (*Stew, error) {
stewardSocket := flag.String("stewardSocket", "/usr/local/steward/tmp/steward.sock", "specify the full path of the steward socket file")
flag.Parse()
_, err := os.Stat(*stewardSocket)
if err != nil {
return nil, fmt.Errorf("error: specify the full path to the steward.sock file: %v", err)
}
s := Stew{}
func newTui() (*tui, error) {
s := tui{}
return &s, nil
}
@ -38,7 +29,7 @@ type slide struct {
primitive tview.Primitive
}
func (s *Stew) Start() error {
func (s *tui) Start() error {
pages := tview.NewPages()
app := tview.NewApplication()