Merge pull request #1 from charmbracelet/signature

feat: add signature
This commit is contained in:
Maas Lalani 2023-07-11 10:24:13 -04:00 committed by GitHub
commit 1e4802c7f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -42,12 +42,13 @@ You can grab one from: https://resend.com/api-keys.
### Environment
To avoid typing your `From: ` email address, you can also set the `RESEND_FROM`
To avoid typing your `From: ` email address, you can also set the `POP_FROM`
environment to pre-fill the field anytime you launch `pop`.
```bash
export RESEND_API_KEY=$(pass RESEND_API_KEY)
export RESEND_FROM=pop@charm.sh
export POP_FROM=pop@charm.sh
export POP_SIGNATURE="Sent with [Pop](https://github.com/charmbracelet/pop)!"
```
## Installation

13
main.go
View file

@ -12,7 +12,8 @@ import (
)
const RESEND_API_KEY = "RESEND_API_KEY"
const RESEND_FROM = "RESEND_FROM"
const POP_FROM = "POP_FROM"
const POP_SIGNATURE = "POP_SIGNATURE"
var (
from string
@ -21,6 +22,7 @@ var (
body string
attachments []string
preview bool
signature string
)
var rootCmd = &cobra.Command{
@ -42,6 +44,10 @@ var rootCmd = &cobra.Command{
body = string(b)
}
if signature != "" {
body += "\n\n" + signature
}
if len(to) > 0 && from != "" && subject != "" && body != "" && !preview {
err := sendEmail(to, from, subject, body, attachments)
if err != nil {
@ -85,9 +91,12 @@ func init() {
rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments")
rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipients")
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents")
rootCmd.Flags().StringVarP(&from, "from", "f", os.Getenv(RESEND_FROM), "Email's sender "+commentStyle.Render("($RESEND_FROM)"))
envFrom := os.Getenv(POP_FROM)
rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender "+commentStyle.Render("($"+POP_FROM+")"))
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")
rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending")
envSignature := os.Getenv("POP_SIGNATURE")
rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email. "+commentStyle.Render("($"+POP_SIGNATURE+")"))
}
func main() {

View file

@ -101,6 +101,11 @@ func NewModel(defaults resend.SendEmailRequest) Model {
body.Cursor.Style = cursorStyle
body.CharLimit = 4000
body.SetValue(defaults.Text)
// Adjust for signature (if none, this is a no-op)
body.CursorUp()
body.CursorUp()
body.Blur()
// Decide which input to focus.