diff options
| -rw-r--r-- | internal/client/ui/colors/colors.go | 1 | ||||
| -rw-r--r-- | internal/client/ui/core/chat/chat.go | 81 | ||||
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 8 |
3 files changed, 84 insertions, 6 deletions
diff --git a/internal/client/ui/colors/colors.go b/internal/client/ui/colors/colors.go index b95c423..10d91e3 100644 --- a/internal/client/ui/colors/colors.go +++ b/internal/client/ui/colors/colors.go @@ -22,6 +22,7 @@ var ( Green = lipgloss.Color("#46d46c") Purple = lipgloss.Color("#BB91F0") DarkPurple = lipgloss.Color("#87123d") + Orange = lipgloss.Color("#F5A670") Background = DarkMidnightBlue BackgroundHighlight = MidnightBlue diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index 70d6654..8600f46 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -1,6 +1,9 @@ package chat import ( + "strconv" + "strings" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -9,12 +12,18 @@ import ( ) var ( + focusStyle = lipgloss.NewStyle().Foreground(colors.Focus) + ViBlurredBorder = lipgloss.NewStyle(). - BorderStyle(lipgloss.RoundedBorder()).UnsetBorderBottom() - ViFocusedBorder = lipgloss.NewStyle(). - BorderStyle(lipgloss.ThickBorder()).UnsetBorderBottom() + Border(lipgloss.RoundedBorder(), true, true, false). + Padding(0, 1) + ViFocusedBorder = ViBlurredBorder.BorderForeground(colors.Focus) + + VimModeStyle = lipgloss.NewStyle().Bold(true) ) +const MaxCharCount = 2000 + type Model struct { vi viminput.Model focus bool @@ -38,17 +47,77 @@ func (m Model) Init() tea.Cmd { } func (m Model) View() string { - input := m.vi.View() + var builder strings.Builder + input := m.vi.View() if m.locked { input = ViFocusedBorder.Render(input) } else { input = ViBlurredBorder.Render(input) } + builder.WriteString(input) + builder.WriteByte('\n') + + border := lipgloss.RoundedBorder() + style := lipgloss.NewStyle() + if m.locked { + style = focusStyle + } + width := lipgloss.Width(input) + + leftAngle := style.Render("") + rightAngle := style.Render("") + + leftCorner := border.BottomLeft + border.Bottom + builder.WriteString(style.Render(leftCorner)) + width -= lipgloss.Width(leftCorner) + + builder.WriteString(leftAngle) + width -= lipgloss.Width(leftAngle) + mode := VimModeStyle.Foreground(colors.Gray).Render(" NONE ") + if m.locked { + switch m.vi.Mode() { + case viminput.InsertMode: + mode = VimModeStyle.Foreground(colors.Green).Render(" INSERT ") + case viminput.NormalMode: + mode = VimModeStyle.Foreground(colors.Orange).Render(" NORMAL ") + case viminput.OpendingMode: + mode = VimModeStyle.Foreground(colors.Red).Render(" O-PENDING ") + case viminput.VisualMode: + mode = VimModeStyle.Foreground(colors.Turquoise).Render(" VISUAL ") + case viminput.VisualLineMode: + mode = VimModeStyle.Foreground(colors.Turquoise).Render(" V-LINE ") + } + } + builder.WriteString(mode) + width -= lipgloss.Width(mode) + builder.WriteString(rightAngle) + width -= lipgloss.Width(rightAngle) + + width -= lipgloss.Width(leftAngle) + count := m.vi.Count() + countStr := " " + strconv.Itoa(count) + if count > MaxCharCount { + countStr = lipgloss.NewStyle().Foreground(colors.Red).Render(countStr) + } + countStr += " / " + strconv.Itoa(MaxCharCount) + " " + width -= lipgloss.Width(countStr) + width -= lipgloss.Width(rightAngle) + + rightCorner := border.Bottom + border.BottomRight + width -= lipgloss.Width(rightCorner) + + bottomCount := width / lipgloss.Width(border.Bottom) + bottom := strings.Repeat(border.Bottom, bottomCount) + builder.WriteString(style.Render(bottom)) - result := input + builder.WriteString(leftAngle) + builder.WriteString(countStr) + builder.WriteString(rightAngle) + builder.WriteString(style.Render(rightCorner)) + // NORMAL master 1 LSP utf-8 go 51% 67:21 - return result + return builder.String() } func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index db2881d..5bc2314 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -1986,3 +1986,11 @@ func (m *Model) Redo() { cursorColumn: m.cursorColumn, }) } + +func (m *Model) Count() int { + sum := 0 + for _, line := range m.lines { + sum += len(line) + } + return sum + len(m.lines) - 1 +} |
