ansiart2utf8

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 6 Imported by: 0

README

ansiart2utf8

GoDoc

Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8.
Escape codes and line endings are processed for terminal friendliness.


ansiart2utf8
  Converts ANSI art to UTF-8 encoding, expands cursor forward ESC sequences
  into spaces, wraps/resets at a specified line width, sends result to STDOUT.

  Leave the [FILE] parameter empty to read from STDIN.

USAGE: ansiart2utf8 [OPTION]... [FILE]...

OPTIONS
  -bytes uint
        MAXIMUM OUTPUT BYTES PER-ROW (0 = NO LIMIT)
  -debug
        DEBUG MODE: line numbering + pipe @ \n
  -w uint
        LINE WRAP WIDTH (default 80)
  -x    ANSI TO XTERM-256 COLOR SUBSTITUTION
          (to overcome strange terminal color scheme palettes)

BEFORE

Before ansiart2utf8 processing

AFTER

After ansiart2utf8 processing

Notes

To build:

  1. Install the latest Go compiler from https://golang.org/dl/
  2. Install the program: go install github.com/BourgeoisBear/ansiart2utf8/ansiart2utf8@latest

To see the result, make sure that your terminal font provides glyphs for the old CP437 box drawing characters.
Here are a few fonts that will do:

Seeing Code Page 437 in Vim

:e ++enc=cp437

Resources

Media

Documentation

Index

Constants

View Source
const (
	SGR_BOLD uint32 = 1 << iota
	SGR_FAINT
	SGR_ITALIC
	SGR_UNDERLINE
	SGR_BLNK_SLOW
	SGR_BLNK_FAST
	SGR_INVERSE
	SGR_CONCEAL
	SGR_STRIKETHROUGH
)
View Source
const (
	CIX_FG = iota
	CIX_BG
	CIX_MAX
)
View Source
const (
	DEFAULT_FG int = 37
	DEFAULT_BG int = 40
)
View Source
const (
	CHR_ESCAPE = 0x1B
	CHR_CR     = 0x0D
	CHR_LF     = 0x0A
)
View Source
const SGR_TERMINATORS = "cfhlmsuABCDEFGHJKNOPSTX\\]^_"

https://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html

Variables

View Source
var Array437 [256]rune = [256]rune{}/* 256 elements not displayed */

TRANSLATION ARRAY

View Source
var OrigDark = []OC{
	OC{Hex: `#000000`, Xterm256: 16},
	OC{Hex: `#AB0000`, Xterm256: 124},
	OC{Hex: `#00AB00`, Xterm256: 34},
	OC{Hex: `#AB5700`, Xterm256: 130},
	OC{Hex: `#0000AB`, Xterm256: 19},
	OC{Hex: `#AB00AB`, Xterm256: 127},
	OC{Hex: `#00ABAB`, Xterm256: 37},
	OC{Hex: `#ABABAB`, Xterm256: 248},
}
View Source
var OrigLight = []OC{
	OC{Hex: `#575757`, Xterm256: 240},
	OC{Hex: `#FF5757`, Xterm256: 203},
	OC{Hex: `#57FF57`, Xterm256: 83},
	OC{Hex: `#FFFF57`, Xterm256: 227},
	OC{Hex: `#5757FF`, Xterm256: 63},
	OC{Hex: `#FF57FF`, Xterm256: 207},
	OC{Hex: `#57FFFF`, Xterm256: 87},
	OC{Hex: `#FFFFFF`, Xterm256: 15},
}

Functions

func CSI_Params

func CSI_Params(pC *EscCode) bool

func HighColor

func HighColor(arCodes []int) ([]int, int)

Formats high color SGR codes

func IaEqual added in v0.5.3

func IaEqual(A, B []int) bool

func IsBtween added in v0.5.3

func IsBtween(v, lo, hi int) bool

func TranslateColors added in v0.5.3

func TranslateColors(sSGR []int, bIntense bool) []int

func VF_Ignore

func VF_Ignore(pC *EscCode) bool

func VF_NonCSI

func VF_NonCSI(pC *EscCode) bool

