term
Text colour and style, cursor movement, progress bars, reading keys and the mouse, and the terminal size.
import term
The term package has everything a good looking command line program needs: text colour and style, progress bars, and for full screen programs, cursor movement and reading keys one at a time.
The colour functions, such as Red, return a new string and print nothing. When the output goes to a file or another program, or NO_COLOR is set, nothing is added and the text stays plain. SetColorMode changes that behaviour.
The functions whose names start with Seq only return the escape sequence, and the one with the same name without the prefix sends it right away. To read keys, put the terminal into raw mode with MakeRaw or MakeCbreak, and always put it back with Restore.
Types
Bar
struct BarNewBar and set the fields to change how it looks.| Name | Type | Description |
|---|---|---|
total | int = 100 | The full value; 100 by default. |
current | int = 0 | The current value. |
width | int = 0 | The width of the bar in cells; zero means automatic, from the terminal width, between 8 and 80. |
label | str = "" | The text that comes before the bar. |
fill | str = "#" | The character of the filled part. |
head | str = "" | The head character; when it is not empty it takes the last filled cell. |
empty | str = "-" | The character of the empty part. |
color | int = 0 | The colour code of the filled part, such as FgGreen; zero means no colour. |
show_percent | bool = true | Show the percentage; on by default. |
show_count | bool = false | Show the count as 150/200. |
show_eta | bool = false | Show the estimated time remaining. |
hide_cursor | bool = true | Hide the cursor while drawing; on by default. |
start_ms | i64 = 0 | The start time, used to work out the time remaining. |
drawn | bool = false | Whether the bar has been drawn at least once. |
done | bool = false | Whether the bar has finished. |
import term
func main:
term.SetColorMode(term.ColorNever)
mut b := term.NewBar(200, "download")
b.width = 20
b.fill = "█"
b.empty = "░"
term.BarSet(b, 50)
println term.BarRender(b)
term.BarAdd(b, 100)
b.show_count = true
println term.BarRender(b)
mut s := term.NewSpinner("working")
defer term.SpinnerFree(s)
println s.label, s.frames.len() > 0
mut frames := Vector {} as Vector<str>
frames.push("◐")
frames.push("◓")
mut s2 := term.NewSpinnerFrames("loading", frames)
defer term.SpinnerFree(s2)
repeat 3:
println term.SpinnerFrame(s2)
s2.idx = (s2.idx + 1) % frames.len()
end
endSpinner
struct Spinner| Name | Type | Description |
|---|---|---|
frames | Vector | The frames of the spinner, shown in turn. |
idx | int = 0 | The index of the current frame. |
label | str = "" | The text beside the spinner. |
color | int = 0 | The colour code of the frame; zero means no colour. |
drawn | bool = false | Whether anything has been drawn on the screen. |
The example for this item is shown with the ones above: term-Bar.salam
Key
struct Key| Name | Type | Description |
|---|---|---|
code | int = 0 | The kind of key; one of the Key constants. |
ch | str = "" | The character, when the key is one. |
ctrl | bool = false | Control was held as well. |
alt | bool = false | Alt was held as well. |
shift | bool = false | Shift was held as well. |
raw | str = "" | The raw bytes that came from the terminal. |
import term
func describe(k: term.Key): str:
if k.code == term.KeyChar:
ret "char " + k.ch + (k.ctrl ? " with ctrl" : "") + (k.alt ? " with alt" : "")
else k.code == term.KeyUp:
ret "up"
else k.code == term.KeyEnter:
ret "enter"
else k.code == term.KeyEscape:
ret "escape"
else k.code >= term.KeyF1 and k.code < term.KeyF1 + 12:
ret "f" + (k.code - term.KeyF1 + 1)
end
ret "code " + k.code
end
func main:
each s in ["a", "\u001b[A", "\r", "\u001b", "\u0001", "\u001bx", "\u001bOQ", "\u001b[3~"]:
println describe(term.Decode(s))
end
m := term.DecodeMouse("\u001b[<0;12;5M")
println m.ok, m.button, m.col, m.row, m.pressed, m.motion
println term.KeyDelete, term.KeyTab, term.KeyBackspace, term.KeySpace, term.KeyEOF, term.KeyUnknown
println term.KeyDown, term.KeyRight, term.KeyLeft, term.KeyHome, term.KeyEnd, term.KeyPageUp, term.KeyPageDown, term.KeyInsert, term.KeyMouse, term.EscDelayMs
endMouseEvent
struct MouseEvent| Name | Type | Description |
|---|---|---|
button | int = 0 | The button number: zero left, 1 middle, 2 right. |
col | int = 0 | The column, from 1. |
row | int = 0 | The row, from 1. |
pressed | bool = false | The button was pressed, not released. |
motion | bool = false | The event is a movement. |
ok | bool = false | The sequence was read correctly. |
The example for this item is shown with the ones above: term-Decode.salam
TermState
struct TermStateRestore.| Name | Type | Description |
|---|---|---|
fd | int = 0 | The file descriptor of the terminal. |
saved | void* | The previous terminal settings on Unix. |
mode_in | int = 0 | The previous input mode on Windows. |
mode_out | int = 0 | The previous output mode on Windows. |
ok | bool = false | Whether the mode change succeeded. |
import term
func main:
if not term.IsTTY(term.StdinFd):
printerrln "this program has to run in a terminal"
ret 1
end
mut state := term.MakeRaw(term.StdinFd)
defer term.Restore(state)
term.Write("press a key (q to quit)\r\n")
until true:
if not term.KeyReady(500):
continue
end
k := term.ReadKey()
if k.code == term.KeyChar and k.ch == "q":
break
end
term.Write("code: " + k.code + "\r\n")
end
k2 := term.GetKey()
b := term.ReadByte()
password := term.ReadPassword("password: ")
println k2.code, b, password.len()
s2 := term.MakeCbreak(term.StdinFd)
mut s3 := s2
term.Restore(s3)
ret 0
endWinSize
struct WinSize| Name | Type | Description |
|---|---|---|
cols | int = 80 | The number of columns. |
rows | int = 24 | The number of rows. |
import term
func main:
w := term.Size()
println w.cols > 0, w.rows > 0, term.Cols() > 0, term.Rows() > 0
t := term.IsTerminal()
println t == term.IsTTY(term.StdoutFd)
println term.StdinFd, term.StdoutFd, term.StderrFd
term.SetColorMode(term.ColorAlways)
println term.SupportsColor()
c256 := term.Supports256Color()
ctrue := term.SupportsTrueColor()
println c256 or not c256, ctrue or not ctrue
endConstants and variables
Reset
const Reset: str = "[0m"import term
import str
func show(s: str): str:
ret str.Replace(s, term.Esc, "\\e")
end
func main:
term.SetColorMode(term.ColorAlways)
println show(term.Red("error")), show(term.Green("ok")), show(term.Yellow("warning"))
println show(term.Bold("important")), show(term.Underline("link")), show(term.Italic("quote"))
println show(term.Dim("a")), show(term.Blink("b")), show(term.Inverse("c")), show(term.Hidden("d")), show(term.Strike("e"))
println show(term.Black("a")), show(term.Blue("b")), show(term.Magenta("c")), show(term.Cyan("d")), show(term.White("e")), show(term.Gray("f"))
println show(term.BrightRed("a")), show(term.BrightGreen("b")), show(term.BrightYellow("c")), show(term.BrightBlue("d")), show(term.BrightMagenta("e")), show(term.BrightCyan("f")), show(term.BrightWhite("g"))
println show(term.OnRed("a")), show(term.OnGreen("b")), show(term.OnYellow("c")), show(term.OnBlue("d")), show(term.OnMagenta("e")), show(term.OnCyan("f")), show(term.OnWhite("g"))
println show(term.Color256("orange", 208)), show(term.OnColor256("x", 236))
println show(term.RGB("hello", 255, 92, 0)), show(term.OnRGB("x", 10, 10, 10))
println show(term.Style("x", term.StyleBold)), show(term.Paint("x", term.Sgr(term.FgRed)))
println show(term.SeqFg256(208)), show(term.SeqBg256(17)), show(term.SeqFgRGB(1, 2, 3)), show(term.SeqBgRGB(4, 5, 6))
println show(term.Reset), show(term.Csi)
term.SetColorMode(term.ColorNever)
println term.Red("no colour"), term.ColorMode() == term.ColorNever, term.ColorAuto
endStyle codes Style…
Style or Sgr.| Name | Value |
|---|---|
StyleBold | 1 |
StyleDim | 2 |
StyleItalic | 3 |
StyleUnderline | 4 |
StyleBlink | 5 |
StyleReverse | 7 |
StyleHidden | 8 |
StyleStrike | 9 |
The example for this item is shown with the ones above: term-Color.salam
Text colours Fg…
Bright to one of them gives the bright variant of the same colour, so 31 + 60 is bright red.| Name | Value |
|---|---|
FgBlack | 30 |
FgRed | 31 |
FgGreen | 32 |
FgYellow | 33 |
FgBlue | 34 |
FgMagenta | 35 |
FgCyan | 36 |
FgWhite | 37 |
FgDefault | 39 |
FgBright | 60 |
The example for this item is shown with the ones above: term-Color.salam
Background colours Bg…
| Name | Value |
|---|---|
BgBlack | 40 |
BgRed | 41 |
BgGreen | 42 |
BgYellow | 43 |
BgBlue | 44 |
BgMagenta | 45 |
BgCyan | 46 |
BgWhite | 47 |
BgDefault | 49 |
The example for this item is shown with the ones above: term-Color.salam
Key codes Key…
code field of a Key. For the function keys, KeyF1 is the code of F1 and F2 through F12 follow it in order.| Name | Value |
|---|---|
KeyUnknown | 0 |
KeyChar | 1 |
KeyEnter | 2 |
KeyTab | 3 |
KeyBackspace | 4 |
KeyEscape | 5 |
KeySpace | 6 |
KeyEOF | 7 |
KeyUp | 10 |
KeyDown | 11 |
KeyRight | 12 |
KeyLeft | 13 |
KeyHome | 14 |
KeyEnd | 15 |
KeyPageUp | 16 |
KeyPageDown | 17 |
KeyInsert | 18 |
KeyDelete | 19 |
KeyF1 | 30 |
KeyMouse | 50 |
The example for this item is shown with the ones above: term-Decode.salam
EscDelayMs
const EscDelayMs: i32 = 50The example for this item is shown with the ones above: term-Decode.salam
Standard file descriptors Std…
IsTTY and MakeRaw.| Name | Value |
|---|---|
StdinFd | 0 |
StdoutFd | 1 |
StderrFd | 2 |
The example for this item is shown with the ones above: term-Size.salam
Esc
const Esc: str = ""The example for this item is shown with the ones above: term-Color.salam
Csi
const Csi: str = "["[.The example for this item is shown with the ones above: term-Color.salam
Colour modes Color…
SetColorMode. In automatic mode, colour is only written when the output is a terminal.| Name | Value |
|---|---|
ColorAuto | 0 |
ColorAlways | 1 |
ColorNever | 2 |
The example for this item is shown with the ones above: term-Color.salam
Functions
SeqUp
func SeqUp(n: int): strn rows up.import term
import str
func show(s: str): str:
ret str.Replace(str.Replace(s, term.Esc, "\\e"), "\u0007", "\\a")
end
func main:
println show(term.SeqUp(2)), show(term.SeqDown(1)), show(term.SeqRight(3)), show(term.SeqLeft(3))
println show(term.SeqNextLine(1)), show(term.SeqPrevLine(1)), show(term.SeqColumn(10)), show(term.SeqMoveTo(5, 20)), show(term.SeqHome())
println show(term.SeqSaveCursor()), show(term.SeqRestoreCursor()), show(term.SeqHideCursor()), show(term.SeqShowCursor())
println show(term.SeqClearScreen()), show(term.SeqClearScrollback()), show(term.SeqClearLine())
println show(term.SeqClearToLineEnd()), show(term.SeqClearToLineStart()), show(term.SeqClearBelow()), show(term.SeqClearAbove()), show(term.SeqResetLine())
println show(term.SeqScrollUp(2)), show(term.SeqScrollDown(2)), show(term.SeqInsertLines(1)), show(term.SeqDeleteLines(1))
println show(term.SeqScrollRegion(2, 20)), show(term.SeqResetScrollRegion())
println show(term.SeqEnterAltScreen()), show(term.SeqExitAltScreen())
println show(term.SeqEnableMouse()), show(term.SeqEnableMouseMotion()), show(term.SeqDisableMouse())
println show(term.SeqTitle("my program"))
endSeqDown
func SeqDown(n: int): strn rows down.The example for this item is shown with the ones above: term-Seq.salam
SeqRight
func SeqRight(n: int): strn columns right.The example for this item is shown with the ones above: term-Seq.salam
SeqLeft
func SeqLeft(n: int): strn columns left.The example for this item is shown with the ones above: term-Seq.salam
SeqNextLine
func SeqNextLine(n: int): strnth next row.The example for this item is shown with the ones above: term-Seq.salam
SeqPrevLine
func SeqPrevLine(n: int): strnth previous row.The example for this item is shown with the ones above: term-Seq.salam
SeqColumn
func SeqColumn(col: int): strThe example for this item is shown with the ones above: term-Seq.salam
SeqMoveTo
func SeqMoveTo(row: int, col: int): strThe example for this item is shown with the ones above: term-Seq.salam
SeqHome
func SeqHome(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqSaveCursor
func SeqSaveCursor(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqRestoreCursor
func SeqRestoreCursor(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqHideCursor
func SeqHideCursor(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqShowCursor
func SeqShowCursor(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearScreen
func SeqClearScreen(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearScrollback
func SeqClearScrollback(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearLine
func SeqClearLine(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearToLineEnd
func SeqClearToLineEnd(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearToLineStart
func SeqClearToLineStart(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearBelow
func SeqClearBelow(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqClearAbove
func SeqClearAbove(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqResetLine
func SeqResetLine(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqScrollUp
func SeqScrollUp(n: int): strn rows.The example for this item is shown with the ones above: term-Seq.salam
SeqScrollDown
func SeqScrollDown(n: int): strn rows.The example for this item is shown with the ones above: term-Seq.salam
SeqInsertLines
func SeqInsertLines(n: int): strn empty lines at the cursor.The example for this item is shown with the ones above: term-Seq.salam
SeqDeleteLines
func SeqDeleteLines(n: int): strn lines from the cursor.The example for this item is shown with the ones above: term-Seq.salam
SeqScrollRegion
func SeqScrollRegion(top: int, bottom: int): strtop through bottom.The example for this item is shown with the ones above: term-Seq.salam
SeqResetScrollRegion
func SeqResetScrollRegion(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqEnterAltScreen
func SeqEnterAltScreen(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqExitAltScreen
func SeqExitAltScreen(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqEnableMouse
func SeqEnableMouse(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqEnableMouseMotion
func SeqEnableMouseMotion(): strThe example for this item is shown with the ones above: term-Seq.salam
SeqDisableMouse
func SeqDisableMouse(): strThe example for this item is shown with the ones above: term-Seq.salam
Up
func Up(n: int)n rows up.import term
func main:
term.EnableAnsi()
term.SetTitle("dashboard")
term.EnterAltScreen()
term.HideCursor()
term.ClearScreen()
term.Home()
term.MoveTo(2, 4)
term.Write(term.Bold("hello from the dashboard"))
term.SaveCursor()
term.Down(2)
term.Right(4)
term.Emit("status: good")
term.RestoreCursor()
term.Up(1)
term.Left(1)
term.NextLine(1)
term.PrevLine(1)
term.Column(1)
term.ClearLine()
term.ClearToLineEnd()
term.ClearBelow()
term.ResetLine()
term.SetScrollRegion(3, term.Rows() - 1)
term.ScrollUp(1)
term.ScrollDown(1)
term.InsertLines(1)
term.DeleteLines(1)
term.ResetScrollRegion()
term.EnableMouse()
term.DisableMouse()
term.Bell()
term.Flush()
term.ClearScrollback()
term.ShowCursor()
term.ExitAltScreen()
term.WriteErr("done\n")
w := term.Size()
println w.cols, w.rows, term.Cols()
endDown
func Down(n: int)n rows down.The example for this item is shown with the ones above: term-Screen.salam
Right
func Right(n: int)n columns right.The example for this item is shown with the ones above: term-Screen.salam
Left
func Left(n: int)n columns left.The example for this item is shown with the ones above: term-Screen.salam
NextLine
func NextLine(n: int)nth next row.The example for this item is shown with the ones above: term-Screen.salam
PrevLine
func PrevLine(n: int)nth previous row.The example for this item is shown with the ones above: term-Screen.salam
Column
func Column(col: int)The example for this item is shown with the ones above: term-Screen.salam
MoveTo
func MoveTo(row: int, col: int)The example for this item is shown with the ones above: term-Screen.salam
Home
func Home()The example for this item is shown with the ones above: term-Screen.salam
SaveCursor
func SaveCursor()The example for this item is shown with the ones above: term-Screen.salam
RestoreCursor
func RestoreCursor()The example for this item is shown with the ones above: term-Screen.salam
HideCursor
func HideCursor()The example for this item is shown with the ones above: term-Screen.salam
ShowCursor
func ShowCursor()The example for this item is shown with the ones above: term-Screen.salam
ClearScreen
func ClearScreen()The example for this item is shown with the ones above: term-Screen.salam
ClearScrollback
func ClearScrollback()The example for this item is shown with the ones above: term-Screen.salam
ClearLine
func ClearLine()The example for this item is shown with the ones above: term-Screen.salam
ClearToLineEnd
func ClearToLineEnd()The example for this item is shown with the ones above: term-Screen.salam
ClearBelow
func ClearBelow()The example for this item is shown with the ones above: term-Screen.salam
ResetLine
func ResetLine()The example for this item is shown with the ones above: term-Screen.salam
ScrollUp
func ScrollUp(n: int)n rows.The example for this item is shown with the ones above: term-Screen.salam
ScrollDown
func ScrollDown(n: int)n rows.The example for this item is shown with the ones above: term-Screen.salam
InsertLines
func InsertLines(n: int)n empty lines at the cursor.The example for this item is shown with the ones above: term-Screen.salam
DeleteLines
func DeleteLines(n: int)n lines from the cursor.The example for this item is shown with the ones above: term-Screen.salam
SetScrollRegion
func SetScrollRegion(top: int, bottom: int)top through bottom, to keep a header still, for instance.The example for this item is shown with the ones above: term-Screen.salam
ResetScrollRegion
func ResetScrollRegion()The example for this item is shown with the ones above: term-Screen.salam
EnterAltScreen
func EnterAltScreen()The example for this item is shown with the ones above: term-Screen.salam
ExitAltScreen
func ExitAltScreen()The example for this item is shown with the ones above: term-Screen.salam
EnableMouse
func EnableMouse()The example for this item is shown with the ones above: term-Screen.salam
DisableMouse
func DisableMouse()The example for this item is shown with the ones above: term-Screen.salam
Sgr
func Sgr(code: int): strThe example for this item is shown with the ones above: term-Color.salam
SeqFg256
func SeqFg256(n: int): strThe example for this item is shown with the ones above: term-Color.salam
SeqBg256
func SeqBg256(n: int): strThe example for this item is shown with the ones above: term-Color.salam
SeqFgRGB
func SeqFgRGB(r: int, g: int, b: int): strThe example for this item is shown with the ones above: term-Color.salam
SeqBgRGB
func SeqBgRGB(r: int, g: int, b: int): strThe example for this item is shown with the ones above: term-Color.salam
Paint
func Paint(s: str, prefix: str): strThe example for this item is shown with the ones above: term-Color.salam
Style
func Style(s: str, code: int): strThe example for this item is shown with the ones above: term-Color.salam
Bold
func Bold(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Dim
func Dim(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Italic
func Italic(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Underline
func Underline(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Blink
func Blink(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Inverse
func Inverse(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Hidden
func Hidden(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Strike
func Strike(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Black
func Black(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Red
func Red(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Green
func Green(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Yellow
func Yellow(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Blue
func Blue(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Magenta
func Magenta(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Cyan
func Cyan(s: str): strThe example for this item is shown with the ones above: term-Color.salam
White
func White(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Gray
func Gray(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightRed
func BrightRed(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightGreen
func BrightGreen(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightYellow
func BrightYellow(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightBlue
func BrightBlue(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightMagenta
func BrightMagenta(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightCyan
func BrightCyan(s: str): strThe example for this item is shown with the ones above: term-Color.salam
BrightWhite
func BrightWhite(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnRed
func OnRed(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnGreen
func OnGreen(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnYellow
func OnYellow(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnBlue
func OnBlue(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnMagenta
func OnMagenta(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnCyan
func OnCyan(s: str): strThe example for this item is shown with the ones above: term-Color.salam
OnWhite
func OnWhite(s: str): strThe example for this item is shown with the ones above: term-Color.salam
Color256
func Color256(s: str, n: int): strThe example for this item is shown with the ones above: term-Color.salam
OnColor256
func OnColor256(s: str, n: int): strThe example for this item is shown with the ones above: term-Color.salam
RGB
func RGB(s: str, r: int, g: int, b: int): strThe example for this item is shown with the ones above: term-Color.salam
OnRGB
func OnRGB(s: str, r: int, g: int, b: int): strThe example for this item is shown with the ones above: term-Color.salam
Strip
func Strip(s: str): strimport term
func main:
term.SetColorMode(term.ColorAlways)
colored := term.Green("hello")
println colored.len(), term.Width(colored), term.Strip(colored)
println term.Width("hello"), term.Width("日本"), term.Width("ab")
term.SetColorMode(term.ColorNever)
println "[" + term.Truncate("the Salam programming language", 10) + "]"
println "[" + term.PadRight("name", 8) + "]", "[" + term.PadLeft("42", 6) + "]", "[" + term.Center("ok", 6) + "]"
println term.FormatDuration(9500), term.FormatDuration(3721000)
println term.FormatBytes(512), term.FormatBytes(1536), term.FormatBytes(3221225472)
endWidth
func Width(s: str): intThe example for this item is shown with the ones above: term-Width.salam
Truncate
func Truncate(s: str, n: int): strn visible characters and keeps the colours intact.The example for this item is shown with the ones above: term-Width.salam
PadRight
func PadRight(s: str, n: int): strn; for laying out columns.The example for this item is shown with the ones above: term-Width.salam
PadLeft
func PadLeft(s: str, n: int): strn.The example for this item is shown with the ones above: term-Width.salam
Center
func Center(s: str, n: int): strn.The example for this item is shown with the ones above: term-Width.salam
FormatDuration
func FormatDuration(ms: i64): str9.5s or 1h 02m.The example for this item is shown with the ones above: term-Width.salam
FormatBytes
func FormatBytes(n: i64): str512 B or 1.5 KB; each unit is 1024 times the one before.The example for this item is shown with the ones above: term-Width.salam
NewBar
func NewBar(total: int, label: str): Bar█ and ░, otherwise # and -.The example for this item is shown with the ones above: term-Bar.salam
BarRender
func BarRender(b &: Bar): strThe example for this item is shown with the ones above: term-Bar.salam
BarDraw
func BarDraw(b &: Bar)import term
import time
func main:
mut b := term.NewBar(50, "processing")
repeat 50:
term.BarAdd(b, 1)
term.BarDraw(b)
time.Sleep(20)
end
term.BarFinish(b)
mut s := term.NewSpinner("connecting to the server")
repeat 20:
term.SpinnerTick(s)
time.Sleep(50)
end
term.SpinnerStop(s, "connected")
term.SpinnerFree(s)
endBarSet
func BarSet(b &: Bar, n: int)The example for this item is shown with the ones above: term-Bar.salam
BarAdd
func BarAdd(b &: Bar, delta: int)The example for this item is shown with the ones above: term-Bar.salam
BarFinish
func BarFinish(b &: Bar)The example for this item is shown with the ones above: term-Progress.salam
NewSpinner
func NewSpinner(label: str): Spinner| / - \ otherwise.The example for this item is shown with the ones above: term-Bar.salam
NewSpinnerFrames
func NewSpinnerFrames(label: str, frames: Vector<str>): SpinnerThe example for this item is shown with the ones above: term-Bar.salam
SpinnerFrame
func SpinnerFrame(s &: Spinner): strThe example for this item is shown with the ones above: term-Bar.salam
SpinnerTick
func SpinnerTick(s &: Spinner)The example for this item is shown with the ones above: term-Progress.salam
SpinnerStop
func SpinnerStop(s &: Spinner, final: str)The example for this item is shown with the ones above: term-Progress.salam
SpinnerFree
func SpinnerFree(s &: Spinner)The example for this item is shown with the ones above: term-Bar.salam
Decode
func Decode(seq: str): Key\e[A is the up key. It is also how you test a program without a real terminal.The example for this item is shown with the ones above: term-Decode.salam
DecodeMouse
func DecodeMouse(seq: str): MouseEvent\e[<0;12;5M.The example for this item is shown with the ones above: term-Decode.salam
ReadByte
func ReadByte(): intThe example for this item is shown with the ones above: term-ReadKey.salam
KeyReady
func KeyReady(timeout_ms: int): boolThe example for this item is shown with the ones above: term-ReadKey.salam
ReadKey
func ReadKey(): KeyThe example for this item is shown with the ones above: term-ReadKey.salam
GetKey
func GetKey(): KeyThe example for this item is shown with the ones above: term-ReadKey.salam
ReadPassword
func ReadPassword(prompt: str): strThe example for this item is shown with the ones above: term-ReadKey.salam
Write
func Write(s: str)The example for this item is shown with the ones above: term-Screen.salam
WriteErr
func WriteErr(s: str)The example for this item is shown with the ones above: term-Screen.salam
Flush
func Flush()The example for this item is shown with the ones above: term-Screen.salam
Emit
func Emit(s: str)The example for this item is shown with the ones above: term-Screen.salam
IsTTY
func IsTTY(fd: int): boolThe example for this item is shown with the ones above: term-Size.salam
IsTerminal
func IsTerminal(): boolThe example for this item is shown with the ones above: term-Size.salam
Size
func Size(): WinSizeThe example for this item is shown with the ones above: term-Size.salam
Cols
func Cols(): intThe example for this item is shown with the ones above: term-Size.salam
Rows
func Rows(): intThe example for this item is shown with the ones above: term-Size.salam
SetColorMode
func SetColorMode(mode: int)--color.The example for this item is shown with the ones above: term-Color.salam
ColorMode
func ColorMode(): intThe example for this item is shown with the ones above: term-Color.salam
SupportsColor
func SupportsColor(): boolNO_COLOR is set, when TERM=dumb, or when the output is not a terminal; CLICOLOR_FORCE turns colour on.The example for this item is shown with the ones above: term-Size.salam
Supports256Color
func Supports256Color(): boolTERM contains 256color or COLORTERM is set.The example for this item is shown with the ones above: term-Size.salam
SupportsTrueColor
func SupportsTrueColor(): boolCOLORTERM is truecolor or 24bit.The example for this item is shown with the ones above: term-Size.salam
EnableAnsi
func EnableAnsi(): boolThe example for this item is shown with the ones above: term-Screen.salam
MakeRaw
func MakeRaw(fd: int): TermStateThe example for this item is shown with the ones above: term-ReadKey.salam
MakeCbreak
func MakeCbreak(fd: int): TermStateThe example for this item is shown with the ones above: term-ReadKey.salam
Restore
func Restore(st &: TermState): booldefer right after the mode change.The example for this item is shown with the ones above: term-ReadKey.salam
Bell
func Bell()The example for this item is shown with the ones above: term-Screen.salam
SeqTitle
func SeqTitle(title: str): strThe example for this item is shown with the ones above: term-Seq.salam
SetTitle
func SetTitle(title: str)The example for this item is shown with the ones above: term-Screen.salam