combinat-0.2.7.2: Generate and manipulate various combinatorial objects.

Safe HaskellNone
LanguageHaskell2010

Math.Combinat.ASCII

Contents

Description

A mini-DSL for ASCII drawing of structures.

From some structures there is also Graphviz and/or diagrams (http://projects.haskell.org/diagrams) visualization support (the latter in the separate libray combinat-diagrams).

Synopsis

The basic type

data ASCII Source

The type of a (rectangular) ASCII figure. Internally it is a list of lines of the same length plus the size.

Note: The Show instance is pretty-printing, so that it's convenient in ghci.

Constructors

ASCII 

Fields

asciiSize :: (Int, Int)
 
asciiLines :: [String]
 

Instances

class DrawASCII a where Source

A type class to have a simple way to draw things

Methods

ascii :: a -> ASCII Source

emptyRect :: ASCII Source

An empty (0x0) rectangle

Alignment

data HAlign Source

Horizontal alignment

Constructors

HLeft 
HCenter 
HRight 

data VAlign Source

Vertical alignment

Constructors

VTop 
VCenter 
VBottom 

data Alignment Source

Constructors

Align HAlign VAlign 

Extension

hExtendTo :: HAlign -> Int -> ASCII -> ASCII Source

Extends an ASCII figure with spaces horizontally to the given width

vExtendTo :: VAlign -> Int -> ASCII -> ASCII Source

Extends an ASCII figure with spaces vertically to the given height

hExtendWith :: HAlign -> Int -> ASCII -> ASCII Source

Extend horizontally with the given number of spaces

vExtendWith :: VAlign -> Int -> ASCII -> ASCII Source

Extend vertically with the given number of empty lines

hIndent :: Int -> ASCII -> ASCII Source

Horizontal indentation

vIndent :: Int -> ASCII -> ASCII Source

Vertical indentation

Separators

data HSep Source

Horizontal separator

Constructors

HSepEmpty

empty separator

HSepSpaces Int

n spaces

HSepString String

some custom string, eg. " | "

Instances

data VSep Source

Vertical separator

Constructors

VSepEmpty

empty separator

VSepSpaces Int

n spaces

VSepString [Char]

some custom list of characters, eg. " - " (the characters are interpreted as below each other)

Instances

Padding

hPad :: Int -> ASCII -> ASCII Source

Horizontally pads with the given number of spaces, on both sides

vPad :: Int -> ASCII -> ASCII Source

Vertically pads with the given number of empty lines, on both sides

pad :: ASCII -> ASCII Source

Pads by single empty lines vertically and two spaces horizontally

Concatenation

hCatWith :: VAlign -> HSep -> [ASCII] -> ASCII Source

Horizontal concatenation

vCatWith :: HAlign -> VSep -> [ASCII] -> ASCII Source

Vertical concatenation

Tabulate

data MatrixOrder Source

Order of elements in a matrix

Constructors

RowMajor 
ColMajor 

autoTabulate Source

Arguments

:: MatrixOrder

whether to use row-major or column-major ordering of the elements

-> Either Int Int

(Right x) creates x columns, while @(Left y)$ creates y rows

-> [ASCII]

list of ASCII rectangles

-> ASCII 

Automatically tabulates ASCII rectangles.

Captions

caption :: String -> ASCII -> ASCII Source

Adds a caption to the bottom, with default settings.

caption' :: Bool -> HAlign -> String -> ASCII -> ASCII Source

Adds a caption to the bottom. The Bool flag specifies whether to add an empty between the caption and the figure

Testing / miscellanea

asciiBox :: (Int, Int) -> ASCII Source

An ASCII box of the given size

roundedAsciiBox :: (Int, Int) -> ASCII Source

An "rounded" ASCII box of the given size

asciiShow :: Show a => a -> ASCII Source