func VF_SGR

func VF_SGR(pC *EscCode) bool

H: extends selection on jump:

  • colors only apply to written areas, rest remain W on B
  • motions do not count as 'written'

Types

type DebugFunc

type DebugFunc func(...interface{}) (int, error)

type EscCode

type EscCode struct {
	Params    string
	Code      rune
	SubParams []int
}

func (*EscCode) Debug

func (pC *EscCode) Debug() string

func (*EscCode) Reset

func (pC *EscCode) Reset()

func (*EscCode) String

func (pC *EscCode) String() string

func (*EscCode) Validate

func (pC *EscCode) Validate() bool

type Grid

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

func NewGrid

func NewGrid(nWidth uint) (G Grid, E error)

func (*Grid) ClearFromPosToBegin

func (gr *Grid) ClearFromPosToBegin(pos GridPos)

func (*Grid) ClearFromPosToEnd

func (gr *Grid) ClearFromPosToEnd(pos GridPos)

func (*Grid) ClearLine

func (gr *Grid) ClearLine(pos GridPos, bToBegin bool)

func (*Grid) Height

func (gr *Grid) Height() int

func (*Grid) Inc

func (gr *Grid) Inc(pos *GridPos, nAmt int)

func (*Grid) IncClamp

func (gr *Grid) IncClamp(pos *GridPos, X, Y int)

Increment GridPos `pos` by X, Y Clamp result to dimensions of Grid `gr`

func (*Grid) Print

func (gr *Grid) Print(iWri io.Writer, nRowBytes int, bDebug, bXterm256, bFakeEsc bool)

func (*Grid) Put

func (gr *Grid) Put(pos GridPos, rChar rune, sgrCodes SGR) error

func (*Grid) ResetChars

func (gr *Grid) ResetChars(rChar rune)

func (*Grid) Touch

func (gr *Grid) Touch(nHeight int)

Extends grid height to `nHeight` if grid is shorter.

type GridCell

type GridCell struct {
	Char  rune
	Brush SGR
}

func (*GridCell) ClearCell

func (gc *GridCell) ClearCell()

type GridPos

type GridPos struct {
	X, Y int
}

func NewPos

func NewPos() GridPos

func (*GridPos) Denorm

func (pos *GridPos) Denorm() (X, Y int)

type GridRow

type GridRow []GridCell

func (GridRow) ClearRow added in v0.5.3

func (R GridRow) ClearRow()

type OC added in v0.5.3

type OC struct {
	Hex      string
	Xterm256 int
}

type SGR

type SGR struct {
	// Bold, Faint, Italic, Underline, Blink, Inverse, Conceal, Strikethrough bool
	Flags uint32
	Color [CIX_MAX][]int
}

func (*SGR) Fclr

func (pS *SGR) Fclr(f uint32)

func (*SGR) Fset

func (pS *SGR) Fset(f uint32)

func (*SGR) GetColor added in v0.5.3

func (pS *SGR) GetColor(CIX int, bXterm256 bool) (RET []int)

func (*SGR) MergeCodes

func (pS *SGR) MergeCodes(biCodes []int) error

MergeCodes SGR int codes (like ESC[0m) into an existing SGR struct

func (*SGR) ToEsc

func (pS *SGR) ToEsc(pPrev *SGR, bAsDiff, bXterm256, bFakeEscape bool) string

type UTF8Marshaller

type UTF8Marshaller struct {
	Width              uint
	MaxBytes           uint
	Translate2Xterm256 bool
	FakeEsc            bool
	Debug              DebugFunc
	Writer             io.Writer
}

func (UTF8Marshaller) Encode

func (M UTF8Marshaller) Encode(rdAnsi io.Reader) (E error)

ENCODES ANSI ART TO MODERN UTF8 TERMINAL CHARS PRE-RENDERS TO MEMORY (MOTION ESCAPES, COLOR CHANGES, ETC) WRITES OUTPUT, LINE-BY-LINE, TO .Writer

type ValidateFunc

type ValidateFunc func(pCode *EscCode) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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