geany

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

README

Test Pipeline Result CodeQL Pipeline Result Security Pipeline Result Go Report Card Code Coverage OpenSSF Scorecard FOSSA Status FOSSA Status GoDoc Reference

   ..
  =≙≙=
 _.OO._
/ \__/ \
 \_><_/
 |=%%=|
  \  /
   \ \ 
   / /
   |/
   (o)                    
    \ \____.----(O)----.,.---.
     `-__  o \_______/ o | O |
         `\  O O O O O  / `-`
           `-=========-`

geany

geany is a library to easily print logos enriched with custom information using the Go templating engine.

Writing a program and just wanting a nice logo for the start should be without hassles. geany aims to provide a smooth experience for developers that just want to show a nice logo and want to enrich it with some more information.

Installation

To install geany, you can use the following command:

$ go get github.com/AlphaOne1/geany

Getting Started

Simple Case

Assuming a file logo.tmpl like this one:

   ..
  =≙≙=
 _.OO._
/ \__/ \
 \_><_/
 |=%%=|      Build using {{ .Geany.GoVersion   }}
  \  /                on {{ .Geany.VcsTime     }}
   \ \     from revision {{ .Geany.VcsRevision }} {{ if eq .Geany.VcsModified "*" }} (modified) {{ end }}
   / /
   |/
   (o)
    \ \____.----(O)----.,.---.
     `-__  o \_______/ o | O |
         `\  O O O O O  / `-`
           `-=========-`

A simple program to produce the logo could look like this:

package main

import (
	_ "embed"

	"github.com/AlphaOne1/geany"
)

//go:embed logo.tmpl
var logo string

func main() {
	_ = geany.PrintLogo(logo, nil)
}

This program produces the following output:

   ..
  =≙≙=
 _.OO._
/ \__/ \
 \_><_/
 |=%%=|      Build using go1.24.1
  \  /                on 2025-03-16T03:16:43Z
   \ \     from revision ce78d813448120739f345efa679b2b244a42e679 
   / /
   |/
   (o)
    \ \____.----(O)----.,.---.
     `-__  o \_______/ o | O |
         `\  O O O O O  / `-`
           `-=========-`

geany provides these attributes inside .Geany

Name Description
GoVersion Go Version used to build the executable
VcsModified Contains a * if the content of the repository was modified before the build, if version control is used
VcsRevision Revision of version control system, if used
VcsTime Time of the revision in the version control system, if used
User Provided Data

Assuming that the geany supplied information is not enough, a user can provide additional data. This data becomes accessible in the template using .Value. A modified example template could look like this:

   ..      ________________________
  =≙≙=    / {{ .Values.Greeting }}
 _.OO._  /
/ \__/ \
 \_><_/
 |=%%=|      Build using {{ .Geany.GoVersion   }}
  \  /                on {{ .Geany.VcsTime     }}
   \ \     from revision {{ .Geany.VcsRevision }} {{ if eq .Geany.VcsModified "*" }} (modified) {{ end }}
   / /
   |/   Special Features A: {{ if .Values.FeatureA -}} enabled {{- else -}} disabled {{- end }}
   (o)                   B: {{ if .Values.FeatureB -}} enabled {{- else -}} disabled {{- end }}
    \ \____.----(O)----.,.---.
     `-__  o \_______/ o | O |
         `\  O O O O O  / `-`
           `-=========-`

The Go program of the simple case needs only slight modification to provide the new data:

package main

import (
	_ "embed"

	"github.com/AlphaOne1/geany"
)

//go:embed logo.tmpl
var logo string

func main() {
	_ = geany.PrintLogo(logo,
		&struct {
			FeatureA bool
			FeatureB bool
			Greeting string
		}{
			FeatureA: true,
			FeatureB: false,
			Greeting: "Hi Geany!",
		})
}

This modified version would print now:

   ..      ________________________
  =≙≙=    / Hi Geany!
 _.OO._  /
/ \__/ \
 \_><_/
 |=%%=|      Build using go1.24.1
  \  /                on 2025-03-16T03:16:43Z
   \ \     from revision ce78d813448120739f345efa679b2b244a42e679 
   / /
   |/   Special Features A: enabled
   (o)                   B: disabled
    \ \____.----(O)----.,.---.
     `-__  o \_______/ o | O |
         `\  O O O O O  / `-`
           `-=========-`

Instead of using a struct, a map could be used to pass the data into the template. The keys of the map then take the place of the structure members.

Basic or Fallback Output

geany offers a fallback mechanism, should a problem occur in normal logo output. Should normal operation fail, the PrintSimple function is employed to somehow give some information, without having the normal logo around.

Note that the logo template itself is checked always and the program will report a broken logo template visibly. So this is not intended to cover up poor logo template design.

The following program uses PrintSimple directly:

package main

import (
	_ "embed"

	"github.com/AlphaOne1/geany"
)

func main() {
	_ = geany.PrintSimple(nil)
}

It produces the following output:

./logo_simple
{
    "Geany": {
        "VcsRevision": "5f4b130546ef200186692d4f88c83386f0c4ae98",
        "VcsTime": "2025-03-16T03:21:23Z",
        "VcsModified": "*",
        "GoVersion": "go1.24.1"
    },
    "Values": null
}

All examples can be found in examples folder.

Documentation

Overview

Package geany contains the logo printing functionality.

Index

Constants

This section is empty.

Variables

View Source
var ErrWriterNil = errors.New("writer is nil")

ErrWriterNil indicates that the provided io.Writer is nil and cannot be used.

Functions

func PrintLogo(tmpl string, values any) error

PrintLogo is a convenience wrapper around PrintLogoWriter, as logos are normally printed to standard output.

func PrintLogoWriter

func PrintLogoWriter(writer io.Writer, tmpl string, values any) error

PrintLogoWriter takes a text/template string as its parameter and renders it to be the logo. It offers the following data for the template:

  • VcsRevision
  • VcsTime
  • VcsModified
  • GoVersion

these can be referenced in the template, e.g., using `{{ .Geany.VcsRevision }}`. An additional custom value can be accessed via the Values field. Its type must match the way that it is accessed in the logo and is accessed using e.g. `{{ .Values.Foo }}`.

The template is parsed and executed. In case of an error, the program's name and user given data are printed as JSON as fallback. The original error and, in case, the error of the fallback are returned.

func PrintSimple

func PrintSimple(values any) error

PrintSimple is a convenience wrapper around PrintSimpleWriter, as logos are normally printed to standard output.

func PrintSimpleWriter

func PrintSimpleWriter(writer io.Writer, values any) error

PrintSimpleWriter outputs just the name of the program, the build information and, in case, the user given data to a user provided io.Writer.

Types

This section is empty.

Directories

Path Synopsis
examples
logo_embed command
Package main contains the geany example with embedded logo.
Package main contains the geany example with embedded logo.
logo_file command
Package main contains the geany example with read logo from a file.
Package main contains the geany example with read logo from a file.
logo_owndata command
Package main contains the geany example with embedded logo and custom data.
Package main contains the geany example with embedded logo and custom data.
logo_simple command
Package main contains the geany example with only the simple logo output.
Package main contains the geany example with only the simple logo output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL