Documentation ¶
Overview ¶
Package term offers a simple way to use ncurses and output colored text
Index ¶
- Constants
- Variables
- func Ask(prompt string) string
- func AskYesNo(question string, noIsDefault bool) bool
- func Clear()
- func Close()
- func DrawAsciiArt(x, y int, text string) int
- func DrawBackground()
- func DrawButton(x, y int, text string, active bool)
- func DrawList(r *Box, items []string, selected int)
- func DrawRaw(x, y int, text string) int
- func FilterS(f func(string) bool, sl []string) (result []string)
- func First(f ReturnsTwoInts) int
- func Flush()
- func Init() error
- func MapS(f func(string) string, sl []string) (result []string)
- func PollEvent() *termbox.Event
- func ReadLn() string
- func Repeat(text string, n int) string
- func RepeatRune(r rune, n int) string
- func Say(x int, y int, text string)
- func ScreenHeight() int
- func ScreenWidth() int
- func Second(f ReturnsTwoInts) int
- func SetBg(bg termbox.Attribute)
- func SetFg(fg termbox.Attribute)
- func Splitlines(s string) []string
- func WaitForKey()
- func Write(x int, y int, text string, fg termbox.Attribute, bg termbox.Attribute)
- func WriteRune(x int, y int, r rune, fg termbox.Attribute, bg termbox.Attribute)
- type Box
- func (b *Box) Center(container *Box)
- func (b *Box) Fill(container *Box)
- func (b *Box) FillWithMargins(container *Box, margins int)
- func (b *Box) FillWithPercentageMargins(container *Box, horizmarginp float32, vertmarginp float32)
- func (b *Box) GetContentPos() (int, int)
- func (b *Box) GetFrame() *Rect
- func (b *Box) GetInner() *Rect
- func (b *Box) Place(container *Box)
- func (b *Box) SetFrame(r *Rect)
- func (b *Box) SetInner(r *Rect)
- func (b *Box) SetNicePlacement(container *Box)
- func (b *Box) SetThirdPlace(container *Box)
- func (b *Box) SetThirdSize(container *Box)
- type Rect
- type ReturnsTwoInts
- type TextOutput
- func (o *TextOutput) DarkBlue(s string) string
- func (o *TextOutput) DarkCyan(s string) string
- func (o *TextOutput) DarkGray(s string) string
- func (o *TextOutput) DarkGreen(s string) string
- func (o *TextOutput) DarkPurple(s string) string
- func (o *TextOutput) DarkRed(s string) string
- func (o *TextOutput) DarkYellow(s string) string
- func (o *TextOutput) Err(msg string)
- func (o *TextOutput) ErrExit(msg string)
- func (o *TextOutput) IsEnabled() bool
- func (o *TextOutput) LightBlue(s string) string
- func (o *TextOutput) LightCyan(s string) string
- func (o *TextOutput) LightGreen(s string) string
- func (o *TextOutput) LightPurple(s string) string
- func (o *TextOutput) LightRed(s string) string
- func (o *TextOutput) LightYellow(s string) string
- func (o *TextOutput) Println(msg string)
- func (o *TextOutput) White(s string) string
Constants ¶
const ( TLCHAR = '╭' // top left TRCHAR = '╮' // top right BLCHAR = '╰' // bottom left BRCHAR = '╯' // bottom right VCHAR = '│' // vertical line, left side VCHAR2 = '│' // vertical line, right side HCHAR = '─' // horizontal line HCHAR2 = '─' // horizontal bottom line )
These are used for drawing "ASCII-art" boxes
const ( Black = termbox.ColorBlack Red = termbox.ColorRed Green = termbox.ColorGreen Yellow = termbox.ColorYellow Blue = termbox.ColorBlue Magenta = termbox.ColorMagenta Cyan = termbox.ColorCyan White = termbox.ColorWhite Bold = termbox.AttrBold Underline = termbox.AttrUnderline Reverse = termbox.AttrReverse )
Only a few selected colors are included here, for providing a coherent visual appearance for command line applications. For more colors, import and use termbox directly.
const VersionString = "term 0.2"
Variables ¶
var ( BG = Blue TITLECOLOR = Cyan | Bold TEXTCOLOR = Black BOXBG = White BOXLIGHT = White | Bold BOXDARK = Black BUTTONFOCUS = Yellow | Bold BUTTONTEXT = White | Bold LISTFOCUS = Red LISTTEXT = Black )
Default color/attribute settings
Functions ¶
func DrawAsciiArt ¶
Outputs a multiline string at the given coordinates. Uses the box background color. Returns the final y coordinate after drawing.
func DrawButton ¶
Draws a button widget at the given placement, with the given text. If active is False, it will look more "grayed out".
func DrawList ¶
Draw a list widget. Takes a Box struct for the size and position. Takes a list of strings to be listed and an int that represents which item is currently selected. Does not scroll or wrap.
func DrawRaw ¶
Outputs a multiline string at the given coordinates. Uses the default background color. Returns the final y coordinate after drawing.
func First ¶
func First(f ReturnsTwoInts) int
Get the first value from the function that returns two ints
func RepeatRune ¶ added in v0.2.2
Repeat a rune n number of times
func ScreenHeight ¶
func ScreenHeight() int
Retrieve the number of lines of characters available on the current screen
func ScreenWidth ¶
func ScreenWidth() int
Retrieve the number of character columns available on the current screen
func Second ¶
func Second(f ReturnsTwoInts) int
Get the second value from the function that returns two ints
Types ¶
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box has one outer and one innner rectangle. This is useful when having margins that surrounds content.
func (*Box) FillWithMargins ¶
Place a Box inside a given container, with the given margins. Margins are given in number of characters.
func (*Box) FillWithPercentageMargins ¶
Place a Box inside a given container, using the given percentage wise ratios. horizmarginp can for example be 0.1 for a 10% horizontal margin around the inner box. vertmarginp works similarly, but for the vertical margins.
func (*Box) GetContentPos ¶
Retrieves the position of the inner rectangle.
func (*Box) SetNicePlacement ¶
Place a Box so that it either fills the given container, or is placed 1/3 from the upper left edge, depending on how much space is left.
func (*Box) SetThirdPlace ¶
Set the position of the Box to 1/3 of the size of the inner rectangle of the given container.
func (*Box) SetThirdSize ¶
Set the size of the Box to 1/3 of the size of the inner rectangle of the given container.
type ReturnsTwoInts ¶
Represents a function that takes no arguments and returns two integers
type TextOutput ¶
type TextOutput struct {
// contains filtered or unexported fields
}
func NewTextOutput ¶
func NewTextOutput(color bool, enabled bool) *TextOutput
func (*TextOutput) DarkBlue ¶
func (o *TextOutput) DarkBlue(s string) string
func (*TextOutput) DarkCyan ¶
func (o *TextOutput) DarkCyan(s string) string
func (*TextOutput) DarkGray ¶
func (o *TextOutput) DarkGray(s string) string
func (*TextOutput) DarkGreen ¶
func (o *TextOutput) DarkGreen(s string) string
func (*TextOutput) DarkPurple ¶
func (o *TextOutput) DarkPurple(s string) string
func (*TextOutput) DarkRed ¶
func (o *TextOutput) DarkRed(s string) string
func (*TextOutput) DarkYellow ¶
func (o *TextOutput) DarkYellow(s string) string
func (*TextOutput) Err ¶
func (o *TextOutput) Err(msg string)
Write an error message in red to stderr if output is enabled
func (*TextOutput) ErrExit ¶
func (o *TextOutput) ErrExit(msg string)
Write an error message to stderr and quit with exit code 1
func (*TextOutput) IsEnabled ¶
func (o *TextOutput) IsEnabled() bool
Checks if textual output is enabled
func (*TextOutput) LightBlue ¶
func (o *TextOutput) LightBlue(s string) string
func (*TextOutput) LightCyan ¶
func (o *TextOutput) LightCyan(s string) string
func (*TextOutput) LightGreen ¶
func (o *TextOutput) LightGreen(s string) string
func (*TextOutput) LightPurple ¶
func (o *TextOutput) LightPurple(s string) string
func (*TextOutput) LightRed ¶
func (o *TextOutput) LightRed(s string) string
func (*TextOutput) LightYellow ¶
func (o *TextOutput) LightYellow(s string) string
func (*TextOutput) Println ¶
func (o *TextOutput) Println(msg string)
Write a message to stdout if output is enabled
func (*TextOutput) White ¶
func (o *TextOutput) White(s string) string