From e8b31652a0a0fa1767d5e5d86fa9f7016057262c Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 11 Jul 2017 15:55:34 +0200 Subject: yagni --- pkg/prompt/main.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'pkg/prompt/main.go') 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" +} -- cgit v1.3.1