highlight

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package highlight classifies the bytes of Ant source for coloring, as the REPL colors its input and ant check its code snippets.

Index

Constants

View Source
const Reset = "\x1b[0m"

Reset ends a color.

Variables

View Source
var ANSI = [Bad + 1]string{
	Keyword:  "\x1b[35m",
	Constant: "\x1b[33m",
	String:   "\x1b[32m",
	Number:   "\x1b[33m",
	Regex:    "\x1b[31m",
	Comment:  "\x1b[90m",
	Type:     "\x1b[36m",
	Function: "\x1b[34m",
	Markup:   "\x1b[36m",
	Bad:      "\x1b[31m",
}

ANSI colors each class with the terminal's own sixteen colors, so that it suits a light or a dark background alike.

Functions

func Paint

func Paint(sb *strings.Builder, s string, cls []Class, base int, colors []string)

Paint writes s colored by the class of each of its bytes, which cls gives from byte base of the source it was computed for; colors gives the escape sequence that starts each class, or "" for none. It resets the color at the end of every run.

Types

type Class

type Class uint8

A Class is what a byte of source is, for its color.

const (
	Plain    Class = iota
	Keyword        // a keyword
	Constant       // true, false, null, void
	String         // a string or raw string, including the braces of its interpolations
	Number         // a number literal
	Regex          // a regular expression literal
	Comment        // a comment
	Type           // a namespace, a type, or a module: a capitalized name, or a built-in type
	Function       // a name that is called
	Markup         // an HTML expression, outside its interpolations
	Bad            // what the lexer could not read, or a reserved word
)

func Classes

func Classes(src string) []Class

Classes returns the class of every byte of src, which may be unfinished: the lexer goes on past what it cannot read.

func FileClasses

func FileClasses(src string) []Class

FileClasses is Classes for the whole text of a file, whose first line may be a #! line.

Jump to

Keyboard shortcuts

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