summaryrefslogtreecommitdiff
path: root/widgets/pgpinfo.go
diff options
context:
space:
mode:
authorKalyan Sriram <coder.kalyan@gmail.com>2020-07-27 01:03:55 -0700
committerReto Brunner <reto@labrat.space>2020-08-06 21:42:06 +0200
commit905cb9dfd3ef197bb4b59039a1be76ce2c8e3099 (patch)
tree2d923c42ec224b1d525d942a7bb17416f4a62dd5 /widgets/pgpinfo.go
parent548a5fff68a648a5e0b6fd909e3c21463addc8af (diff)
downloadaerc-905cb9dfd3ef197bb4b59039a1be76ce2c8e3099.zip
Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of aerc's look (color scheme, font weight, etc). Default styleset is installed to /path/to/aerc/stylesets/default.
Diffstat (limited to 'widgets/pgpinfo.go')
-rw-r--r--widgets/pgpinfo.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/widgets/pgpinfo.go b/widgets/pgpinfo.go
index 5da9141..94fb877 100644
--- a/widgets/pgpinfo.go
+++ b/widgets/pgpinfo.go
@@ -3,40 +3,40 @@ package widgets
import (
"errors"
+ "git.sr.ht/~sircmpwn/aerc/config"
"git.sr.ht/~sircmpwn/aerc/lib/ui"
- "github.com/gdamore/tcell"
"golang.org/x/crypto/openpgp"
pgperrors "golang.org/x/crypto/openpgp/errors"
)
type PGPInfo struct {
ui.Invalidatable
- details *openpgp.MessageDetails
+ details *openpgp.MessageDetails
+ uiConfig config.UIConfig
}
-func NewPGPInfo(details *openpgp.MessageDetails) *PGPInfo {
- return &PGPInfo{details: details}
+func NewPGPInfo(details *openpgp.MessageDetails, uiConfig config.UIConfig) *PGPInfo {
+ return &PGPInfo{details: details, uiConfig: uiConfig}
}
func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
- errorStyle := tcell.StyleDefault.Background(tcell.ColorRed).
- Foreground(tcell.ColorWhite).Bold(true)
- softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).Bold(true)
- validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
+ errorStyle := p.uiConfig.GetStyle(config.STYLE_ERROR)
+ warningStyle := p.uiConfig.GetStyle(config.STYLE_WARNING)
+ validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS)
+ defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) ||
p.details.SignedBy == nil {
- x := ctx.Printf(0, 0, softErrorStyle, "*")
- x += ctx.Printf(x, 0, tcell.StyleDefault,
+ x := ctx.Printf(0, 0, warningStyle, "*")
+ x += ctx.Printf(x, 0, defaultStyle,
" Signed with unknown key (%8X); authenticity unknown",
p.details.SignedByKeyId)
} else if p.details.SignatureError != nil {
x := ctx.Printf(0, 0, errorStyle, "Invalid signature!")
- x += ctx.Printf(x, 0, tcell.StyleDefault.
- Foreground(tcell.ColorRed).Bold(true),
+ x += ctx.Printf(x, 0, errorStyle,
" This message may have been tampered with! (%s)",
p.details.SignatureError.Error())
} else {
@@ -44,24 +44,26 @@ func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
ident := entity.PrimaryIdentity()
x := ctx.Printf(0, 0, validStyle, "✓ Authentic ")
- x += ctx.Printf(x, 0, tcell.StyleDefault,
+ x += ctx.Printf(x, 0, defaultStyle,
"Signature from %s (%8X)",
ident.Name, p.details.SignedByKeyId)
}
}
func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) {
- validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
+ validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS)
+ defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
entity := p.details.DecryptedWith.Entity
ident := entity.PrimaryIdentity()
x := ctx.Printf(0, y, validStyle, "✓ Encrypted ")
- x += ctx.Printf(x, y, tcell.StyleDefault,
+ x += ctx.Printf(x, y, defaultStyle,
"To %s (%8X) ", ident.Name, p.details.DecryptedWith.PublicKey.KeyId)
}
func (p *PGPInfo) Draw(ctx *ui.Context) {
- ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+ defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
if p.details.IsSigned && p.details.IsEncrypted {
p.DrawSignature(ctx)
p.DrawEncryption(ctx, 1)