Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed Apr 3, 2021
1 parent d05df70 commit 2fc3070
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions tui/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,39 @@ const (
)

func Timeline(MastodonClient *mastodon.Client) {
app := tview.NewApplication()
app := tview.NewApplication()

input := tview.NewInputField().
SetLabel("@user.instance.org: ").
SetLabelColor(tcell.ColorDefault).
SetFieldBackgroundColor(tcell.ColorDefault).
SetDoneFunc(func(key tcell.Key) {
// app.Stop()
})

logoBox := tview.NewTextView().
stream := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetWrap(true)

box := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(logoBox, 0, 1, true)

app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlN {
_, _, w, _ := logoBox.Box.GetInnerRect()
output := mast.Timeline(MastodonClient, w)
fmt.Fprint(logoBox, tview.TranslateANSI(output))
return nil
}
return event
})

if err := app.SetRoot(box, true).Run(); err != nil {
panic(err)
grid := tview.NewGrid().
SetRows(0, 1).
SetColumns(0).
SetBorders(true).
AddItem(stream, 0, 0, 1, 1, 0, 0, false).
AddItem(input, 1, 0, 1, 1, 0, 0, true)

app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlN {
_, _, w, _ := stream.Box.GetInnerRect()
output := mast.Timeline(MastodonClient, w)
fmt.Fprint(stream, tview.TranslateANSI(output))
return nil
}
return event
})

if err := app.SetRoot(grid, true).Run(); err != nil {
panic(err)
}
}

0 comments on commit 2fc3070

Please sign in to comment.