Skip to content
Snippets Groups Projects
statusView.go 946 B
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package views
    
    import (
    	"fmt"
    	"time"
    
    	"github.com/rivo/tview"
    	"google.golang.org/grpc"
    )
    
    type GoSDNStatusView struct {
    	statusGoSDNView *tview.TextView
    }
    
    //TODO: change to grpcStatusView
    func NewGoSDNStatusView(conn *grpc.ClientConn) *GoSDNStatusView {
    	//TODO: change to uses FlexBox if there is more to display in the header
    	sv := &GoSDNStatusView{
    		statusGoSDNView: tview.NewTextView(),
    	}
    
    	sv.statusGoSDNView.
    		SetRegions(true).
    		SetBorder(true).
    		SetTitle("Status: gRPC")
    
    	go goSDNTicker(sv, conn)
    
    	return sv
    }
    
    func (sv *GoSDNStatusView) GetContent() tview.Primitive {
    	return sv.statusGoSDNView
    }
    
    func (sv *GoSDNStatusView) SetContent(s string) {
    	sv.statusGoSDNView.Clear()
    	sv.statusGoSDNView.SetText(s)
    }
    
    func goSDNTicker(sv *GoSDNStatusView, conn *grpc.ClientConn) {
    	ticker := time.NewTicker(5 * time.Second)
    	sv.statusGoSDNView.SetText("???")
    	for range ticker.C {
    		sv.statusGoSDNView.Clear()
    		fmt.Println(sv)
    	}
    }