summaryrefslogtreecommitdiff
path: root/menu/banner.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
committerewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
commit45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch)
tree852ebc3a0112c94dc9726d0b27ab057bf6383660 /menu/banner.go
i have to commit at some point!
Diffstat (limited to 'menu/banner.go')
-rw-r--r--menu/banner.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/menu/banner.go b/menu/banner.go
new file mode 100644
index 0000000..c9d8e56
--- /dev/null
+++ b/menu/banner.go
@@ -0,0 +1,92 @@
+package menu
+
+import (
+ "github.com/charmbracelet/lipgloss"
+ "os/exec"
+ "pik/menu/style"
+ "pik/model"
+ "pik/paths"
+ "strings"
+)
+
+var (
+ BannerStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ BannerSourceLabelStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().Faint(true).MarginRight(1)
+ })
+ BannerSubItemStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().Faint(true).MarginRight(1)
+ })
+ BannerSubStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ BannerSelfStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().MarginRight(1)
+ })
+ BannerPromptStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ BannerArgsStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().MarginLeft(1)
+ })
+ BannerArgStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ BannerTerminatorColor = lipgloss.Color("1")
+ BannerTerminatorStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().Faint(true).Foreground(BannerTerminatorColor)
+ })
+)
+
+func Banner(source *model.Source, target model.Target, args ...string) string {
+ var parts, argParts []string
+ parts = append(parts, BannerPromptStyle.Render("> "))
+ parts = append(parts, BannerSelfStyle.Render("pik"))
+ parts = append(parts, BannerSourceLabelStyle.Render(source.Label()))
+ if sub := target.Sub(); sub != nil {
+ for i, s := range sub {
+ sub[i] = BannerSubItemStyle.Render(s)
+ }
+ parts = append(parts, BannerSubStyle.Render(sub...))
+ }
+ parts = append(parts, target.ShortestId())
+ if args != nil {
+ needsTerminator := false
+ for _, a := range args {
+ if strings.HasPrefix(a, "-") {
+ needsTerminator = true
+ }
+ argParts = append(argParts, BannerArgStyle.Render(a))
+ }
+
+ if needsTerminator {
+ argParts = append([]string{BannerTerminatorStyle.Render("--")}, argParts...)
+ }
+
+ parts = append(parts, BannerArgsStyle.Render(argParts...))
+ }
+ result := BannerStyle.Render(lipgloss.JoinHorizontal(lipgloss.Left, parts...))
+ return result
+}
+
+var (
+ CmdStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle().Faint(true)
+ })
+ CmdDirStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ CmdArgStyle = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+)
+
+func InlineCmd(cmd *exec.Cmd) string {
+ var args []string
+ for _, a := range cmd.Args {
+ args = append(args, paths.ReplaceHome(a))
+ }
+ return CmdStyle.Render(" # "+CmdDirStyle.Render(paths.ReplaceHome(cmd.Dir)+":"), CmdArgStyle.Render(args...))
+}