Skip to content
Snippets Groups Projects
Select Git revision
  • faaf9f7393297507fe86d2641a8a8489ae5968ff
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

statusscreen.go

Blame
  • user avatar
    Hans Moog authored
    faaf9f73
    History
    statusscreen.go 2.98 KiB
    package statusscreen
    
    import (
        "github.com/gdamore/tcell"
        "github.com/iotaledger/goshimmer/packages/daemon"
        "github.com/iotaledger/goshimmer/packages/node"
        "github.com/rivo/tview"
        "time"
    )
    
    var statusMessages = make(map[string]*StatusMessage)
    var messageLog = make([]*StatusMessage, 0)
    
    var app *tview.Application
    
    func configure(plugin *node.Plugin) {
        node.DEFAULT_LOGGER.Enabled = false
    
        plugin.Node.AddLogger(DEFAULT_LOGGER)
    
        daemon.Events.Shutdown.Attach(func() {
            node.DEFAULT_LOGGER.Enabled = true
    
            if app != nil {
                app.Stop()
            }
        })
    }
    
    func run(plugin *node.Plugin) {
        newPrimitive := func(text string) *tview.TextView {
            textView := tview.NewTextView()
    
            textView.
                SetTextAlign(tview.AlignLeft).
                SetText(" " + text)
    
            return textView
        }
    
        app = tview.NewApplication()
    
        headerBar := NewUIHeaderBar()
    
        content := tview.NewGrid()
        content.SetBackgroundColor(tcell.ColorWhite)
        content.SetColumns(0)
    
        footer := newPrimitive("")
        footer.SetBackgroundColor(tcell.ColorDarkMagenta)
        footer.SetTextColor(tcell.ColorWhite)
    
        grid := tview.NewGrid().
            SetRows(10, 0, 1).
            SetColumns(0).
            SetBorders(false).
            AddItem(headerBar.Primitive, 0, 0, 1, 1, 0, 0, false).
            AddItem(content, 1, 0, 1, 1, 0, 0, false).
            AddItem(footer, 2, 0, 1, 1, 0, 0, false)
    
        frame := tview.NewFrame(grid).
            SetBorders(1, 1, 0, 0, 2, 2)
        frame.SetBackgroundColor(tcell.ColorDarkGray)
    
        app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
            if event.Key() == tcell.KeyCtrlC || event.Key() == tcell.KeyESC{
                daemon.Shutdown()
    
                return nil
            }
    
            return event
        })
    
        app.SetBeforeDrawFunc(func(screen tcell.Screen) bool {
            headerBar.Update()
    
            rows := make([]int, 1)
            rows[0] = 1
            _, _, _, height := content.GetRect()
            for i := 0; i < len(messageLog) && i < height - 2; i++ {
                rows = append(rows, 1)
            }
    
            content.Clear()
            content.SetRows(rows...)
    
            blankLine := newPrimitive("")
            blankLine.SetBackgroundColor(tcell.ColorWhite)
            content.AddItem(blankLine, 0, 0, 1, 1, 0, 0, false)
    
            for i, message := range messageLog[len(messageLog) - len(rows) - 1 + 2:] {
                if i < height - 2 {
                    content.AddItem(NewUILogEntry(*message).Primitive, i+1, 0, 1, 1, 0, 0, false)
                }
            }
    
            return false
        })
    
        daemon.BackgroundWorker(func() {
            for {
                select {
                case <- daemon.ShutdownSignal:
                    return
                case <- time.After(1 * time.Second):
                    app.QueueUpdateDraw(func() {})
                }
            }
        })
    
        daemon.BackgroundWorker(func() {
            if err := app.SetRoot(frame, true).SetFocus(frame).Run(); err != nil {
                panic(err)
            }
        })
    }
    
    var PLUGIN = node.NewPlugin("Status Screen", configure, run)