decorator

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 4 Imported by: 1

README

Overview

Decorator is a simple library for adding comments onto lines of text, primarily aimed at user-friendly error messages.

For example:

image

The above output was generated from the following code:

  var d Decorator
	
  d.AddLine("printf(\"%s\", 400)", LineMetadata{FileName: "main.c", LineNumber: 5})
  d.ColourLine(0, LineColour{From: 0, To: 6, Colour: FgYellow})
  d.ColourLine(0, LineColour{From: 7, To: 11, Colour: FgMagenta})
  d.ColourLine(0, LineColour{From: 13, To: 16, Colour: FgCyan})

  d.AddTopComment(0, 8, "%s was specified.")
  d.ColourTopComment(0, 0, LineColour{From: 0, To: 3, Colour: FgGreen})

  d.AddBottomComment(0, 13, "But a %d value was passed")
  d.ColourBottomComment(0, 0, LineColour{From: 6, To: 8, Colour: FgRed})
  
  print(d.String())

yada yada TODO

Documentation

Overview

A simple package for adding colourful comments onto source code lines primarily for the use of user-friendly error messages.

Index

Constants

View Source
const (
	Normal    = "\033[0m"
	Bold      = "\033[1m"
	FgBlack   = "\033[30m"
	FgRed     = "\033[31m"
	FgGreen   = "\033[32m"
	FgYellow  = "\033[33m"
	FgBlue    = "\033[34m"
	FgMagenta = "\033[35m"
	FgCyan    = "\033[36m"
	FgWhite   = "\033[37m"
	BgBlack   = "\033[40m"
	BgRed     = "\033[41m"
	BgGreen   = "\033[42m"
	BgYellow  = "\033[43m"
	BgBlue    = "\033[44m"
	BgMagenta = "\033[45m"
	BgCyan    = "\033[46m"
	BgWhite   = "\033[47m"
)

The different styles that can be applied to a line. Currently you can only specify one value per line.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decorator

type Decorator struct {
	// contains filtered or unexported fields
}

The main type responsible for this library's functionality.

func (*Decorator) AddBottomComment

func (dec *Decorator) AddBottomComment(line int, at int, comment string) error

Adds a comment below the specified line, pointing at a specific character in that line. Lines can have multiple bottom comments.

func (*Decorator) AddLine

func (dec *Decorator) AddLine(line string, meta LineMetadata) error

Adds a new line to be decorated.

func (*Decorator) AddTopComment

func (dec *Decorator) AddTopComment(line int, at int, comment string) error

Adds a comment above the specified line, pointing at a specific character in that line. Lines can have multiple top comments.

func (*Decorator) ColourBottomComment

func (dec *Decorator) ColourBottomComment(line int, comment int, colour LineColour) error

Applies colouring to the specified comment for the specified line.

func (*Decorator) ColourLine

func (dec *Decorator) ColourLine(line int, colour LineColour) error

Applies colouring to the specified line.

func (*Decorator) ColourTopComment

func (dec *Decorator) ColourTopComment(line int, comment int, colour LineColour) error

Applies colouring to the specified comment for the specified line.

func (*Decorator) String

func (dec *Decorator) String() string

Constructs a string consisting of all the lines; their metadata, and their comments.

type LineColour

type LineColour struct {
	// The index of the first character to colour.
	From int

	// The index of the last character (non-inclusive) to colour.
	To int

	// The colouring to apply.
	Colour LineColourEnum
}

Describes how to colour a particular segment of a line.

type LineColourEnum

type LineColourEnum string

An enumeration defining how to style a line.

type LineMetadata

type LineMetadata struct {
	// The line number that this line was extracted from.
	LineNumber int

	// The file that this line belongs to.
	FileName string
	// contains filtered or unexported fields
}

Describes metadata about a line.

Jump to

Keyboard shortcuts

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