Replace bottombar with custom component
ADD
ui/bottombar.go
+package ui
+
+import (
+ "fmt"
+
+ "github.com/Bios-Marcel/cordless/config"
+ "github.com/Bios-Marcel/cordless/tview"
+ "github.com/Bios-Marcel/cordless/ui/shortcutdialog"
+ "github.com/Bios-Marcel/cordless/ui/tviewutil"
+ "github.com/gdamore/tcell"
+ "github.com/mattn/go-runewidth"
+ "github.com/rivo/uniseg"
+)
+
+// BottomBar custom simple component to render static information at the bottom
+// of the application.
+type BottomBar struct {
+ *tview.Box
+ items []*bottomBarItem
+}
+
+type bottomBarItem struct {
+ name string
+ content string
+}
+
+// Draw draws this primitive onto the screen. Implementers can call the
+// screen's ShowCursor() function but should only do so when they have focus.
+// (They will need to keep track of this themselves.)
+func (b *BottomBar) Draw(screen tcell.Screen) bool {
+ hasDrawn := b.Box.Draw(screen)
+ if !hasDrawn {
+ return false
+ }
+
+ style := tcell.StyleDefault.
+ //Background(config.GetTheme().PrimitiveBackgroundColor).
+ Foreground(config.GetTheme().PrimaryTextColor).
+ Reverse(true)
+
+ xPos, yPos, _, _ := b.GetInnerRect()
+ for _, item := range b.items {
+ gr := uniseg.NewGraphemes(item.content)
+ for gr.Next() {
+ r := gr.Runes()
+ width := runewidth.StringWidth(gr.Str())
+ var comb []rune
+ if len(r) > 1 {
+ comb = r[1:]
+ }
+
+ screen.SetContent(xPos, yPos, r[0], comb, style)
+ xPos += width
+ }
+
+ //Spacing between items
+ xPos++
+ screen.SetContent(xPos, yPos, ' ', nil, tcell.StyleDefault)
+ }
+
+ return true
+}
+
+// NewBottomBar creates a new bar to be put at the bottom aplication.
+// It contains static information and hints.
+func NewBottomBar(username string) *BottomBar {
+ loggedInAsText := fmt.Sprintf("Logged in as: '%s'", tviewutil.Escape(username))
+ shortcutInfoText := fmt.Sprintf("View / Change shortcuts: %s", shortcutdialog.EventToString(shortcutsDialogShortcut))
+
+ bottomBar := &BottomBar{
+ Box: tview.NewBox(),
+ items: []*bottomBarItem{
+ {
+ name: "username",
+ content: loggedInAsText,
+ },
+ {
+ name: "shortcut-info",
+ content: shortcutInfoText,
+ },
+ },
+ }
+ bottomBar.SetBorder(false)
+
+ return bottomBar
+}

MODIFY
ui/window.go
ui/window.go
@@ -9,7 +9,6 @@ import (
"strings"
"time"
- "github.com/mattn/go-runewidth"
"github.com/mdp/qrterminal/v3"
"github.com/Bios-Marcel/cordless/fileopen"
@@ -1149,29 +1148,7 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
window.rootContainer.AddItem(window.dialogReplacement, 2, 0, false)
if config.Current.ShowBottomBar {
- bottomBar := tview.NewFlex().SetDirection(tview.FlexColumn)
- bottomBar.SetBackgroundColor(config.GetTheme().PrimitiveBackgroundColor)
-
- loggedInAsText := fmt.Sprintf("Logged in as: '%s'", tviewutil.Escape(session.State.User.String()))
- if vtxxx {
- // For some reason there's an offset when the tag is applied. I have no idea how to fix this.
- // Except maybe unify the bottom bar into a single TextView rather than using two in a Flex.
- loggedInAsText = "[::r]" + loggedInAsText
- }
- loggedInAs := tview.NewTextView().SetText(loggedInAsText).SetDynamicColors(true)
- loggedInAs.SetTextColor(config.GetTheme().PrimitiveBackgroundColor).SetBackgroundColor(config.GetTheme().PrimaryTextColor)
-
- bottomBar.AddItem(loggedInAs, runewidth.StringWidth(loggedInAsText), 0, false)
- bottomBar.AddItem(tview.NewBox(), 1, 0, false)
-
- shortcutInfoText := fmt.Sprintf("View / Change shortcuts: %s", shortcutdialog.EventToString(shortcutsDialogShortcut))
- if vtxxx {
- shortcutInfoText = "[::r]" + shortcutInfoText
- }
- shortcutInfo := tview.NewTextView().SetText(shortcutInfoText).SetDynamicColors(true)
- shortcutInfo.SetTextColor(config.GetTheme().PrimitiveBackgroundColor).SetBackgroundColor(config.GetTheme().PrimaryTextColor)
- bottomBar.AddItem(shortcutInfo, runewidth.StringWidth(shortcutInfoText), 0, false)
-
+ bottomBar := NewBottomBar(session.State.User.Username)
window.rootContainer.AddItem(bottomBar, 1, 0, false)
}

Replace bottombar with custom component