summaryrefslogtreecommitdiff
path: root/pkg/prompt/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/prompt/main.go')
-rw-r--r--pkg/prompt/main.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/pkg/prompt/main.go b/pkg/prompt/main.go
index 6b4764a..ff51f0c 100644
--- a/pkg/prompt/main.go
+++ b/pkg/prompt/main.go
@@ -18,16 +18,22 @@
package prompt
-import "os"
+import (
+ "os"
+ "strings"
+
+ "github.com/majewsky/gofu/pkg/cli"
+)
//Exec executes the prettyprompt applet and returns an exit code (0 for
//success, >0 for error).
func Exec() int {
- var buf LineBuffer
- addLogin(&buf)
+ fields := []string{
+ getLoginField(),
+ }
+ line := strings.Join(fields, " ")
- os.Stdout.Write(buf.Bytes())
- os.Stdout.Write([]byte("\n"))
+ os.Stdout.Write([]byte(line + "\n"))
return 0
}
@@ -44,3 +50,18 @@ func handleError(err error) {
os.Stderr.Write([]byte("\x1B[1;31mPrompt error: " + err.Error() + "\x1B[0m\n"))
}
}
+
+func getPrintableLength(text string) int {
+ return len(cli.AnsiEscapeRx.ReplaceAllString(text, ""))
+}
+
+//withColor adds ANSI escape sequences to the string to display it with a
+//certain color. The color is given as the semicolon-separated list of
+//arguments to the ANSI escape sequence SGR, e.g. "1;41" for bold with red
+//background.
+func withColor(color, text string) string {
+ if color == "0" {
+ return text
+ }
+ return "\x1B[" + color + "m" + text + "\x1B[0m"
+}