diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 24ac60f..0000000 --- a/TODO.md +++ /dev/null @@ -1,4 +0,0 @@ -# TODO - -- Fix selections -- Add column borders diff --git a/app_model.go b/app_model.go index 92c75f1..77793b3 100644 --- a/app_model.go +++ b/app_model.go @@ -18,6 +18,7 @@ func (m *AppModel) Init() tea.Cmd { func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: + logging.DebugLogger.Printf("AppModel received key: %s\n", msg.String()) // Add this line switch { case key.Matches(msg, m.keys.Space): if item, ok := m.list.SelectedItem().(Model); ok { @@ -63,19 +64,19 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m.models[i].Name < m.models[j].Name }) m.refreshList() - m.keys.SortOrder = "name" // Update sort order + m.keys.SortOrder = "name" case key.Matches(msg, m.keys.SortBySize): sort.Slice(m.models, func(i, j int) bool { return m.models[i].Size > m.models[j].Size }) m.refreshList() - m.keys.SortOrder = "size" // Update sort order + m.keys.SortOrder = "size" case key.Matches(msg, m.keys.SortByModified): sort.Slice(m.models, func(i, j int) bool { return m.models[i].Modified.After(m.models[j].Modified) }) m.refreshList() - m.keys.SortOrder = "modified" // Update sort order + m.keys.SortOrder = "modified" case key.Matches(msg, m.keys.SortByQuant): sort.Slice(m.models, func(i, j int) bool { return m.models[i].QuantizationLevel < m.models[j].QuantizationLevel @@ -86,7 +87,7 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m.models[i].Family < m.models[j].Family }) m.refreshList() - m.keys.SortOrder = "family" // Update sort order + m.keys.SortOrder = "family" case key.Matches(msg, m.keys.RunModel): if item, ok := m.list.SelectedItem().(Model); ok { runModel(item.Name) diff --git a/config/config.go b/config/config.go index cfda210..1593e29 100644 --- a/config/config.go +++ b/config/config.go @@ -28,11 +28,6 @@ var defaultConfig = Config{ SortOrder: "modified", // Default sort order } -type ConfigOption struct { - Key string - Value string -} - func LoadConfig() (Config, error) { configPath := getConfigPath() fmt.Println("Loading config from:", configPath) // Debug print @@ -78,10 +73,12 @@ func SaveConfig(config Config) error { if err != nil { return fmt.Errorf("failed to create config file: %w", err) } - defer file.Close() - if err := json.NewEncoder(file).Encode(config); err != nil { + encoder := json.NewEncoder(file) + encoder.SetIndent("", " ") // Set indentation for better readability + + if err := encoder.Encode(config); err != nil { return fmt.Errorf("failed to encode config to file: %w", err) } return nil diff --git a/helpers.go b/helpers.go index e10e7eb..e4021ff 100644 --- a/helpers.go +++ b/helpers.go @@ -2,6 +2,7 @@ package main import ( "gollama/logging" + "sort" "github.com/charmbracelet/lipgloss" "github.com/ollama/ollama/api" @@ -110,3 +111,24 @@ func wrapText(text string, width int) string { wrapped += text return wrapped } + +func sortModels(models *[]Model, order string) { + switch order { + case "name": + sort.Slice(*models, func(i, j int) bool { + return (*models)[i].Name < (*models)[j].Name + }) + case "size": + sort.Slice(*models, func(i, j int) bool { + return (*models)[i].Size > (*models)[j].Size + }) + case "modified": + sort.Slice(*models, func(i, j int) bool { + return (*models)[i].Modified.After((*models)[j].Modified) + }) + case "family": + sort.Slice(*models, func(i, j int) bool { + return (*models)[i].Family < (*models)[j].Family + }) + } +} diff --git a/item_delegate.go b/item_delegate.go index 41690ae..638355e 100644 --- a/item_delegate.go +++ b/item_delegate.go @@ -25,6 +25,7 @@ func (d itemDelegate) Spacing() int { return 0 } func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { switch msg := msg.(type) { case tea.KeyMsg: + logging.DebugLogger.Printf("itemDelegate received key: %s\n", msg.String()) // Add this line switch msg.String() { case " ": // space key pressed i, ok := m.SelectedItem().(Model) diff --git a/keymap.go b/keymap.go index ccfcb69..8a6d1d1 100644 --- a/keymap.go +++ b/keymap.go @@ -20,7 +20,7 @@ type KeyMap struct { func NewKeyMap() *KeyMap { return &KeyMap{ - Space: key.NewBinding(key.WithKeys(" "), key.WithHelp("space", "toggle selection")), + Space: key.NewBinding(key.WithKeys("space"), key.WithHelp("space", "toggle selection")), Delete: key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "delete selected models")), SortByName: key.NewBinding(key.WithKeys("n"), key.WithHelp("n", "sort by name")), SortBySize: key.NewBinding(key.WithKeys("s"), key.WithHelp("s", "sort by size")), diff --git a/main.go b/main.go index 3525ff8..05bc3c1 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ type AppModel struct { ollamaModelsDir string lmStudioModelsDir string noCleanup bool + cfg *config.Config } func main() { @@ -122,6 +123,7 @@ func main() { ollamaModelsDir: *ollamaDirFlag, lmStudioModelsDir: *lmStudioDirFlag, noCleanup: *noCleanupFlag, + cfg: &cfg, } if *ollamaDirFlag == "" { @@ -169,6 +171,7 @@ func main() { } // Save the updated configuration + cfg.SortOrder = keys.GetSortOrder() if err := config.SaveConfig(cfg); err != nil { panic(err) } diff --git a/styles.go b/styles.go new file mode 100644 index 0000000..cec6999 --- /dev/null +++ b/styles.go @@ -0,0 +1,22 @@ +package main + +import "github.com/charmbracelet/lipgloss" + +var ( + headerStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#FF00FF")). + Background(lipgloss.Color("#000000")). + Bold(true). + Italic(true). + Padding(0, 1) + + rowStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#FFFFFF")). + Background(lipgloss.Color("#1A1A1A")). + Padding(0, 1) + + selectedRowStyle = rowStyle.Copy(). + Foreground(lipgloss.Color("#000000")). + Background(lipgloss.Color("#FF00FF")). + Bold(true) +)