Documentation ¶
Index ¶
- Variables
- func Sample()
- type Formatters
- type Helpers
- type Page
- func (p *Page) Add(rowContent string, altID string, dateTime string)
- func (p *Page) AddAction(validAction string)
- func (p *Page) AddBlankRow()
- func (p *Page) AddBreakRow()
- func (p *Page) AddColumns(columns ...string)
- func (p *Page) AddColumnsTitle(columns ...string)
- func (p *Page) AddFieldValuePair(key string, value string)
- func (p *Page) AddIntAction(validAction int)
- func (p *Page) AddMenuOption(id int, rowContent string, altID string, dateTime string)
- func (p *Page) AddParagraph(msg []string)
- func (p *Page) AddParagraphString(msg string)
- func (p *Page) Back()
- func (p *Page) BlockAction(action string)
- func (p *Page) BlockIntAction(action int)
- func (p *Page) Body()
- func (p *Page) Break(row int)
- func (p *Page) Clear()
- func (p *Page) ClearContent(row int)
- func (p *Page) Clearline(row int)
- func (p *Page) Display_Actions() (nextAction string)
- func (p *Page) Display_Confirmation(msg string) (bool, error)
- func (p *Page) Display_Input(minLen, maxLen int) (nextAction string, selected pageRow)
- func (p *Page) Dump(in ...string)
- func (p *Page) Error(err error, msg ...string)
- func (p *Page) Footer()
- func (p *Page) FormatRowOutput(msg string) string
- func (p *Page) Forward()
- func (p *Page) GetActions() []string
- func (p *Page) GetBlockedActions() []string
- func (p *Page) GetDebugRow(rowNo int) pageRow
- func (p *Page) GetHelp() []string
- func (p *Page) GetOptions(includeDefaults bool) string
- func (p *Page) GetRows() int
- func (p *Page) Header(msg string)
- func (p *Page) Help()
- func (p *Page) Hint(info string, msg ...string)
- func (p *Page) Info(info string, msg ...string)
- func (p *Page) Input(msg string, options string) string
- func (p *Page) InputHintInfo(msg string)
- func (p *Page) IsBlockedAction(action string) bool
- func (p *Page) PagingInfo(page, ofPages int)
- func (p *Page) ResetPrompt()
- func (p *Page) ResetSetHelp()
- func (p *Page) SetHelp(msg []string)
- func (p *Page) SetPrompt(prompt string)
- func (p *Page) SetTitle(title string)
- func (p *Page) ShowOptions()
- func (p *Page) Success(message string, msg ...string)
- func (p *Page) UnblockAction(action string)
- func (p *Page) ViewPort() ViewPort
- func (p *Page) Warning(warning string, msg ...string)
- type Styles
- type ViewPort
- func (t *ViewPort) Banner(msg string)
- func (t *ViewPort) Baud() int
- func (t *ViewPort) Blank()
- func (t *ViewPort) Break()
- func (t *ViewPort) Clear()
- func (t *ViewPort) ClearCurrentLine()
- func (t *ViewPort) Close()
- func (t *ViewPort) CurrentRow() int
- func (t *ViewPort) Delay() int
- func (t *ViewPort) DelayInSec() float64
- func (t *ViewPort) DelayIt()
- func (t *ViewPort) Error(err error, msg ...string)
- func (t *ViewPort) Format(msg string, text string) string
- func (t *ViewPort) Header(msg string)
- func (t *ViewPort) Height() int
- func (t *ViewPort) InfoMessage(msg string)
- func (t *ViewPort) Input(msg string, options string) (output string)
- func (t *ViewPort) InputError(err error, msg ...string)
- func (t *ViewPort) InputPagingInfo(page, ofPages int)
- func (t *ViewPort) NewPage(title string) *Page
- func (t *ViewPort) NoBaudRate() bool
- func (t *ViewPort) Paragraph(msg []string)
- func (t *ViewPort) Print(msg string)
- func (t *ViewPort) PrintIt(msg string)
- func (t *ViewPort) Println(msg string)
- func (t *ViewPort) ResetDelay()
- func (t *ViewPort) SError(err error, msg ...string) string
- func (t *ViewPort) SetBaud(baudRate int)
- func (t *ViewPort) SetDelayInMin(delayMs int)
- func (t *ViewPort) SetDelayInMs(delayMs int)
- func (t *ViewPort) SetDelayInSec(delayMs float64)
- func (t *ViewPort) SetTerminalSize(width, height int)
- func (t *ViewPort) Shout(msg string)
- func (t *ViewPort) Special(msg string)
- func (t *ViewPort) Spool(msg []byte)
- func (t *ViewPort) TerminalSize() (width, height int)
- func (t *ViewPort) Underline(msg string) string
- func (t *ViewPort) Wait()
- func (t *ViewPort) Width() int
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidAction = errs.ErrInvalidAction
)
Errors for exported functions
Functions ¶
Types ¶
type Formatters ¶
type Formatters struct { Bold func(s string) string SQuote func(s string) string PQuote func(s string) string DQuote func(s string) string QQuote func(s string) string Upcase func(s string) string Downcase func(s string) string HumanFromUnixDate func(unixTime int64) string HumanDiskSize func(size uint64) string Human func(a any) string DateString func() string TimeString func() string TrimRepeatingCharacters func(s string, c string) string DateTimeString func() string TimeAgo func(t string) string FormatDate func(t time.Time) string FormatDuration func(t time.Duration) string }
type Helpers ¶
type Helpers struct { RandomIP func() string RandomMAC func() string RandomPort func() int RandomFloat func(min int, max int) float64 ToInt func(s string) int ToString func(i int) string CoinToss func() bool IsInt func(i string) bool GetHostName func() string GetUsername func() string GetSytemInfo func() string RoundFloatToTwoDPS func(f float64) float64 IsActionIn func(action string, actionToCheck ...string) bool }
type Page ¶
type Page struct { ActivePageIndex int // The index of the active page. // contains filtered or unexported fields }
Page represents a page in a document or a user interface.
func (*Page) Add ¶
The `Add` function is used to add a new row of data to a page. It takes four parameters: `pageRowNumber`, `rowContent`, `altID`, and `dateTime`.
func (*Page) AddAction ¶
AddAction takes a validAction string as a parameter. The function adds the validAction to the list of available actions on the page.
func (*Page) AddBreakRow ¶
func (p *Page) AddBreakRow()
func (*Page) AddColumns ¶
func (*Page) AddColumnsTitle ¶
AddColumnsTitle adds a ruler to the page, separating the columns
func (*Page) AddFieldValuePair ¶
AddFieldValuePair adds a field value pair to the page
AddFieldValuePair takes two strings as arguments, where the first string represents the field name and the second string represents the field value. The function adds a row to the page with the field name on the left and the field value on the right, separated by a colon.
Example:
page.AddFieldValuePair("Field Name", "Field Value")
func (*Page) AddIntAction ¶
AddIntAction adds an action to the page with the given integer value
func (*Page) AddMenuOption ¶
The `Add` function is used to add a new row of data to a page. It takes four parameters: `pageRowNumber`, `rowContent`, `altID`, and `dateTime`.
func (*Page) AddParagraph ¶
func (*Page) AddParagraphString ¶
func (*Page) Back ¶
func (p *Page) Back()
Back moves to the previous page. If the current page is the first page, it returns an error.
func (*Page) BlockAction ¶
func (*Page) BlockIntAction ¶
func (*Page) ClearContent ¶
func (*Page) Display_Actions ¶
func (*Page) Display_Input ¶
func (*Page) FormatRowOutput ¶
func (*Page) Forward ¶
func (p *Page) Forward()
Forward moves to the next page. If the current page is the last page, it returns an error.
func (*Page) GetActions ¶
func (*Page) GetBlockedActions ¶
func (*Page) GetDebugRow ¶
GetDebugRow returns the pageRow at the specified index.
This function is used for debugging purposes.
func (*Page) GetOptions ¶
func (*Page) Header ¶
The `Header` function is a method of the `Crt` struct. It is responsible for printing a banner message to the console.
func (*Page) Input ¶
The `Input` function is a method of the `Crt` struct. It is used to display a prompt for the user for input on the terminal.
func (*Page) InputHintInfo ¶
func (*Page) IsBlockedAction ¶
func (*Page) PagingInfo ¶
func (*Page) ResetPrompt ¶
func (p *Page) ResetPrompt()
ResetPrompt resets the prompt to the default value
func (*Page) ResetSetHelp ¶
func (p *Page) ResetSetHelp()
func (*Page) ShowOptions ¶
func (p *Page) ShowOptions()
func (*Page) UnblockAction ¶
type Styles ¶
type Styles struct { Reset string RED string GREEN string YELLOW string BLUE string MAGENTA string CYAN string GREY string GRAY string WHITE string BOLD string UNDERLINE string ClearLine string Red func(s string) string Green func(s string) string Yellow func(s string) string Blue func(s string) string Magenta func(s string) string Cyan func(s string) string Grey func(s string) string Gray func(s string) string White func(s string) string Bold func(s string) string Underline func(s string) string }
type ViewPort ¶
type ViewPort struct { Helpers *Helpers // Helper functions Formatters *Formatters // Formatter functions Styles *Styles // Colour functions // contains filtered or unexported fields }
The ViewPort type represents a terminal screen with properties such as whether it is a terminal, its width and height, and whether it is the first row. @property {bool} isTerminal - A boolean value indicating whether the CRT (Cathode Ray Tube) is a terminal or not. If it is a terminal, it means that it is a device used for input and output of data to and from a computer. If it is not a terminal, it means that it is not used @property {int} width - The width property represents the number of characters that can be displayed horizontally on the terminal screen. @property {int} height - The `height` property represents the number of rows in the terminal or console window. @property {bool} firstRow - The `firstRow` property is a boolean value that indicates whether the current row is the first row of the terminal screen.
func New ¶
func New() ViewPort
The function `New` initializes a new `Crt` struct with information about the terminal size and whether it is a terminal or not.
func NewWithSize ¶
func (*ViewPort) Banner ¶
The `Banner` function is a method of the `Crt` struct. It is responsible for printing a banner message to the console.
func (*ViewPort) Blank ¶
func (t *ViewPort) Blank()
The `Blank()` function is used to print a blank line on the terminal. It calls the `Format()` method of the `Crt` struct to format an empty string with the normal character (`chNormal`). Then, it prints the formatted string using `fmt.Println()`.
func (*ViewPort) Break ¶
func (t *ViewPort) Break()
The `Break()` function is used to print a line break on the terminal. It calls the `row()` method of the `Crt` struct to get the formatted line break string, and then it prints the string using `fmt.Println()`. This creates a visual separation between different sections or blocks of text on the terminal.
func (*ViewPort) ClearCurrentLine ¶
func (t *ViewPort) ClearCurrentLine()
ClearCurrentLine clears the current line in the terminal
func (*ViewPort) Close ¶
func (t *ViewPort) Close()
The `Close()` function is a method of the `Crt` struct. It is used to print a closing line on the terminal. It calls the `row()` method of the `Crt` struct to get the formatted closing line string, and then it prints the string using `fmt.Println()`. This creates a visual separation between different sections or blocks of text on the terminal.
func (*ViewPort) CurrentRow ¶
Get the current row of the terminal
func (*ViewPort) Delay ¶
Get Delay The above code is defining a method called "Delay" for a struct type "Crt". This method returns an integer value, which is the value of the "delay" field of the struct.
func (*ViewPort) DelayInSec ¶
Get Delay in seconds The above code is defining a method called "DelayInSec" for a struct type "Crt". This method returns the delay value of the "Crt" struct in seconds. The delay value is divided by 1000 to convert it from milliseconds to seconds and then returned as a float64.
func (*ViewPort) DelayIt ¶
func (t *ViewPort) DelayIt()
The above code is defining a method called "DelayIt" for a struct type "Crt". This method takes no arguments and has no return value.
func (*ViewPort) Error ¶
The `Error` function is a method of the `Crt` struct. It takes two parameters: `msg` of type string and `err` of type error.
func (*ViewPort) Format ¶
The `Format` function is a method of the `Crt` struct. It takes two parameters: `in` of type string and `t` of type string.
func (*ViewPort) Header ¶
The `Header` function is a method of the `Crt` struct. It is responsible for printing a banner message to the console.
func (*ViewPort) InfoMessage ¶
func (*ViewPort) Input ¶
The `Input` function is a method of the `Crt` struct. It is used to display a prompt for the user for input on the terminal.
func (*ViewPort) InputError ¶
The `InputError` function is a method of the `Crt` struct. It takes a `msg` parameter of type string and prints an error message to the terminal. It uses the `Format` method of the `Crt` struct to format the message with the bold red color and the special character (`chSpecial`). Then, it prints the formatted string using `fmt.Println()`.
func (*ViewPort) InputPagingInfo ¶
The `InputPagingInfo` function is a method of the `Crt` struct. It is used to print information about the current page and total number of pages to the terminal.
Parameters: page: The current page number. ofPages: The total number of pages.
Returns: None.
func (*ViewPort) NewPage ¶
The NewPage function creates a new page with a truncated title and initializes other properties.
func (*ViewPort) NoBaudRate ¶
NoBaudRate returns true if the CRT's baud rate is set to col, false otherwise.
func (*ViewPort) Paragraph ¶
Paragraph formats a list of strings as paragraphs, wrapping lines as needed to fit within the terminal width.
func (*ViewPort) Print ¶
The `Print` function is a method of the `Crt` struct. It takes a `msg` parameter of type string and prints it to the terminal. It uses the `Format` method of the `Crt` struct to format the message with the normal character (`chNormal`). Then, it prints the formatted string using `fmt.Println()`.
func (*ViewPort) PrintIt ¶
PrintIt prints a message to the terminal.
If the CRT's baud rate is set to col, the function prints the message without applying any delays or formatting. If the baud rate is non-zero, the function prints the message character by character, with a delay of 1000000 microseconds (1 millisecond) between each character. The function also prints the current row number at the end of the message.
The function returns without printing a new line. To print a new line, use the Println method.
func (*ViewPort) Println ¶
Println prints a message to the terminal and adds a new line.
If the CRT's baud rate is set to col, the function prints the message without applying any delays or formatting. If the baud rate is non-zero, the function prints the message character by character, with a delay of 1000000 microseconds (1 millisecond) between each character. The function also prints the current row number at the end of the message.
The function returns without printing a new line. To print a new line, use the Println method.
func (*ViewPort) ResetDelay ¶
func (t *ViewPort) ResetDelay()
The above code is defining a method called "ResetDelay" for a struct type "Crt". This method is a member of the "Crt" struct and has a receiver of type "*Crt". Inside the method, it calls another method called "defaultDelay" on the receiver "T".
func (*ViewPort) SetBaud ¶
SetBaud sets the baud rate for the CRT.
If the specified baud rate is not supported, an error is returned and the CRT's baud rate is reset to the default value.
func (*ViewPort) SetDelayInMin ¶
The `SetDelayInMin` function is a method of the `Crt` struct. It takes an `int` parameter `delay` and sets the `delay` property of the `Crt` struct to the value of `delay` multiplied by 60000. This function is used to set the delay in milliseconds that should be applied before printing each character to the terminal, but it takes the delay in minutes instead of milliseconds.
func (*ViewPort) SetDelayInMs ¶
The `SetDelayInMs` function is a method of the `Crt` struct. It takes an `int` parameter `delay` and sets the `delay` property of the `Crt` struct to the value of `delay`. This property represents the delay in milliseconds that should be applied before printing each character to the terminal.
func (*ViewPort) SetDelayInSec ¶
The `SetDelayInSec` function is a method of the `Crt` struct. It takes a parameter `delay` of type `interface{}`.
func (*ViewPort) SetTerminalSize ¶
The `SetTerminalSize` function is a method of the `Crt` struct. It takes two parameters, `width` and `height`, which represent the desired width and height of the terminal screen.
func (*ViewPort) Shout ¶
The `Shout` function is a method of the `Crt` struct. It takes a `msg` parameter of type string and prints a formatted message to the terminal.
func (*ViewPort) Special ¶
The `Special` function is a method of the `Crt` struct. It takes a `msg` parameter of type string and prints it to the terminal using the `fmt.Println()` function. The message is formatted with the special character (`chSpecial`) using the `Format` method of the `Crt` struct. This function is used to print a special message or highlight certain text on the terminal.
func (*ViewPort) Spool ¶
Spool prints the contents of a byte slice to the terminal.
The byte slice is split into lines by the t.SymNewline character (\n). For each line, the function determines whether the line is empty. If the line is not empty, it is prepended with " " (two spaces) and printed to the terminal.
If the byte slice is empty, the function returns without printing anything.
The function also prints a blank line after all lines have been printed.
func (*ViewPort) TerminalSize ¶
The `TerminalSize` function is a method of the `Crt` struct. It returns the width and height of the terminal screen. It retrieves the values of the `width` and `height` properties of the `Crt` struct and returns them as integers.
func (*ViewPort) Underline ¶
The `Underline` method of the `Crt` struct is used to format a string with an underline. It takes a `msg` parameter of type string and returns a formatted string with the `msg` surrounded by the underline escape characters (`underline` and `reset`). The `fmt.Sprintf` function is used to concatenate the escape characters and the `msg` string. This method is used to create an underlined text effect when printing to the terminal.