go3a

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: GPL-3.0 Imports: 6 Imported by: 1

README

go3a

This library provides a structural representation of 3a ascii animations format and methods for reading and writing it.

Usage

Install

$ go get github.com/DomesticMoth

Here's a simple example that parsing a string in 3a format and displaying title, author and body:

package main

import  (
	"github.com/DomesticMoth/go3a"
	"fmt"
)

func main() {
	text := "width 12\nheight 5\ndelay 300\ncolors fg\ntitle just an apple\nauthor DomesticMoth\n\n\n  ,--./,-.  444444444444\n / //     \\ 444cc4444444\n|          |444444444444\n \\        / 444444444444\n  '._,._,'  444444444444\n\n  ,--./,-.  444444444444\n / //    _\\ 444cc4444444\n|       /   4444444ffff4\n \\      `-, 4444444ffff4\n  '._,._,'  444444444444\n\n  ,--./,-.  444444444444\n / //   ,-' 444cc4444444\n|      (    4444444f4444\n \\      `-, 4444444ffff4\n  '._,._,'  444444444444\n"
	art, _ := go3a.Load(text)
	fmt.Println("title: ", art.Header.Title)
	fmt.Println("author: ", art.Header.Author)
	fmt.Println(art.Body.ToString(true))
}

Short API description

Structs

The core of the library is the Art struct, which implements the 3a structure:

type Art struct {
	Header Header
	Body Body
}

Header struct contains information about the header of 3a file:

type Header struct {
	Width uint16
	Height uint16
	Delay uint16
	LoopEnable bool
	ColorMod ColorMod
	Utf8 bool
	Datacols uint16
	Preview uint16
	Audio string
	Title string
	Author string
}

Body type is a list of frames, where each frame is a list of rows, and each row is a list of row fragments:

type Row []RowFragment
type Frame []Row
type Body []Frame

Each RowFragment is a set of consecutive symbols with the same values of foreground and background colors:

type RowFragment struct {
    Text string
    FgColor Color
    BgColor Color
}
Functions

Load(s string) (*Art, error) and Save(art Art, pretify bool) string functions allow you to convert strings to Art and back.
LoadFile(path string) (*Art, error) and SaveFile(art Art, pretify bool, path string) error functions allow you to read 3a files to Art and write Art to 3a files.

Documentation

Overview

This file is part of go3a.

go3a is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

go3a is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with go3a. If not, see <https://www.gnu.org/licenses/>.

This file is part of go3a.

go3a is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

go3a is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with go3a. If not, see <https://www.gnu.org/licenses/>.

This file is part of go3a.

go3a is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

go3a is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with go3a. If not, see <https://www.gnu.org/licenses/>.

This file is part of go3a.

go3a is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

go3a is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with go3a. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	DEFAULT_DELAY   uint16   = 50
	DEFAULT_PREVIEW uint16   = 0
	DEFAULT_LOOP    bool     = true
	DEFAULT_COLORS  ColorMod = ColorModNone
	DEFAULT_UTF8    bool     = false
)

Variables

This section is empty.

Functions

func Save added in v0.1.2

func Save(art Art, pretify bool) string

func SaveFile added in v0.1.2

func SaveFile(art Art, pretify bool, path string) error

Types

type Art

type Art struct {
	Header Header
	Body   Body
}

func Load added in v0.1.2

func Load(s string) (*Art, error)

func LoadFile added in v0.1.2

func LoadFile(path string) (*Art, error)

type Body

type Body []Frame

func BodyFromString added in v0.1.2

func BodyFromString(s string, h Header) (Body, error)

func (Body) ToString added in v0.1.2

func (frames Body) ToString(pretify bool) string

type Color

type Color int64
const (
	ColorBlack Color = iota
	ColorBlue
	ColorGreen
	ColorCyan
	ColorRed
	ColorMagenta
	ColorYellow
	ColorWhite
	ColorGray
	ColorBrightBlue
	ColorBrightGreen
	ColorBrightCyan
	ColorBrightRed
	ColorBrightMagenta
	ColorBrightYellow
	ColorBrightWhite
	NoColor
)

func (Color) ToString added in v0.1.2

func (c Color) ToString() string

type ColorMod

type ColorMod int64
const (
	ColorModNone ColorMod = iota
	ColorModFg
	ColorModBg
	ColorModFull
)

func ColorModFromString added in v0.1.2

func ColorModFromString(s string) (ColorMod, error)

func (ColorMod) ToDatacols added in v0.1.2

func (cm ColorMod) ToDatacols() uint16

func (ColorMod) ToString added in v0.1.2

func (cm ColorMod) ToString() string

type Frame

type Frame []Row
type Header struct {
	Width      uint16
	Height     uint16
	Delay      uint16
	LoopEnable bool
	ColorMod   ColorMod
	Utf8       bool
	Datacols   uint16
	Preview    uint16
	Audio      string
	Title      string
	Author     string
}

func HeaderFromString added in v0.1.2

func HeaderFromString(s string) (*Header, error)

func (Header) ToString added in v0.1.2

func (header Header) ToString() string

type InvalidHeight

type InvalidHeight struct{}

func (InvalidHeight) Error

func (e InvalidHeight) Error() string

type InvalidWidth

type InvalidWidth struct{}

func (InvalidWidth) Error

func (e InvalidWidth) Error() string

type Row

type Row []RowFragment

type RowFragment

type RowFragment struct {
	Text    string
	FgColor Color
	BgColor Color
}

type ThereIsNoBody

type ThereIsNoBody struct{}

func (ThereIsNoBody) Error

func (e ThereIsNoBody) Error() string

type UnknownColor

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

func (UnknownColor) Error

func (e UnknownColor) Error() string

type UnknownColorMod

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

func (UnknownColorMod) Error

func (e UnknownColorMod) Error() string

Jump to

Keyboard shortcuts

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