html2xterm

package module
v0.0.0-...-e38ed02 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 5 Imported by: 0

README

html2xterm

GoDoc MIT License Go Report Card CircleCI codecov

Convert (certain) colorized HTML to ANSI and xterm.js

Works well with HTML generated by:

Usage:

$ ./html2xterm saved.html > saved.ans
$ ./html2xterm -js saved.html > saved.js

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	R, G, B uint8
}

Color represents a 24-bit RGB color.

func (Color) ANSI

func (c Color) ANSI() string

ANSI returns the Color's ANSI code using true-color notation (24-bit).

type Line

type Line struct {
	Segments []Segment
}

Line represents a line of Output.

func (Line) ANSI

func (l Line) ANSI() string

ANSI returns the ANSI representation of the line written in true-color notation (24-bit).

func (Line) JS

func (l Line) JS() string

JS returns an unquoted JavaScript string of the ANSI output. The string is escaped to work inside either double or single quotes.

func (Line) LeftPad

func (l Line) LeftPad(n int) Line

LeftPad returns a new Line left-padded with n spaces.

func (Line) Length

func (l Line) Length() int

Length returns the line length in number of characters.

func (Line) String

func (l Line) String() string

String returns the text-only output without ANSI codes.

type Output

type Output struct {
	Lines []Line
}

Output represents the parsed HTML. See the Convert function.

func Center

func Center(minWidth int, outputs ...Output) []Output

Center returns a slice of Output's centered together. If no outputs are at least minWidth in length, then they are centered using minWidth. It is valid to call this function with midWidth set to 0.

func Convert

func Convert(html string) (Output, error)

Convert converts HTML to an Output which can be used to extract ANSI or xterm.js strings.

Specifically, this function looks for <span> and <font> tags with "color" attributes or "style" attributes which specify a color. Tags surrounded in <div></div> are treated as individual lines and <br> creates a new line.

It's known to work with the HTML output of a few sites: - http://patorjk.com/text-color-fader/ - https://asciiart.club/ - https://www.text-image.com/convert/

func (Output) ANSI

func (o Output) ANSI() string

ANSI returns the ANSI representation of the output written in true-color notation (24-bit).

func (*Output) Center

func (o *Output) Center(width int)

Center centers all lines using the specified width. If the Output's MaxLength is greater than or equal to width no change is made.

func (Output) JS

func (o Output) JS() string

JS returns an unquoted JavaScript string of the ANSI output. The string is escaped to work inside either double or single quotes.

func (Output) MaxLength

func (o Output) MaxLength() int

MaxLength returns the maximum line length in number of characters.

func (Output) String

func (o Output) String() string

String returns the text-only output without ANSI codes.

type Segment

type Segment struct {
	Text  string
	Color Color
}

Segment represents a text segment of a line and its color.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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