terminal

package
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 22

Documentation

Index

Constants

View Source
const InputColumn int = StartColumn + 2
View Source
const StartColumn int = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type ViewPort

type ViewPort struct {
	Helpers    *hlpr.Helpers    // Helper functions
	Formatters *hlpr.Formatters // Formatter functions
	Styles     *hlpr.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 NewWithSize(width, height int) ViewPort

func (*ViewPort) Banner

func (t *ViewPort) Banner(msg string)

The `Banner` function is a method of the `Crt` struct. It is responsible for printing a banner message to the console.

func (*ViewPort) Baud

func (t *ViewPort) Baud() int

Baud returns the current baud rate of the CRT.

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) Clear

func (t *ViewPort) Clear()

clear the terminal screen

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

func (t *ViewPort) CurrentRow() int

Get the current row of the terminal

func (*ViewPort) Delay

func (t *ViewPort) Delay() int

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

func (t *ViewPort) DelayInSec() float64

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

func (t *ViewPort) Error(err error, msg ...string)

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

func (t *ViewPort) Format(msg string, text string) string

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

func (t *ViewPort) Header(msg string)

The `Header` function is a method of the `Crt` struct. It is responsible for printing a banner message to the console.

func (*ViewPort) Height

func (t *ViewPort) Height() int

Get the height of the terminal

func (*ViewPort) InfoMessage

func (t *ViewPort) InfoMessage(msg string)

func (*ViewPort) Input

func (t *ViewPort) Input(msg string, options string) (output string)

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

func (t *ViewPort) InputError(err error, msg ...string)

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

func (t *ViewPort) InputPagingInfo(page, ofPages int)

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) NoBaudRate

func (t *ViewPort) NoBaudRate() bool

NoBaudRate returns true if the CRT's baud rate is set to col, false otherwise.

func (*ViewPort) Paragraph

func (t *ViewPort) Paragraph(msg []string)

Paragraph formats a list of strings as paragraphs, wrapping lines as needed to fit within the terminal width.

func (*ViewPort) Print

func (t *ViewPort) Print(msg string)

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

func (t *ViewPort) PrintIt(msg string)

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

func (t *ViewPort) Println(msg string)

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) SError

func (t *ViewPort) SError(err error, msg ...string) string

func (*ViewPort) SetBaud

func (t *ViewPort) SetBaud(baudRate int)

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

func (t *ViewPort) SetDelayInMin(delayMs int)

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

func (t *ViewPort) SetDelayInMs(delayMs int)

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

func (t *ViewPort) SetDelayInSec(delayMs float64)

The `SetDelayInSec` function is a method of the `Crt` struct. It takes a parameter `delay` of type `interface{}`.

func (*ViewPort) SetTerminalSize

func (t *ViewPort) SetTerminalSize(width, height int)

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

func (t *ViewPort) Shout(msg string)

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

func (t *ViewPort) Special(msg string)

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

func (t *ViewPort) Spool(msg []byte)

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

func (t *ViewPort) TerminalSize() (width, height int)

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

func (t *ViewPort) Underline(msg string) string

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.

func (*ViewPort) Wait

func (t *ViewPort) Wait()

func (*ViewPort) Width

func (t *ViewPort) Width() int

Get the width of the terminal

Jump to

Keyboard shortcuts

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