Skip to content

Commit

Permalink
fix: cursor on image view
Browse files Browse the repository at this point in the history
  • Loading branch information
somnek committed Jan 15, 2024
1 parent ef03fce commit d2b66e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
20 changes: 17 additions & 3 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

func getCurrentViewItemCount(m model) int {
var itemCount int
if m.page == pageContainer {
itemCount = len(m.containers)
} else {
itemCount = len(m.images)
}
return itemCount
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
Expand All @@ -32,7 +42,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// processes
m.processes = updatePendingProcesses(m)

logToFile(m.processes)
return m, doTick()

case tea.WindowSizeMsg:
Expand Down Expand Up @@ -82,14 +91,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case key.Matches(msg, m.keys.Up): // move cursor up
itemCount := getCurrentViewItemCount(m)
// increment cursor unless we're at the beginning of the list
if m.cursor > 0 {
m.cursor--
} else {
m.cursor = len(m.containers) - 1
m.cursor = itemCount - 1
}

case key.Matches(msg, m.keys.Down): // move cursor down
if m.cursor < len(m.containers)-1 {
itemCount := getCurrentViewItemCount(m)

// decrement cursor unless we're at the end of the list
if m.cursor < itemCount-1 {
m.cursor++
} else {
m.cursor = 0
Expand Down
31 changes: 0 additions & 31 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func buildImageDescShort(id string) string {
desc += fmt.Sprintf("Size : %s\n", convertSizeToHumanRedable(image.Size))
desc += fmt.Sprintf("Cmd : %s\n", strings.Join(image.Config.Cmd, " "))
desc += fmt.Sprintf("Volumes : %v\n", formatImageVolumes(image.Config.Volumes))
// desc += fmt.Sprintf("Volumes : %v\n", image.Config.Volumes)
return desc
}

Expand All @@ -124,36 +123,6 @@ func buildImageView(m model) (string, string) {
}
padBodyHeight(&bodyL, len(m.images)+2)
return bodyLStyle.Render(bodyL), bodyRStyle.Render(bodyR)

// var s string
// // truncate
// shouldTruncate := false
// imageList := m.images
// if len(m.images) > 10 {
// shouldTruncate = true
// imageList = m.images[:10]
// }

// for i, choice := range imageList {
// cursor := " " // default cursor
// if m.cursor == i {
// cursor = "👉"
// }
// checked := " "
// if _, ok := m.selected[i]; ok {
// checked = "x"
// }
// name := choice.name
// if len(name) > 25 {
// name = name[:25] + "..."
// }
// s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, name)
// }
// // add more images message
// if shouldTruncate {
// s += fmt.Sprintf("\n %d more images... ↓\n", len(m.images)-10)
// }
// return bodyLStyle.Render(s)
}

func buildLogView(m model) string {
Expand Down

0 comments on commit d2b66e1

Please sign in to comment.