-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UI element for periodic arguments (#25)
- Loading branch information
1 parent
72f188f
commit 1790091
Showing
5 changed files
with
99 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ui | ||
|
||
import ( | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/siddhantac/hledger" | ||
) | ||
|
||
type periodType string | ||
|
||
const ( | ||
monthly periodType = "monthly" | ||
quarter periodType = "quarterly" | ||
yearly periodType = "yearly" | ||
) | ||
|
||
type Period struct { | ||
periodType hledger.PeriodType | ||
} | ||
|
||
func newPeriod() *Period { | ||
return &Period{periodType: hledger.PeriodYearly} | ||
} | ||
|
||
func (p *Period) Init() tea.Cmd { return nil } | ||
|
||
func (p *Period) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.String() { | ||
case "m": | ||
p.periodType = hledger.PeriodMonthly | ||
case "u": | ||
p.periodType = hledger.PeriodQuarterly | ||
case "y": | ||
p.periodType = hledger.PeriodYearly | ||
case "q", "esc": | ||
return p, tea.Quit | ||
} | ||
} | ||
return p, nil | ||
} | ||
|
||
func (p *Period) View() string { | ||
sectionTitleStyle := lipgloss.NewStyle(). | ||
MarginTop(1). | ||
MarginRight(1). | ||
PaddingRight(1). | ||
PaddingLeft(1). | ||
Foreground(theme.Accent) | ||
sectionTitle := sectionTitleStyle.Render("PERIOD") | ||
|
||
inactiveTextStyle := lipgloss.NewStyle(). | ||
Foreground(theme.PrimaryForeground). | ||
MarginRight(2) | ||
textStyle := lipgloss.NewStyle(). | ||
MarginRight(2) | ||
|
||
var monthView, quarterView, yearView string | ||
switch p.periodType { | ||
case hledger.PeriodMonthly: | ||
monthView = textStyle.Render("monthly") | ||
quarterView = inactiveTextStyle.Render("quarterly") | ||
yearView = inactiveTextStyle.Render("yearly") | ||
case hledger.PeriodQuarterly: | ||
monthView = inactiveTextStyle.Render("monthly") | ||
quarterView = textStyle.Render("quarterly") | ||
yearView = inactiveTextStyle.Render("yearly") | ||
case hledger.PeriodYearly: | ||
monthView = inactiveTextStyle.Render("monthly") | ||
quarterView = inactiveTextStyle.Render("quarterly") | ||
yearView = textStyle.Render("yearly") | ||
} | ||
|
||
return lipgloss.JoinVertical( | ||
lipgloss.Right, | ||
sectionTitle, | ||
monthView, | ||
quarterView, | ||
yearView, | ||
) | ||
} |