diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-18 21:10:40 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-18 21:10:40 +0300 |
| commit | 84b404e392c94174d1c5ae4feb8afc4f5d334346 (patch) | |
| tree | 19237b127ef441e820dfd98bb4d0725736614093 /internal | |
| parent | 170a30c7cce4dbe78a20d6379998dcfc41a5c524 (diff) | |
added prompt colors
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/platforms/linkedin/linkedin.go | 2 | ||||
| -rw-r--r-- | internal/platforms/mastodon/mastodon.go | 2 | ||||
| -rw-r--r-- | internal/prompt/prompt.go | 12 |
3 files changed, 13 insertions, 3 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go index 0f5673e..4be231c 100644 --- a/internal/platforms/linkedin/linkedin.go +++ b/internal/platforms/linkedin/linkedin.go @@ -64,7 +64,7 @@ func callLinkedInAPI(ctx context.Context, personID, accessToken, message string) if err != nil { return fmt.Errorf("Error encoding JSON:%w", err) } - if !prompt.Yes(fmt.Sprintf("%s\nDo you want to post this message to LinkedIn?", string(payload))) { + if !prompt.YesWithContent("Do you want to post this message to LinkedIn?", message) { return prompt.ErrAborted } diff --git a/internal/platforms/mastodon/mastodon.go b/internal/platforms/mastodon/mastodon.go index c5d5c35..2cb280f 100644 --- a/internal/platforms/mastodon/mastodon.go +++ b/internal/platforms/mastodon/mastodon.go @@ -27,7 +27,7 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, ent entry.Entry) log.Println("Not posting", ent, "to Mastodon as dry-run enabled") return nil } - if !prompt.Yes(fmt.Sprintf("%s\nDo you want to post this message to Mastodon?", string(payloadBytes))) { + if !prompt.YesWithContent("Do you want to post this message to Mastodon?", content) { return prompt.ErrAborted } diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index 0afe98e..9feff70 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -6,15 +6,25 @@ import ( "fmt" "os" "strings" + + "github.com/fatih/color" ) var ErrAborted = errors.New("aborted") +var contentSprintf = color.New(color.FgCyan, color.BgBlue, color.Bold).SprintFunc() +var dangerSprintf = color.New(color.FgWhite, color.BgRed, color.Bold).SprintFunc() + +func YesWithContent(question, content string) bool { + fmt.Print(contentSprintf(content)) + fmt.Print("\n") + return Yes(question) +} func Yes(question string) bool { reader := bufio.NewReader(os.Stdin) for { - fmt.Print(question, " (y/n): ") + fmt.Printf("%s ", dangerSprintf(fmt.Sprintf("%s (y/n):", question))) input, err := reader.ReadString('\n') if err != nil { fmt.Println("Error reading input:", err) |
