~whereswaldon/rosebud

5b78fa3053a96be3a796fa38d429927a33b9a06c — Chris Waldon 1 year, 4 days ago bc2c40b
cmd/rosebud: log submitted transaction

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 27 insertions(+), 0 deletions(-)

M cmd/rosebud/main.go
M cmd/rosebud/main.go => cmd/rosebud/main.go +27 -0
@@ 1,6 1,7 @@
package main

import (
	"bytes"
	"fmt"
	"image"
	"io"


@@ 334,6 335,30 @@ func (u *UI) layoutAccountTreeNode(gtx C, at *AccountTreeNode) D {
	return d.DetailInset().Layout(gtx, theme.Account(u.Theme.Th, balance).Layout)
}

func toTxBytes(tx ledger.Transaction) []byte {
	var b bytes.Buffer
	b.WriteString("\n\n")
	b.WriteString(tx.Date.Format("2006-01-02"))
	b.WriteString(" ")
	b.WriteString(tx.Payee)
	b.WriteString("\n")
	for i, change := range tx.AccountChanges {
		if i < len(tx.Comments) {
			b.WriteString("\t; ")
			b.WriteString(tx.Comments[i])
			b.WriteString("\n")
		}
		b.WriteString("\t")
		b.WriteString(change.Name)
		b.WriteString("  ")
		b.WriteString(change.Balance.StringFixedBank())
		b.WriteString(" ; ")
		b.WriteString(change.Comment)
		b.WriteString("\n")
	}
	return b.Bytes()
}

func (u *UI) layoutTransactions(gtx C) D {
	u.TxList.Axis = layout.Vertical
	list := material.List(u.Theme.Th, &u.TxList)


@@ 344,6 369,8 @@ func (u *UI) layoutTransactions(gtx C) D {
				case appwidget.SuggestionRequestEvent[string]:
					suggestions := fuzzy.FindFold(e.Text, maps.Keys(u.AccountRegistry.elements))
					u.TxEditor.SetAccountSuggestions(suggestions)
				case appwidget.TransactionSubmittedEvent:
					log.Println(string(toTxBytes(e.Value)))
				}
			}
			return layout.UniformInset(4).Layout(gtx, apptheme.TxForm(u.Theme, &u.TxEditor).Layout)