~tgrosinger/ledger-tui

25bfb521a6f09dd22e2fc1ce8cddc8f346da612f — Tony Grosinger 1 year, 3 months ago 61ed583
Switch to a fullscreen layout with side-by-side frames
M go.mod => go.mod +5 -4
@@ 2,14 2,15 @@ module github.com/tgrosinger/ledger-tui

go 1.18

require github.com/charmbracelet/bubbletea v0.22.0
require (
	github.com/charmbracelet/bubbletea v0.22.0
	github.com/charmbracelet/lipgloss v0.5.0
	github.com/spf13/cobra v1.5.0
)

require (
	github.com/atotto/clipboard v0.1.4 // indirect
	github.com/charmbracelet/lipgloss v0.5.0 // indirect
	github.com/inconshreveable/mousetrap v1.0.0 // indirect
	github.com/lrstanley/bubblezone v0.0.0-20220729154607-e408d1dc3890 // indirect
	github.com/spf13/cobra v1.5.0 // indirect
	github.com/spf13/pflag v1.0.5 // indirect
)


M go.sum => go.sum +0 -3
@@ 14,8 14,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lrstanley/bubblezone v0.0.0-20220729154607-e408d1dc3890 h1:mAJcJhjnJiwT3w9q1whqbnvDfezUSR+ECVb+B1j3D64=
github.com/lrstanley/bubblezone v0.0.0-20220729154607-e408d1dc3890/go.mod h1:CxaUrg7Y6DmnquTpb1Rgxib+u+NcRxrDi8m/mR1poTM=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=


@@ 24,7 22,6 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 h1:kMlmsLSbjkikxQJ1IPwaM+7LJ9ltFu/fi8CRzvSnQmA=
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=

M pkg/tui/commands/add/add.go => pkg/tui/commands/add/add.go +26 -15
@@ 12,11 12,13 @@ import (
	"github.com/charmbracelet/bubbles/key"
	"github.com/charmbracelet/bubbles/textinput"
	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
	"github.com/spf13/cobra"

	"github.com/tgrosinger/ledger-tui/pkg/tui/currencyinput"
	"github.com/tgrosinger/ledger-tui/pkg/tui/dateinput"
	"github.com/tgrosinger/ledger-tui/pkg/tui/postingsinput"
	"github.com/tgrosinger/ledger-tui/pkg/tui/suggestions"
)

var AddCmd = &cobra.Command{


@@ 33,14 35,15 @@ func executeAddTUI(cmd *cobra.Command, args []string) {
		date:          dateinput.New(time.Now(), true),
		description:   textinput.New(),
		total:         currencyinput.New("$"),
		suggestionBox: suggestions.New(),
		help:          help.New(),
		keymap: keymap{
			nextField: key.NewBinding(
				key.WithKeys("tab"),
				key.WithHelp("tab", "Next Field")),
				key.WithHelp("tab", "Next")),
			prevField: key.NewBinding(
				key.WithKeys("shift+tab"),
				key.WithHelp("shift+tab", "Previous Field")),
				key.WithHelp("shift+tab", "Previous")),
			quit: key.NewBinding(
				key.WithKeys("esc", "ctrl+c"),
				key.WithHelp("esc", "Quit")),


@@ 49,8 52,9 @@ func executeAddTUI(cmd *cobra.Command, args []string) {

	addTUI.description.Placeholder = "Transaction Description"
	addTUI.description.Validate = descriptionValidator
	addTUI.description.Prompt = ""

	p := tea.NewProgram(addTUI)
	p := tea.NewProgram(addTUI, tea.WithAltScreen())
	if err := p.Start(); err != nil {
		fmt.Printf("Alas, there's been an error: %v", err)
		os.Exit(1)


@@ 91,8 95,14 @@ type AddTxTUI struct {
	description   textinput.Model
	total         currencyinput.Model

	suggestionBox suggestions.Model

	keymap keymap
	help   help.Model

	// halfFrame is a style which can fit two side by side, separated by a
	// simple border. Will be resized when the window resizes.
	halfFrame lipgloss.Style
}

func (m AddTxTUI) Init() tea.Cmd {


@@ 103,6 113,11 @@ func (m AddTxTUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	cmds := make([]tea.Cmd, 3)

	switch msg := msg.(type) {
	case tea.WindowSizeMsg:
		m.halfFrame = lipgloss.NewStyle().
			Width((msg.Width/2)-2).
			Height(msg.Height-4).
			Border(lipgloss.NormalBorder(), true)
	case dateinput.Msg:
		switch msg {
		case dateinput.NextInputMsg:


@@ 205,13 220,11 @@ func (m AddTxTUI) helpView() string {
}

func (m AddTxTUI) View() string {
	log.Println("Rendering LedgerTUI")

	output := strings.Builder{}
	output.WriteString("Tx Date: " + m.date.View())
	output.WriteString("Date: " + m.date.View())

	if m.furthestFocus >= description {
		output.WriteString("\nDescription: " + m.description.View())
		output.WriteString("\nDesc: " + m.description.View())
	}

	if m.furthestFocus >= total {


@@ 219,12 232,10 @@ func (m AddTxTUI) View() string {

	}

	// TODO: When accounts is focused, only show the account view.
	// The account view should have a text box at the top, and a list of
	// suggestions below that can be selected.
	// Maybe use a "next" button or something to make it less jarring.

	output.WriteString(m.helpView())

	return output.String()
	return lipgloss.JoinVertical(lipgloss.Left,
		lipgloss.JoinHorizontal(lipgloss.Top,
			m.halfFrame.Render(output.String()),
			m.halfFrame.Render(m.suggestionBox.View())),
		m.helpView(),
	)
}

M pkg/tui/currencyinput/currencyinput.go => pkg/tui/currencyinput/currencyinput.go +0 -2
@@ 2,7 2,6 @@ package currencyinput

import (
	"errors"
	"log"
	"strconv"
	"strings"



@@ 39,7 38,6 @@ func numberValidator(s string) error {
	}

	decimalPlaces := (len(s) - 1) - decimalIndex
	log.Println(decimalPlaces)
	if decimalPlaces > 2 {
		return errors.New("currency may only have two decimal places")
	}

A pkg/tui/suggestions/suggestions.go => pkg/tui/suggestions/suggestions.go +22 -0
@@ 0,0 1,22 @@
package suggestions

import tea "github.com/charmbracelet/bubbletea"

type Model struct {
}

func New() Model {
	return Model{}
}

func Init() tea.Cmd {
	return nil
}

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
	return m, nil
}

func (m Model) View() string {
	return "Suggestions"
}