Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sammcj committed May 31, 2024
1 parent 550c4d7 commit ed7d567
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
4 changes: 0 additions & 4 deletions TODO.md

This file was deleted.

9 changes: 5 additions & 4 deletions app_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"gollama/logging"
"sort"

"github.com/charmbracelet/lipgloss"
"github.com/ollama/ollama/api"
Expand Down Expand Up @@ -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
})
}
}
1 change: 1 addition & 0 deletions item_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type AppModel struct {
ollamaModelsDir string
lmStudioModelsDir string
noCleanup bool
cfg *config.Config
}

func main() {
Expand Down Expand Up @@ -122,6 +123,7 @@ func main() {
ollamaModelsDir: *ollamaDirFlag,
lmStudioModelsDir: *lmStudioDirFlag,
noCleanup: *noCleanupFlag,
cfg: &cfg,
}

if *ollamaDirFlag == "" {
Expand Down Expand Up @@ -169,6 +171,7 @@ func main() {
}

// Save the updated configuration
cfg.SortOrder = keys.GetSortOrder()
if err := config.SaveConfig(cfg); err != nil {
panic(err)
}
Expand Down
22 changes: 22 additions & 0 deletions styles.go
Original file line number Diff line number Diff line change
@@ -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)
)

0 comments on commit ed7d567

Please sign in to comment.