Skip to content
Open
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
7 changes: 7 additions & 0 deletions cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import (
"github.com/hmans/beans/internal/tui"
)

var tuiExcludeArchived bool

var tuiCmd = &cobra.Command{
Use: "tui",
Short: "Open the interactive TUI",
Long: `Opens an interactive terminal user interface for browsing and managing beans.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Override config if flag was explicitly set
if cmd.Flags().Changed("exclude-archived") {
cfg.TUI.ExcludeArchived = tuiExcludeArchived
}
return tui.Run(core, cfg)
},
}

func init() {
tuiCmd.Flags().BoolVarP(&tuiExcludeArchived, "exclude-archived", "e", false, "Exclude beans with archive statuses (completed, scrapped)")
rootCmd.AddCommand(tuiCmd)
}
6 changes: 6 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ type PriorityConfig struct {
// Note: Statuses are no longer stored in config - they are hardcoded like types.
type Config struct {
Beans BeansConfig `yaml:"beans"`
TUI TUIConfig `yaml:"tui,omitempty"`

// configDir is the directory containing the config file (not serialized)
// Used to resolve relative paths
configDir string `yaml:"-"`
}

// TUIConfig defines settings for the TUI.
type TUIConfig struct {
ExcludeArchived bool `yaml:"exclude_archived,omitempty"`
}

// BeansConfig defines settings for bean creation.
type BeansConfig struct {
// Path is the path to the beans directory (relative to config file location)
Expand Down
16 changes: 16 additions & 0 deletions internal/graph/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func ApplyFilter(beans []*bean.Bean, filter *model.BeanFilter, core *beancore.Co
result = filterByNoBlockedBy(result)
}

// Archive filter
if filter.ExcludeArchived != nil && *filter.ExcludeArchived {
result = filterByNotArchived(result, core)
}

return result
}

Expand Down Expand Up @@ -331,3 +336,14 @@ func filterByNoBlockedBy(beans []*bean.Bean) []*bean.Bean {
}
return result
}

// filterByNotArchived filters beans that are not in the archive directory.
func filterByNotArchived(beans []*bean.Bean, core *beancore.Core) []*bean.Bean {
var result []*bean.Bean
for _, b := range beans {
if !core.IsArchived(b.ID) {
result = append(result, b)
}
}
return result
}
9 changes: 8 additions & 1 deletion internal/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,6 @@ input BeanFilter {
noBlocking: Boolean
"Exclude beans that have explicit blocked-by entries"
noBlockedBy: Boolean
"Exclude beans that are in the archive directory"
excludeArchived: Boolean
}
12 changes: 9 additions & 3 deletions internal/tui/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ func (m listModel) Init() tea.Cmd {
}

func (m listModel) loadBeans() tea.Msg {
// Build filter if tag filter is set
// Build filter based on active filters
var filter *model.BeanFilter
if m.tagFilter != "" {
filter = &model.BeanFilter{Tags: []string{m.tagFilter}}
if m.tagFilter != "" || m.config.TUI.ExcludeArchived {
filter = &model.BeanFilter{}
if m.tagFilter != "" {
filter.Tags = []string{m.tagFilter}
}
if m.config.TUI.ExcludeArchived {
filter.ExcludeArchived = &m.config.TUI.ExcludeArchived
}
}

// Query filtered beans
Expand Down