From 4d071aacb7bc67cd12ad52d43afa00858f02b54f Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Wed, 17 Jan 2024 02:48:01 +0700 Subject: [PATCH] Adding logo to \copyright --- handler/handler.go | 7 +------ metacmd/cmds.go | 3 +++ text/text.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/handler/handler.go b/handler/handler.go index 5be0d1c973f..a80698c268e 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -8,7 +8,6 @@ import ( "database/sql" "errors" "fmt" - "image/png" "io" "log" "net/url" @@ -229,11 +228,7 @@ func (h *Handler) Run() error { if iactive { // graphics logo if typ := env.TermGraphics(); typ.Available() { - logo, err := png.Decode(bytes.NewReader(text.LogoPng)) - if err != nil { - return err - } - if err := typ.Encode(stdout, logo); err != nil { + if err := typ.Encode(stdout, text.Logo); err != nil { return err } } diff --git a/metacmd/cmds.go b/metacmd/cmds.go index 4bc170c9522..6f72ba80f26 100644 --- a/metacmd/cmds.go +++ b/metacmd/cmds.go @@ -82,6 +82,9 @@ func init() { Name: "copyright", Desc: Desc{"show " + text.CommandName + " usage and distribution terms", ""}, Process: func(p *Params) error { + if typ := env.TermGraphics(); typ.Available() { + typ.Encode(p.Handler.IO().Stdout(), text.Logo) + } p.Handler.Print(text.Copyright) return nil }, diff --git a/text/text.go b/text/text.go index 70c502fb07f..1a826f30298 100644 --- a/text/text.go +++ b/text/text.go @@ -3,7 +3,10 @@ package text import ( + "bytes" _ "embed" + "image" + "image/png" "regexp" "strings" ) @@ -119,6 +122,9 @@ var CommandUpper = func() string { return strings.ToUpper(Command()) } +// Logo is the logo. +var Logo image.Image + // LogoPng is the embedded logo. // //go:embed logo.png @@ -139,3 +145,10 @@ Arguments: Options: {{.Context.Flags|FlagsToTwoColumns|FormatTwoColumns}}{{end}}` } + +func init() { + var err error + if Logo, err = png.Decode(bytes.NewReader(LogoPng)); err != nil { + panic(err) + } +}