console

package
v0.0.0-...-dc8a8ef Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTtyAvailable

func IsTtyAvailable() bool

IsTtyAvailable attempts to open a tty connection, returning true if successful.

console.IsTtyAvailable()  			// Check if tty can be opened
result := console.IsTtyAvailable()  // Capture if tty is available

Types

type AppleScriptConsole

type AppleScriptConsole struct {
}

AppleScriptConsole is a MacOS gui interface for receiving input.

func NewAppleScriptReader

func NewAppleScriptReader() AppleScriptConsole

NewAppleScriptReader creates an interface that reads input using AppleScript.

ascript := consolerw.NewAppleScriptReader()  // New AppleScript interface

func (AppleScriptConsole) Option

func (r AppleScriptConsole) Option(message string, prompt string, options []string) (int, error)

Option displays a desktop dialog box prompting for a selection.

consolerw.Option("Message text", "Action", []string{"hello", "world"})  // Display a dialog box with hello and world as options.
selection, err := consolerw.Option("My dialog")              			// Capture the selected index for the dialog box

Parameters:

message string     // Required - The message explaining the choices
prompt string      // Required - The prompt for input
options string     // Required - The options given in the dialog box

func (AppleScriptConsole) Print

func (r AppleScriptConsole) Print(prompt string) error

Print writes the message a desktop notification.

err := consolerw.Print("List of Items")        // Display text as notification

Parameters:

message string      // Required - The message to be written to desktop notification.

func (AppleScriptConsole) Println

func (r AppleScriptConsole) Println(prompt string) error

Println writes the message a desktop notification.

err := consolerw.Print("List of Items")        // Display text as notification

Parameters:

message string      // Required - The message to be written to desktop notification.

func (AppleScriptConsole) ReadInt

func (r AppleScriptConsole) ReadInt(prompt string) (int, error)

ReadInt triggers a desktop dialog box with a integer prompt.

index, err := consolerw.ReadInt("Selection:")   // Prompt for integer value

Parameters:

prompt string      // Required - The prompt for input.

func (AppleScriptConsole) ReadLine

func (r AppleScriptConsole) ReadLine(prompt string) (string, error)

ReadLine triggers a desktop dialog box with a text prompt.

text, err := consolerw.ReadLine("Selection:")   // Prompt for text

Parameters:

prompt string      // Required - The prompt for input.

func (AppleScriptConsole) ReadPassword

func (r AppleScriptConsole) ReadPassword(prompt string) (string, error)

ReadPassword triggers a desktop dialog box for receiving password input.

passwd, err := consolerw.ReadPassword("Selection:")   // Prompt for password value

Parameters:

prompt string      // Required - The prompt for input.

type ConsoleReader

type ConsoleReader interface {
	ReadLine(prompt string) (string, error)
	ReadPassword(prompt string) (string, error)
	ReadInt(prompt string) (int, error)
	Option(header string, prompt string, options []string) (int, error)
	Print(message string) error
	Println(message string) error
}

ConsoleReader is an interface for receiving user input.

type DefaultConsoleReader

type DefaultConsoleReader struct {
	Tty bool
}

DefaultConsoleReader is a console interface for emitting and receiving output.

func NewConsoleReader

func NewConsoleReader(tty bool) DefaultConsoleReader

NewConsoleReader creates a that reads from the console.

reader := consolerw.NewConsoleReader(false)        // Write output to stderr
reader := consolerw.NewConsoleReader(true)        // Write output to tty device

Parameters:

tty bool      // Required - True if output should be written to tty; false otherwise.

func (DefaultConsoleReader) Option

func (r DefaultConsoleReader) Option(header string, prompt string, options []string) (int, error)

Option displays a list of options, prompting the console for a selection.

consolerw.Option("Message text", "Action", []string{"hello", "world"})  // Display a list of hello and world, zero indexed for selection.

Parameters:

header string     // Required - The header of the list selection
prompt string      // Required - The prompt for input
options string     // Required - The options given in the list

func (DefaultConsoleReader) Print

func (r DefaultConsoleReader) Print(message string) error

Print writes the message to the output channel.

err := consolerw.Print("List of Items")        // Display text to the console.

Parameters:

message string      // Required - The message to be written to console.

func (DefaultConsoleReader) Println

func (r DefaultConsoleReader) Println(message string) error

Println writes the message to the output channel with a newline.

err := consolerw.Println("List of Items")        // Display text to the console.

Parameters:

message string      // Required - The message to be written to console.

func (DefaultConsoleReader) ReadInt

func (r DefaultConsoleReader) ReadInt(prompt string) (int, error)

ReadInt prompts the console for an integer input with a prompt.

index, err := consolerw.ReadInt("Selection:")        // Prompt for selection

Parameters:

prompt string      // Required - The prompt for integer.

func (DefaultConsoleReader) ReadLine

func (r DefaultConsoleReader) ReadLine(prompt string) (string, error)

ReadLine prompts the console for input with a prompt.

text, err := consolerw.ReadLine("Selection:")        // Prompt for selection

Parameters:

prompt string      // Required - The prompt for input.

func (DefaultConsoleReader) ReadPassword

func (r DefaultConsoleReader) ReadPassword(prompt string) (string, error)

ReadPassword prompts the console for a password input with a prompt.

passw, err := consolerw.ReadPassword("Password:")        // Prompt for password

Parameters:

prompt string      // Required - The prompt for input.

Jump to

Keyboard shortcuts

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