annot

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 6 Imported by: 1

README

build Go Report Card

Annot

Annotate a string line leading to a description.

The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
 ↑  └──┬───┘          └───┬───┘                 ↑
 │     └─ adjective       │                     └─ comma
 │                        │
 └─ article               └─ facts, information, and skills acquired
                             through experience or education;
                             the theoretical or practical understanding
                             of a subject.

Installation

go get github.com/meyermarcel/annot

Example

package main

import (
	"fmt"

	"github.com/meyermarcel/annot"
)

func main() {
	fmt.Println("The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.")
	fmt.Println(annot.String(
		&annot.Annot{Col: 1, Lines: []string{"article"}},
		&annot.Annot{Col: 4, ColEnd: 11, Lines: []string{"adjective"}},
		&annot.Annot{Col: 22, ColEnd: 30, Lines: []string{
			"facts, information, and skills acquired",
			"through experience or education;",
			"the theoretical or practical understanding",
			"of a subject.",
		}},
		&annot.Annot{Col: 48, Lines: []string{"comma"}},
	))
}

Output:

The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
 ↑  └──┬───┘          └───┬───┘                 ↑
 │     └─ adjective       │                     └─ comma
 │                        │
 └─ article               └─ facts, information, and skills acquired
                             through experience or education;
                             the theoretical or practical understanding
                             of a subject.

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/meyermarcel/annot"
)

func main() {
	fmt.Println("The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.")
	fmt.Println(annot.String(
		&annot.Annot{Col: 1, Lines: []string{"article"}},
		&annot.Annot{Col: 4, ColEnd: 11, Lines: []string{"adjective"}},
		&annot.Annot{Col: 22, ColEnd: 30, Lines: []string{
			"facts, information, and skills acquired",
			"through experience or education;",
			"the theoretical or practical understanding",
			"of a subject.",
		}},
		&annot.Annot{Col: 48, Lines: []string{"comma"}},
	))
}
Output:

The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
 ↑  └──┬───┘          └───┬───┘                 ↑
 │     └─ adjective       │                     └─ comma
 │                        │
 └─ article               └─ facts, information, and skills acquired
                             through experience or education;
                             the theoretical or practical understanding
                             of a subject.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(annots ...*Annot) string

String returns the rendered annotations as a string.

func Write

func Write(w io.Writer, annots ...*Annot) error

Write renders the annotations and writes them to a writer w.

Types

type Annot

type Annot struct {
	// Col is the position of the arrowhead of the annotation.
	// E.g. 0 draws an arrow to the first character in a line.
	Col int

	// ColEnd needs to be higher than Col. If ColEnd is set a
	// range is annotated.
	ColEnd int

	// Lines is the text of the annotation represented in one or more lines.
	Lines []string
	// contains filtered or unexported fields
}

Annot annotates information with a text (represented in Lines) at a position in a line (Col).

func (*Annot) AppendLines

func (a *Annot) AppendLines(lines ...string)

AppendLines adds initial or appends additional lines to an annotation.

type ColExceedsColEndError added in v0.4.0

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

func (*ColExceedsColEndError) Error added in v0.4.0

func (e *ColExceedsColEndError) Error() string

func (*ColExceedsColEndError) Is added in v0.4.0

func (e *ColExceedsColEndError) Is(target error) bool

type OverlapError added in v0.4.0

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

func (*OverlapError) Error added in v0.4.0

func (e *OverlapError) Error() string

func (*OverlapError) Is added in v0.4.0

func (e *OverlapError) Is(target error) bool

Jump to

Keyboard shortcuts

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