Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ test:
demo:
vhs demo.tape

demov3:
vhs home_v3.tape
vhs reports_v3.tape

release:
GITHUB_TOKEN=$(GITHUB_TOKEN) goreleaser release --clean

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ To try V3, you can update to the latest version and run

Please note, **v3 does not use a config file yet**. So if you are using a config file with v2 then it won't be used with v3.

## Demo

![demo](assets/demo_v3.gif)

### Screenshots

<details>
<summary>Home</summary>

![home](assets/screenshot_home_v3.png)

</details>

<details>
<summary>Reports</summary>

![reports](assets/screenshot_reports_v3.png)

</details>

## V3 roadmap
- [x] Accounts table
- [x] Balance table
Expand Down
Binary file added assets/demo_v3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot_home_v3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshot_reports_v3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions config_v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"journalFile": "data/hledger.journal"
}
40 changes: 40 additions & 0 deletions demo_v3.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Output assets/home_v3.gif
Set Shell zsh
Set Width 1920
Set Height 1200
Set Framerate 30
Set FontSize 16

Type "go run . -v3 -cfg config_v3.json"
Enter
Sleep 2s
Type "jj"
Sleep 1s
Type "2jj"
Sleep 1s
Type "j"
Sleep 1s
Type "jj"
Sleep 1s

Type "3j"
Sleep 1s
Type "1"
Sleep 1s
Type "kk"
Sleep 1s
Type "2j"
Sleep 1s
Enter
Sleep 1s
Type "j3"
Sleep 1s

Sleep 1s
Tab
Sleep 3s
Type "2"
Sleep 1s

Type "qq"

10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ func main() {
flag.Parse()

if runV3 {
v3.Start(isDebug)
var cfg v3.Config
if configFile != "" {
var err error
cfg, err = v3.NewConfig(configFile)
if err != nil {
log.Fatal(err)
}
}
v3.Start(cfg, isDebug)
} else {
cfg := ui.DefaultConfig
if configFile != "" {
Expand Down
29 changes: 29 additions & 0 deletions ui/v2/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ui

import (
"encoding/json"
"io"
"os"
)

type Config struct {
JournalFile string `json:"journalFile"`
}

func NewConfig(configFile string) (Config, error) {
file, err := os.Open(configFile)
if err != nil {
return Config{}, err
}

return parseJSON(file)
}

func parseJSON(file io.Reader) (Config, error) {
var cfg Config
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
return cfg, err
}

return cfg, nil
}
10 changes: 10 additions & 0 deletions ui/v2/hledger/hledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ import (
)

type HledgerData struct {
journalFile string
}

func NewHledgerData(journalFile string) HledgerData {
return HledgerData{
journalFile: journalFile,
}
}

func (hd HledgerData) runCommand(args []string) (io.Reader, error) {
log.Printf("data: command: %v", args)
if hd.journalFile != "" {
args = append(args, "-f", hd.journalFile)
}
cmd := exec.Command("hledger", args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions ui/v2/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/charmbracelet/lipgloss"
)

func Start(isDebug bool) {
func Start(config Config, isDebug bool) {
if isDebug {
f, err := tea.LogToFile("puffin.log", "debug")
if err != nil {
Expand All @@ -26,7 +26,7 @@ func Start(isDebug bool) {
// log.Printf("init puffin %s", Version)
// var p *tea.Program
cmdRunner := newCmdRunner()
p := tea.NewProgram(newUI(cmdRunner))
p := tea.NewProgram(newUI(cmdRunner, config))
cmdRunner.p = p
cmdRunner.listen()
if _, err := p.Run(); err != nil {
Expand Down Expand Up @@ -56,15 +56,16 @@ type ui struct {
captureKeysMode bool
}

func newUI(cr *cmdRunner) *ui {
func newUI(cr *cmdRunner, config Config) *ui {
ledgerData := hledger.NewHledgerData(config.JournalFile)
return &ui{
tabTitles: []string{
"Home",
"Reports",
},
tabContent: []tea.Model{
newHome(hledger.HledgerData{}, cr),
newReports(hledger.HledgerData{}, cr),
newHome(ledgerData, cr),
newReports(ledgerData, cr),
},
captureKeysMode: true,
cmdRunner: cr,
Expand Down
Loading