Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusLindroth committed Mar 24, 2020
1 parent 25ab273 commit 9e9f214
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 322 deletions.
2 changes: 0 additions & 2 deletions app.go
Expand Up @@ -2,11 +2,9 @@ package main

import (
"github.com/mattn/go-mastodon"
"github.com/rivo/tview"
)

type App struct {
App *tview.Application
UI *UI
Me *mastodon.Account
API *API
Expand Down
38 changes: 24 additions & 14 deletions authoverlay.go
Expand Up @@ -16,28 +16,38 @@ const (
authCodeStep
)

func NewAuthoverlay(app *App, flex *tview.Flex, view *tview.InputField, controls *Controls) *AuthOverlay {
return &AuthOverlay{
func NewAuthOverlay(app *App) *AuthOverlay {
a := &AuthOverlay{
app: app,
Flex: flex,
View: view,
Controls: controls,
Flex: tview.NewFlex(),
Input: tview.NewInputField(),
Text: tview.NewTextView(),
authStep: authNoneStep,
}

a.Flex.SetBackgroundColor(app.Config.Style.Background)
a.Input.SetBackgroundColor(app.Config.Style.Background)
a.Input.SetFieldBackgroundColor(app.Config.Style.Background)
a.Input.SetFieldTextColor(app.Config.Style.Text)
a.Text.SetBackgroundColor(app.Config.Style.Background)
a.Text.SetTextColor(app.Config.Style.Text)
a.Flex.SetDrawFunc(app.Config.ClearContent)
a.Draw()
return a
}

type AuthOverlay struct {
app *App
Flex *tview.Flex
View *tview.InputField
Controls *Controls
Input *tview.InputField
Text *tview.TextView
authStep authStep
account AccountRegister
redirectURL string
}

func (a *AuthOverlay) GotInput() {
input := strings.TrimSpace(a.View.GetText())
input := strings.TrimSpace(a.Input.GetText())
switch a.authStep {
case authInstanceStep:
if !(strings.HasPrefix(input, "https://") || strings.HasPrefix(input, "http://")) {
Expand All @@ -55,7 +65,7 @@ func (a *AuthOverlay) GotInput() {
}
a.account = acc
openURL(acc.AuthURI)
a.View.SetText("")
a.Input.SetText("")
a.authStep = authCodeStep
a.Draw()
case authCodeStep:
Expand Down Expand Up @@ -91,14 +101,14 @@ func (a *AuthOverlay) Draw() {
switch a.authStep {
case authNoneStep:
a.authStep = authInstanceStep
a.View.SetText("")
a.Input.SetText("")
a.Draw()
return
case authInstanceStep:
a.View.SetLabel("Instance: ")
a.Controls.View.SetText("Enter the url of your instance. Will default to https://\nPress Enter when done")
a.Input.SetLabel("Instance: ")
a.Text.SetText("Enter the url of your instance. Will default to https://\nPress Enter when done")
case authCodeStep:
a.Controls.View.SetText(fmt.Sprintf("The login URL has opened in your browser. If it didn't work open this URL\n%s", a.account.AuthURI))
a.View.SetLabel("Authorization code: ")
a.Text.SetText(fmt.Sprintf("The login URL has opened in your browser. If it didn't work open this URL\n%s", a.account.AuthURI))
a.Input.SetLabel("Authorization code: ")
}
}
21 changes: 13 additions & 8 deletions cmdbar.go
Expand Up @@ -6,22 +6,27 @@ import (
"github.com/rivo/tview"
)

func NewCmdBar(app *App, view *tview.InputField) *CmdBar {
return &CmdBar{
app: app,
View: view,
func NewCmdBar(app *App) *CmdBar {
c := &CmdBar{
app: app,
Input: tview.NewInputField(),
}

c.Input.SetFieldBackgroundColor(app.Config.Style.Background)
c.Input.SetFieldTextColor(app.Config.Style.Text)

return c
}

type CmdBar struct {
app *App
View *tview.InputField
app *App
Input *tview.InputField
}

func (c *CmdBar) GetInput() string {
return strings.TrimSpace(c.View.GetText())
return strings.TrimSpace(c.Input.GetText())
}

func (c *CmdBar) ClearInput() {
c.View.SetText("")
c.Input.SetText("")
}
10 changes: 10 additions & 0 deletions linkoverlay.go
Expand Up @@ -12,6 +12,16 @@ func NewLinkOverlay(app *App) *LinkOverlay {
TextBottom: tview.NewTextView(),
List: tview.NewList(),
}

l.TextBottom.SetBackgroundColor(app.Config.Style.Background)
l.List.SetBackgroundColor(app.Config.Style.Background)
l.List.SetMainTextColor(app.Config.Style.Text)
l.List.SetSelectedBackgroundColor(app.Config.Style.ListSelectedBackground)
l.List.SetSelectedTextColor(app.Config.Style.ListSelectedText)
l.List.ShowSecondaryText(false)
l.List.SetHighlightFullLine(true)
l.Flex.SetDrawFunc(app.Config.ClearContent)

l.TextBottom.SetText("[O]pen")
return l
}
Expand Down

0 comments on commit 9e9f214

Please sign in to comment.