sample

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package sample opens and encodes the example embedded text files. These files are used for demostrating the info and the view commands.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrEncode   = errors.New("no encoding provided")
	ErrConvert  = errors.New("unknown convert method")
	ErrConvNil  = errors.New("conv argument cannot be empty")
	ErrName     = errors.New("sample filename does not exist")
	ErrNotFound = errors.New("internal embed file is not found")
)
View Source
var ANSI embed.FS

ANSI is the embedded file system with the ansi subdirectory.

View Source
var File embed.FS

File is the embedded file system with all the static files.

View Source
var PlainText embed.FS

PlainText is the embedded file system with the text subdirectory.

Functions

func Map

func Map() map[string]Sample

Map is the collection of sample text files. Each sample includes the output method, character encoding, the filename and a brief description.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/sample"
)

func main() {
	s := sample.Map()["037"]
	fmt.Printf("%s - %s, %s", s.Name, s.Description, s.Encoding)
}
Output:

plaintext/cp037.txt - EBCDIC 037 IBM mainframe test, IBM Code Page 037

func Open

func Open(name string) ([]byte, error)

Open the named sample text file. The byte array is encoded using the original character encoding.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/sample"
)

func main() {
	b, _ := sample.Open("037")
	fmt.Print(len(b))
}
Output:

130

func Transform

func Transform(e encoding.Encoding, b ...byte) ([]byte, error)

Transform the byte array to use the supplied character encoding.

func Valid

func Valid(name string) bool

Valid reports whether the named sample text file exists.

Types

type Flags

type Flags struct {
	Input    encoding.Encoding // Input encoding is set using the input flag.
	Original bool              // Original encoding is set using the original flag.
}

Flags and configuration values by the user.

func (Flags) Open

func (flag Flags) Open(conv *convert.Convert, name string) ([]rune, error)

Open and convert the named sample text file into Unicode runes. Use the other open function to return the raw bytes in their original encoding.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/convert"
	"github.com/bengarrett/retrotxtgo/sample"
	"golang.org/x/text/encoding/charmap"
)

func main() {
	c := convert.Convert{}
	f := sample.Flags{Input: charmap.CodePage037}
	r, _ := f.Open(&c, "037")
	fmt.Print(string(r[0:15]))
}
Output:

RetroTxt EBCDIC

type Output

type Output int

Output method for the embedded text files.

const (
	Ansi Output = iota // should only be use with ANSI text
	Ctrl               // print the common text control codes as characters
	Text               // obeys the common text controls
	Dump               // obeys the common text controls except for EOF, end-of-file
)

type Sample

type Sample struct {
	// the order of these fields must not be changed
	Convert     Output            // Convert text method.
	Encoding    encoding.Encoding // Encoding used by the sample.
	Name        string            // Name of the sample.
	Description string            // Description of the sample.
}

Sample textfile data.

Jump to

Keyboard shortcuts

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