Skip to content

Commit

Permalink
keys & logview
Browse files Browse the repository at this point in the history
  • Loading branch information
somnek committed Jan 14, 2024
1 parent aa56f1d commit a137fa8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var keys = keyMap{
key.WithHelp("esc", "clear selection"),
),
SelectAll: key.NewBinding(
key.WithKeys("shift+a"),
key.WithKeys("A"),
key.WithHelp("shift+a", "select all"),
),
Tab: key.NewBinding(
Expand All @@ -96,15 +96,15 @@ var keys = keyMap{
key.WithHelp("space/enter", "toggle selection"),
),
Remove: key.NewBinding(
key.WithKeys("x"),
key.WithHelp("x", "remove container"),
key.WithKeys("X"),
key.WithHelp("shift+x", "remove container"),
),
Restart: key.NewBinding(
key.WithKeys("r"),
key.WithHelp("r", "restart container"),
),
Kill: key.NewBinding(
key.WithKeys("shift+k"),
key.WithKeys("K"),
key.WithHelp("shift+k", "kill container"),
),
Stop: key.NewBinding(
Expand All @@ -120,7 +120,7 @@ var keys = keyMap{
key.WithHelp("p", "pause container"),
),
Unpause: key.NewBinding(
key.WithKeys("shift+p"),
key.WithKeys("P"),
key.WithHelp("shift+p", "unpause container"),
),
}
8 changes: 6 additions & 2 deletions style.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
lastPage = 4
minHeightPerView = 8 // 6 item
maxHeightPerView = 12 // 10 item
fixedWidth = 92
fixedWidth = 88 // 92
fixedBodyLWidth = 36 // exclude padding
fixedBodyRWidth = 44 // exclude padding
)
Expand Down Expand Up @@ -73,6 +73,10 @@ var (
Foreground(black).
Background(grey)

styleCheck = lipgloss.NewStyle().
checkStyle = lipgloss.NewStyle().
Foreground(hotGreen)

itemCountStyle = lipgloss.NewStyle().
Foreground(frenchBlue).
Bold(true)
)
12 changes: 7 additions & 5 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func buildImageView(m model) string {
func buildLogView(m model) string {
var s string
s += m.logs
logStyle.MarginLeft((fixedWidth - len(s)) / 2)
logStyle.MarginLeft((fixedWidth - lipgloss.Width(s)) / 2)
logStyle.AlignHorizontal(lipgloss.Center)
return logStyle.Render(s)
}

Expand All @@ -115,7 +116,7 @@ func buildContainerView(m model) (string, string) {
name := choice.name
name = runewidth.Truncate(name, 25, "...")
if _, ok := m.selected[i]; ok {
check = styleCheck.Render("✔")
check = checkStyle.Render("✔")
}
bodyL += fmt.Sprintf("%s %s %s %s", cursor, check, state, name) + "\n"
}
Expand All @@ -140,8 +141,9 @@ func (m model) View() string {

// title
// title := strings.Repeat(" ", 36) + "🐳 Docker"
// titleStyle.MarginLeft((m.width - (fixedWidth + lipgloss.Width(title)/2)) / 2)
// title = titleStyle.Render(title)
title := "🐳 Docker"
titleStyle.MarginLeft((m.width / 2) - (lipgloss.Width(title) / 2))
title = titleStyle.Render(title)

// join left + right component
body = lipgloss.JoinHorizontal(lipgloss.Left, bodyL, bodyR)
Expand All @@ -154,7 +156,7 @@ func (m model) View() string {
final += lipgloss.JoinVertical(lipgloss.Top, body, bottom)
appStyle.MarginLeft((m.width - fixedWidth) / 2)

return appStyle.Render(final) + "\n"
return title + "\n" + appStyle.Render(final) + "\n"
}

func padBodyHeight(s *string, itemCount int) {
Expand Down

0 comments on commit a137fa8

Please sign in to comment.