Skip to content
Snippets Groups Projects
app.go 743 B
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package app
    
    
    import "github.com/rivo/tview"
    
    type view interface {
    	GetContent() tview.Primitive
    }
    
    Malte Bauch's avatar
    Malte Bauch committed
    
    
    type App struct {
    
    Malte Bauch's avatar
    Malte Bauch committed
    	app   *tview.Application
    	pages *tview.Pages
    
    }
    
    func NewApp() *App {
    	a := &App{
    		app: tview.NewApplication(),
    	}
    	return a
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (a *App) SetRoot(v view) {
    	a.pages = v.GetContent().(*tview.Pages)
    	a.app.SetRoot(a.pages, true)
    }
    
    func (a *App) SwitchPage(s string) {
    	if a.pages.HasPage(s) {
    		a.pages.SwitchToPage(s)
    	}
    }
    
    func (a *App) AddPage(name string, p view) {
    	a.pages.AddPage(name, p.GetContent(), true, false)
    
    }
    
    func (a *App) Run() error {
    	return a.app.Run()
    }
    
    Malte Bauch's avatar
    Malte Bauch committed
    
    func (a *App) Stop() {
    	a.app.Stop()
    }
    
    Malte Bauch's avatar
    Malte Bauch committed
    func (a *App) Draw() {
    	a.app.Draw()
    }
    
    
    func (a *App) SetFocus(v tview.Primitive) {
    	a.app.SetFocus(v)
    }