Skip to content

Commit

Permalink
Merge pull request #17 from algorandfoundation/feat/border-labels
Browse files Browse the repository at this point in the history
feat: border titles
  • Loading branch information
HashMapsData2Value authored Oct 29, 2024
2 parents d7ec2cc + ade4db3 commit fde8e8a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ui/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func (m ProtocolViewModel) View() string {
if isCompact && m.Data.NeedsUpdate {
rows = append(rows, blue.Render(" Upgrade Available: ")+green.Render(strconv.FormatBool(m.Data.NeedsUpdate)))
}
return topSections(max(0, size)).Render(lipgloss.JoinVertical(lipgloss.Left,
return WithTitle("Protocol", topSections(max(0, size)).Render(lipgloss.JoinVertical(lipgloss.Left,
rows...,
))
)))
}

// MakeProtocolViewModel constructs a ProtocolViewModel using a given StatusModel and predefined metrics.
Expand Down
4 changes: 2 additions & 2 deletions ui/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ func (m StatusViewModel) View() string {

row3 := lipgloss.JoinHorizontal(lipgloss.Left, beginning, middle, end)

return topSections(max(0, size)).Render(
return WithTitle("Status", topSections(max(0, size)).Render(
lipgloss.JoinVertical(lipgloss.Left,
row1,
"",
cyan.Render(" -- "+strconv.Itoa(m.Data.Metrics.Window)+" round average --"),
row2,
row3,
))
)))
}

// MakeStatusViewModel constructs the model to be used in a tea.Program
Expand Down
16 changes: 15 additions & 1 deletion ui/style.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ui

import "github.com/charmbracelet/lipgloss"
import (
"github.com/charmbracelet/lipgloss"
"strings"
)

var (
rounderBorder = func() lipgloss.Style {
Expand Down Expand Up @@ -34,3 +37,14 @@ var (
Foreground(lipgloss.Color("12")).
Render
)

func WithTitle(title string, view string) string {
r := []rune(view)
if lipgloss.Width(view) >= len(title)+4 {
b, _, _, _, _ := rounderBorder.GetBorder()
id := strings.IndexRune(view, []rune(b.Top)[0])
start := string(r[0:id])
return start + title + string(r[len(title)+id:])
}
return view
}

0 comments on commit fde8e8a

Please sign in to comment.