Compare commits
No commits in common. "4391530fad6c4cd3bd4964c6ceeb9abe49409fa0" and "6a10a08d9e88b27137d53bbe8e722aecfd59e6cc" have entirely different histories.
4391530fad
...
6a10a08d9e
1 changed files with 1 additions and 36 deletions
|
@ -1,4 +1,5 @@
|
||||||
// warning this code is messy and terrible
|
// warning this code is messy and terrible
|
||||||
|
// TODO read list data from file
|
||||||
package launcher
|
package launcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -14,8 +15,6 @@ import (
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ===============
|
|
||||||
// lipgloss styles
|
|
||||||
var appStyle = lipgloss.NewStyle().Margin(1, 2)
|
var appStyle = lipgloss.NewStyle().Margin(1, 2)
|
||||||
|
|
||||||
var titleStyle = lipgloss.NewStyle().
|
var titleStyle = lipgloss.NewStyle().
|
||||||
|
@ -28,8 +27,6 @@ var categoryTitleStyle = lipgloss.NewStyle().
|
||||||
Background(lipgloss.Color("4")).
|
Background(lipgloss.Color("4")).
|
||||||
Padding(0, 1)
|
Padding(0, 1)
|
||||||
|
|
||||||
// ============
|
|
||||||
// data structs
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
title string
|
title string
|
||||||
desc string
|
desc string
|
||||||
|
@ -50,8 +47,6 @@ func (p Program) Title() string { return p.title }
|
||||||
func (p Program) Description() string { return p.desc }
|
func (p Program) Description() string { return p.desc }
|
||||||
func (p Program) FilterValue() string { return p.title }
|
func (p Program) FilterValue() string { return p.title }
|
||||||
|
|
||||||
// ======================
|
|
||||||
// bubbletea model struct
|
|
||||||
type model struct {
|
type model struct {
|
||||||
categoriesList list.Model
|
categoriesList list.Model
|
||||||
categoriesKeys *categoriesKeyMap
|
categoriesKeys *categoriesKeyMap
|
||||||
|
@ -61,8 +56,6 @@ type model struct {
|
||||||
shouldExec string
|
shouldExec string
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============
|
|
||||||
// list keybinds
|
|
||||||
type categoriesKeyMap struct {
|
type categoriesKeyMap struct {
|
||||||
selectKey key.Binding
|
selectKey key.Binding
|
||||||
}
|
}
|
||||||
|
@ -94,8 +87,6 @@ func newProgramsKeyMap() *programsKeyMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================
|
|
||||||
// bubbletea model methods
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -150,13 +141,7 @@ func (m model) View() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============
|
|
||||||
// run launcher
|
|
||||||
func Run(cmd *cobra.Command, args []string) error {
|
func Run(cmd *cobra.Command, args []string) error {
|
||||||
// =========
|
|
||||||
// init data
|
|
||||||
|
|
||||||
// TODO read this from a file instead
|
|
||||||
categories := []list.Item{
|
categories := []list.Item{
|
||||||
Category{
|
Category{
|
||||||
title: "editors",
|
title: "editors",
|
||||||
|
@ -228,15 +213,11 @@ func Run(cmd *cobra.Command, args []string) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================
|
|
||||||
// create delegates and keybinds
|
|
||||||
categoryDelegate := list.NewDefaultDelegate()
|
categoryDelegate := list.NewDefaultDelegate()
|
||||||
categoryKeys := newCategoriesKeyMap()
|
categoryKeys := newCategoriesKeyMap()
|
||||||
programDelegate := list.NewDefaultDelegate()
|
programDelegate := list.NewDefaultDelegate()
|
||||||
programKeys := newProgramsKeyMap()
|
programKeys := newProgramsKeyMap()
|
||||||
|
|
||||||
// ===================
|
|
||||||
// set delegate styles
|
|
||||||
categoryDelegate.Styles.SelectedTitle = categoryDelegate.Styles.SelectedTitle.
|
categoryDelegate.Styles.SelectedTitle = categoryDelegate.Styles.SelectedTitle.
|
||||||
Foreground(lipgloss.Color("4")).BorderLeftForeground(lipgloss.Color("4"))
|
Foreground(lipgloss.Color("4")).BorderLeftForeground(lipgloss.Color("4"))
|
||||||
categoryDelegate.Styles.SelectedDesc = categoryDelegate.Styles.SelectedTitle
|
categoryDelegate.Styles.SelectedDesc = categoryDelegate.Styles.SelectedTitle
|
||||||
|
@ -245,8 +226,6 @@ func Run(cmd *cobra.Command, args []string) error {
|
||||||
Foreground(lipgloss.Color("1")).BorderLeftForeground(lipgloss.Color("1"))
|
Foreground(lipgloss.Color("1")).BorderLeftForeground(lipgloss.Color("1"))
|
||||||
programDelegate.Styles.SelectedDesc = programDelegate.Styles.SelectedTitle
|
programDelegate.Styles.SelectedDesc = programDelegate.Styles.SelectedTitle
|
||||||
|
|
||||||
// ====================
|
|
||||||
// define initial model
|
|
||||||
initialModel := model{
|
initialModel := model{
|
||||||
categoriesList: list.New(categories, categoryDelegate, 0, 0),
|
categoriesList: list.New(categories, categoryDelegate, 0, 0),
|
||||||
categoriesKeys: categoryKeys,
|
categoriesKeys: categoryKeys,
|
||||||
|
@ -255,8 +234,6 @@ func Run(cmd *cobra.Command, args []string) error {
|
||||||
selectedCategory: false,
|
selectedCategory: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================================
|
|
||||||
// set initial model styles and keys
|
|
||||||
initialModel.categoriesList.Title = "the cherry.town program directory"
|
initialModel.categoriesList.Title = "the cherry.town program directory"
|
||||||
initialModel.categoriesList.Styles.Title = titleStyle
|
initialModel.categoriesList.Styles.Title = titleStyle
|
||||||
initialModel.categoriesList.AdditionalShortHelpKeys = func() []key.Binding {
|
initialModel.categoriesList.AdditionalShortHelpKeys = func() []key.Binding {
|
||||||
|
@ -284,8 +261,6 @@ func Run(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================
|
|
||||||
// run bubbletea program
|
|
||||||
p := tea.NewProgram(initialModel)
|
p := tea.NewProgram(initialModel)
|
||||||
finalModel, err := p.Run()
|
finalModel, err := p.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -293,16 +268,6 @@ func Run(cmd *cobra.Command, args []string) error {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============
|
|
||||||
// clear screen
|
|
||||||
|
|
||||||
// TODO this feels hacky and should probably be replaced
|
|
||||||
execCmd := exec.Command("clear")
|
|
||||||
execCmd.Stdout = os.Stdout
|
|
||||||
execCmd.Run()
|
|
||||||
|
|
||||||
// ====================================
|
|
||||||
// execute chosen command if one is set
|
|
||||||
if finalModel, ok := finalModel.(model); ok && finalModel.shouldExec != "" {
|
if finalModel, ok := finalModel.(model); ok && finalModel.shouldExec != "" {
|
||||||
execCmd := exec.Command(finalModel.shouldExec)
|
execCmd := exec.Command(finalModel.shouldExec)
|
||||||
execCmd.Stdin = os.Stdin
|
execCmd.Stdin = os.Stdin
|
||||||
|
|
Loading…
Add table
Reference in a new issue