Added frequency name at the top of chat (might flip the bg/fg later)

This commit is contained in:
2025-01-19 18:53:57 +02:00
parent 0a5ed18ac8
commit abe7eabce9
3 changed files with 28 additions and 6 deletions

View File

@@ -77,7 +77,7 @@ ___] | |__] | \| | | \|`)
focusedRememberChecked = focusedStyle.Render(blurredRememberChecked)
focusedRememberUnchecked = focusedStyle.Render(blurredRememberUnchecked)
centerStyle = lipgloss.NewStyle().Width(authWidth).AlignHorizontal(0.5)
centerStyle = lipgloss.NewStyle().Width(authWidth).AlignHorizontal(lipgloss.Center)
)
func init() {

View File

@@ -71,6 +71,11 @@ var (
SetString("\n(edited)").String()
WidthWithoutVi = PaddingCount*2 + lipgloss.Width(LeftCorner) + lipgloss.Width(RightCorner)
FrequencyNameStyle = lipgloss.NewStyle().
Background(colors.BackgroundDim).
AlignHorizontal(lipgloss.Center).
Border(lipgloss.ThickBorder(), false, false, true)
)
const (
@@ -142,9 +147,13 @@ func (m Model) Init() tea.Cmd {
}
func (m *Model) Prerender() {
frequencyName := m.renderFrequencyName()
frequencyHeight := lipgloss.Height(frequencyName)
messagebox := m.renderMessageBox()
messagesHeight := ui.Height - lipgloss.Height(messagebox)
messagesHeight -= 1 // For the extra \n at the end
messageBoxHeight := lipgloss.Height(messagebox)
messagesHeight := ui.Height - messageBoxHeight - frequencyHeight
// if m.messagesCache == nil || messagesHeight != m.messagesHeight {
// // Re-render
@@ -154,7 +163,7 @@ func (m *Model) Prerender() {
m.messagesCache = &messages
m.messagesHeight = messagesHeight
m.prerender = *m.messagesCache + messagebox
m.prerender = frequencyName + *m.messagesCache + messagebox
}
func (m Model) View() string {
@@ -870,3 +879,16 @@ func (m *Model) editMessage() tea.Cmd {
func (m *Model) SetWidth(width int) {
m.width = width
}
func (m *Model) renderFrequencyName() string {
networkId := state.NetworkId(m.networkIndex)
if m.frequencyIndex == -1 || networkId == nil {
return ""
}
frequency := state.State.Frequencies[*networkId][m.frequencyIndex]
color := lipgloss.Color(frequency.HexColor)
return FrequencyNameStyle.Width(m.width).Foreground(color).
Render(frequency.Name) + "\n"
}

View File

@@ -18,8 +18,8 @@ import (
const (
DEBUG = true
MinWidth = 85
Center = 0.499
MinWidth = 85
Center lipgloss.Position = 0.499
)
var (