Skip to content

Commit

Permalink
Version and build date added to the header
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoluyaktov committed Jul 20, 2023
1 parent 0853e23 commit 4cb4790
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ before:
builds:
- id: default
main: ./main.go
binary: abb_ia
ldflags: -X github.com/vpoluyaktov/abb_ia/internal/config.appVersion={{.Version}} -X github.com/vpoluyaktov/abb_ia/internal/config.buildDate={{.Date}}
env: [CGO_ENABLED=0]
goos:
- linux
Expand All @@ -16,7 +18,7 @@ builds:
- amd64
- 386
- arm64
binary: abb_ia


release:
ids: [ default ]
Expand Down
23 changes: 22 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package config

import "time"

// singleton
var (
configInstance *Config
appVersion, buildDate string
)

type Config struct {
Expand Down Expand Up @@ -114,4 +117,22 @@ func SetSampleRate(b string) {

func SampleRate() string {
return configInstance.sampleRate
}
}

func AppVersion() string {
if appVersion == "" {
appVersion = "0.0.0"
}
return appVersion
}

func BuildDate() string {
// 2023-07-20T14:45:12Z
fmt := "01/02/2006"
bd, err := time.Parse(time.RFC3339, buildDate)
if buildDate != "" && err != nil {
return bd.Format(fmt)
} else {
return time.Now().Format(fmt)
}
}
11 changes: 1 addition & 10 deletions internal/ui/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type footer struct {
busyFlag bool
busyIndicator *tview.TextView
statusMessage *tview.TextView
version *tview.TextView
}

func newFooter(dispatcher *mq.Dispatcher) *footer {
Expand All @@ -36,18 +35,10 @@ func newFooter(dispatcher *mq.Dispatcher) *footer {
f.statusMessage.SetTextColor(footerFgColor)
f.statusMessage.SetBackgroundColor(footerBgColor)

f.version = tview.NewTextView()
f.version.SetText("v.0.0.1")
f.version.SetTextAlign(tview.AlignRight)
f.version.SetBorder(false)
f.version.SetTextColor(footerFgColor)
f.version.SetBackgroundColor(footerBgColor)

f.grid = tview.NewGrid()
f.grid.SetColumns(8, -1, 10)
f.grid.SetColumns(8, -1)
f.grid.AddItem(f.busyIndicator, 0, 0, 1, 1, 0, 0, false)
f.grid.AddItem(f.statusMessage, 0, 1, 1, 1, 0, 0, false)
f.grid.AddItem(f.version, 0, 2, 1, 1, 0, 0, false)

return f
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newFrame(dispatcher *mq.Dispatcher) *frame {
}

func (f *frame) addHeader(header *header) {
f.grid.AddItem(header.view, 0, 0, 1, 1, 0, 0, false)
f.grid.AddItem(header.grid, 0, 0, 1, 1, 0, 0, false)
}

func (f *frame) addFooter(footer *footer) {
Expand Down
32 changes: 24 additions & 8 deletions internal/ui/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,41 @@ package ui

import (
"github.com/rivo/tview"
"github.com/vpoluyaktov/abb_ia/internal/config"
"github.com/vpoluyaktov/abb_ia/internal/dto"
"github.com/vpoluyaktov/abb_ia/internal/mq"
)

type header struct {
view *tview.TextView
mq *mq.Dispatcher
mq *mq.Dispatcher
grid *tview.Grid
appName *tview.TextView
version *tview.TextView
}

func newHeader(dispatcher *mq.Dispatcher) *header {
h := &header{}
h.mq = dispatcher
h.view = tview.NewTextView()
h.view.SetText("Audiobook Builder - Internet Archive version")
h.view.SetBorder(false)
h.view.SetTextColor(headerFgColor)
h.view.SetBackgroundColor(headerBGColor)

h.mq.RegisterListener(mq.Header, h.dispatchMessage)

h.appName = tview.NewTextView()
h.appName.SetText("Audiobook Builder - Internet Archive version")
h.appName.SetBorder(false)
h.appName.SetTextColor(headerFgColor)
h.appName.SetBackgroundColor(headerBGColor)

h.version = tview.NewTextView()
h.version.SetText("v" + config.AppVersion() + " (" + config.BuildDate() + ")")
h.version.SetTextAlign(tview.AlignRight)
h.version.SetBorder(false)
h.version.SetTextColor(footerFgColor)
h.version.SetBackgroundColor(footerBgColor)

h.grid = tview.NewGrid()
h.grid.SetColumns(-1, 50)
h.grid.AddItem(h.appName, 0, 0, 1, 1, 0, 0, false)
h.grid.AddItem(h.version, 0, 1, 1, 1, 0, 0, false)

return h
}

Expand Down

0 comments on commit 4cb4790

Please sign in to comment.