shell/prompt.go
2023-03-19 13:08:11 +01:00

88 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"time"
"github.com/fatih/color"
)
var prompts = []func() *ColorString{ps1, ps2, ps3, ps4, ps5}
func prompt() *ColorString {
// width, _, err := terminal.GetSize(int(os.Stdin.Fd()))
// if err != nil {
// return ">"
// }
return ps1()
// for _, pfunc := range prompts {
// prompt := pfunc()
// if prompt.Len()+inputBuffer.Len() < width {
// return prompt.String()
// }
// }
}
func ps1() *ColorString {
p := new(ColorString)
p.Append(time.Now().Format("15:04:05"), color.FgRed)
p.Append(" • ")
p.Append(debugInfo, color.FgMagenta)
if len(debugInfo) > 0 {
p.Append(" • ")
}
p.Append(env("USER"), color.FgGreen)
p.Append(" • ")
p.Append(host(), color.FgYellow)
p.Append(" • ")
p.Append(wd(), color.FgBlue)
p.Append(" ", color.FgRed)
p.Append("", color.FgYellow)
p.Append(" ", color.FgGreen)
return p
}
func ps2() *ColorString {
p := new(ColorString)
p.Append(env("USER"), color.FgGreen)
p.Append(" • ")
p.Append(host(), color.FgYellow)
p.Append(" • ")
p.Append(wd(), color.FgBlue)
p.Append(" ", color.FgRed)
p.Append("", color.FgYellow)
p.Append(" ", color.FgGreen)
return p
}
func ps3() *ColorString {
p := new(ColorString)
p.Append(env("USER"), color.FgGreen)
p.Append(" • ")
p.Append(wd(), color.FgBlue)
p.Append(" ", color.FgRed)
p.Append("", color.FgYellow)
p.Append(" ", color.FgGreen)
return p
}
func ps4() *ColorString {
p := new(ColorString)
p.Append(wd(), color.FgBlue)
p.Append(" ", color.FgRed)
p.Append("", color.FgYellow)
p.Append(" ", color.FgGreen)
return p
}
func ps5() *ColorString {
p := new(ColorString)
p.Append(" ", color.FgRed)
p.Append("", color.FgYellow)
p.Append(" ", color.FgGreen)
return p
}