소스 검색

wip: refactoring tui

adamdottv 8 달 전
부모
커밋
ae339015fc

+ 1 - 1
packages/tui/internal/components/chat/editor.go

@@ -256,7 +256,7 @@ func (m *editorComponent) View() string {
 		m.textarea.View(),
 	)
 	textarea = styles.BaseStyle().
-		Width(m.width). // -2).
+		Width(m.width).
 		Border(lipgloss.NormalBorder(), true, true).
 		BorderForeground(t.Border()).
 		Render(textarea)

+ 7 - 5
packages/tui/internal/components/core/status.go

@@ -101,13 +101,15 @@ func (m statusComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 
 func logo() string {
 	t := theme.CurrentTheme()
-	mark := styles.Bold().Foreground(t.Primary()).Render("◧ ")
-	open := styles.Muted().Render("open")
-	code := styles.BaseStyle().Bold(true).Render("code")
-	version := styles.Muted().Render(app.Info.Version)
+	base := lipgloss.NewStyle().Background(t.BackgroundElement()).Foreground(t.TextMuted()).Render
+	emphasis := lipgloss.NewStyle().Bold(true).Background(t.BackgroundElement()).Foreground(t.Text()).Render
+
+	open := base("open")
+	code := emphasis("code ")
+	version := base(app.Info.Version)
 	return styles.Padded().
 		Background(t.BackgroundElement()).
-		Render(mark + open + code + " " + version)
+		Render(open + code + version)
 }
 
 func formatTokensAndCost(tokens float32, contextWindow float32, cost float32) string {

+ 10 - 10
packages/tui/internal/components/dialog/complete.go

@@ -82,7 +82,7 @@ type CompletionDialog interface {
 	SetWidth(width int)
 }
 
-type completionDialogCmp struct {
+type completionDialogComponent struct {
 	query                string
 	completionProvider   CompletionProvider
 	width                int
@@ -105,11 +105,11 @@ var completionDialogKeys = completionDialogKeyMap{
 	),
 }
 
-func (c *completionDialogCmp) Init() tea.Cmd {
+func (c *completionDialogComponent) Init() tea.Cmd {
 	return nil
 }
 
-func (c *completionDialogCmp) complete(item CompletionItemI) tea.Cmd {
+func (c *completionDialogComponent) complete(item CompletionItemI) tea.Cmd {
 	value := c.pseudoSearchTextArea.Value()
 
 	if value == "" {
@@ -125,7 +125,7 @@ func (c *completionDialogCmp) complete(item CompletionItemI) tea.Cmd {
 	)
 }
 
-func (c *completionDialogCmp) close() tea.Cmd {
+func (c *completionDialogComponent) close() tea.Cmd {
 	c.listView.SetItems([]CompletionItemI{})
 	c.pseudoSearchTextArea.Reset()
 	c.pseudoSearchTextArea.Blur()
@@ -133,7 +133,7 @@ func (c *completionDialogCmp) close() tea.Cmd {
 	return util.CmdHandler(CompletionDialogCloseMsg{})
 }
 
-func (c *completionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	var cmds []tea.Cmd
 	switch msg := msg.(type) {
 	case tea.KeyMsg:
@@ -203,7 +203,7 @@ func (c *completionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	return c, tea.Batch(cmds...)
 }
 
-func (c *completionDialogCmp) View() string {
+func (c *completionDialogComponent) View() string {
 	t := theme.CurrentTheme()
 	baseStyle := styles.BaseStyle()
 
@@ -231,15 +231,15 @@ func (c *completionDialogCmp) View() string {
 		Render(c.listView.View())
 }
 
-func (c *completionDialogCmp) SetWidth(width int) {
+func (c *completionDialogComponent) SetWidth(width int) {
 	c.width = width
 }
 
-func (c *completionDialogCmp) BindingKeys() []key.Binding {
+func (c *completionDialogComponent) BindingKeys() []key.Binding {
 	return layout.KeyMapToSlice(completionDialogKeys)
 }
 
-func NewCompletionDialogCmp(completionProvider CompletionProvider) CompletionDialog {
+func NewCompletionDialogComponent(completionProvider CompletionProvider) CompletionDialog {
 	ti := textarea.New()
 
 	items, err := completionProvider.GetChildEntries("")
@@ -254,7 +254,7 @@ func NewCompletionDialogCmp(completionProvider CompletionProvider) CompletionDia
 		false,
 	)
 
-	return &completionDialogCmp{
+	return &completionDialogComponent{
 		query:                "",
 		completionProvider:   completionProvider,
 		pseudoSearchTextArea: ti,

+ 2 - 2
packages/tui/internal/components/dialog/session.go

@@ -122,7 +122,7 @@ func (s *sessionDialogComponent) View() string {
 	maxWidth := 40 // Minimum width
 	for _, sess := range s.sessions {
 		if len(sess.Title) > maxWidth-4 { // Account for padding
-			maxWidth = len(sess.Title) + 4
+			maxWidth = len(sess.Title) + 0
 		}
 	}
 
@@ -173,7 +173,7 @@ func (s *sessionDialogComponent) View() string {
 		lipgloss.Left,
 		title,
 		baseStyle.Width(maxWidth).Render(""),
-		baseStyle.Width(maxWidth).Render(lipgloss.JoinVertical(lipgloss.Left, sessionItems...)),
+		baseStyle.Width(maxWidth-2).Render(lipgloss.JoinVertical(lipgloss.Left, sessionItems...)),
 		baseStyle.Width(maxWidth).Render(""),
 	)
 

+ 10 - 10
packages/tui/internal/components/util/simple-list.go

@@ -22,7 +22,7 @@ type SimpleList[T SimpleListItem] interface {
 	GetItems() []T
 }
 
-type simpleListCmp[T SimpleListItem] struct {
+type simpleListComponent[T SimpleListItem] struct {
 	fallbackMsg         string
 	items               []T
 	selectedIdx         int
@@ -59,11 +59,11 @@ var simpleListKeys = simpleListKeyMap{
 	),
 }
 
-func (c *simpleListCmp[T]) Init() tea.Cmd {
+func (c *simpleListComponent[T]) Init() tea.Cmd {
 	return nil
 }
 
-func (c *simpleListCmp[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+func (c *simpleListComponent[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	switch msg := msg.(type) {
 	case tea.KeyMsg:
 		switch {
@@ -83,11 +83,11 @@ func (c *simpleListCmp[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 	return c, nil
 }
 
-func (c *simpleListCmp[T]) BindingKeys() []key.Binding {
+func (c *simpleListComponent[T]) BindingKeys() []key.Binding {
 	return layout.KeyMapToSlice(simpleListKeys)
 }
 
-func (c *simpleListCmp[T]) GetSelectedItem() (T, int) {
+func (c *simpleListComponent[T]) GetSelectedItem() (T, int) {
 	if len(c.items) > 0 {
 		return c.items[c.selectedIdx], c.selectedIdx
 	}
@@ -96,20 +96,20 @@ func (c *simpleListCmp[T]) GetSelectedItem() (T, int) {
 	return zero, -1
 }
 
-func (c *simpleListCmp[T]) SetItems(items []T) {
+func (c *simpleListComponent[T]) SetItems(items []T) {
 	c.selectedIdx = 0
 	c.items = items
 }
 
-func (c *simpleListCmp[T]) GetItems() []T {
+func (c *simpleListComponent[T]) GetItems() []T {
 	return c.items
 }
 
-func (c *simpleListCmp[T]) SetMaxWidth(width int) {
+func (c *simpleListComponent[T]) SetMaxWidth(width int) {
 	c.maxWidth = width
 }
 
-func (c *simpleListCmp[T]) View() string {
+func (c *simpleListComponent[T]) View() string {
 	t := theme.CurrentTheme()
 	baseStyle := styles.BaseStyle()
 
@@ -149,7 +149,7 @@ func (c *simpleListCmp[T]) View() string {
 }
 
 func NewSimpleList[T SimpleListItem](items []T, maxVisibleItems int, fallbackMsg string, useAlphaNumericKeys bool) SimpleList[T] {
-	return &simpleListCmp[T]{
+	return &simpleListComponent[T]{
 		fallbackMsg:         fallbackMsg,
 		items:               items,
 		maxVisibleItems:     maxVisibleItems,

+ 1 - 1
packages/tui/internal/page/chat.go

@@ -189,7 +189,7 @@ func (p *chatPage) BindingKeys() []key.Binding {
 
 func NewChatPage(app *app.App) layout.ModelWithView {
 	cg := completions.NewFileAndFolderContextGroup()
-	completionDialog := dialog.NewCompletionDialogCmp(cg)
+	completionDialog := dialog.NewCompletionDialogComponent(cg)
 	messagesContainer := layout.NewContainer(
 		chat.NewMessagesComponent(app),
 	)

+ 2 - 4
packages/tui/internal/styles/styles.go

@@ -9,9 +9,7 @@ import (
 // BaseStyle returns the base style with background and foreground colors
 func BaseStyle() lipgloss.Style {
 	t := theme.CurrentTheme()
-	return lipgloss.NewStyle().
-		Background(t.Background()).
-		Foreground(t.Text())
+	return lipgloss.NewStyle().Foreground(t.Text())
 }
 
 func Panel() lipgloss.Style {
@@ -30,7 +28,7 @@ func Regular() lipgloss.Style {
 
 func Muted() lipgloss.Style {
 	t := theme.CurrentTheme()
-	return lipgloss.NewStyle().Background(t.Background()).Foreground(t.TextMuted())
+	return lipgloss.NewStyle().Foreground(t.TextMuted())
 }
 
 // Bold returns a bold style