Documentation ¶
Index ¶
- Constants
- Variables
- func AddCmd(cmds []CommandOption)
- func SetPromt(s string)
- func Start(errorHandler func(error) error)
- type CommandLine
- func (cmdline *CommandLine) AddCmd(cmds []CommandOption)
- func (cmdline *CommandLine) Cell() []termbox.Cell
- func (cmdline *CommandLine) Cursor() (X, Y int)
- func (cmdline *CommandLine) DeleteRuneBackward()
- func (cmdline *CommandLine) DeleteRuneForward()
- func (cmdline *CommandLine) DeleteTheRestOfTheLine()
- func (cmdline *CommandLine) Draw(x, y int)
- func (cmdline *CommandLine) Execute() error
- func (cmdline *CommandLine) HasCmd(cmd string) bool
- func (cmdline *CommandLine) InsertRune(r rune)
- func (cmdline *CommandLine) KeyCompletion()
- func (cmdline *CommandLine) MoveCursorOneRuneBackward()
- func (cmdline *CommandLine) MoveCursorOneRuneForward()
- func (cmdline *CommandLine) MoveCursorTo(boffset int)
- func (cmdline *CommandLine) MoveCursorToBeginningOfTheLine()
- func (cmdline *CommandLine) MoveCursorToEndOfTheLine()
- func (cmdline *CommandLine) MoveDown()
- func (cmdline *CommandLine) MoveUp()
- func (cmdline *CommandLine) PrintDesc()
- func (cmdline *CommandLine) RuneBeforeCursor() (rune, int)
- func (cmdline *CommandLine) RuneUnderCursor() (rune, int)
- func (cmdline *CommandLine) SetPromt(b []byte)
- type CommandOption
- type StdBuffer
- func (stdbuf *StdBuffer) Draw(x, y, termW, termH int)
- func (stdbuf *StdBuffer) Fd() *os.File
- func (stdbuf *StdBuffer) PutByte(b []byte, refresh func())
- func (stdbuf *StdBuffer) PutCell(c []termbox.Cell, endWithNewline bool, refresh func())
- func (stdbuf *StdBuffer) PutString(s string, refresh func())
Constants ¶
const ( // TabLength 4 or 8? That's a question. TabLength = 4 // NumOfLines is the Maximum lines of the stdbuffer. NumOfLines = 1000 // NumOfHistory is the Maximum lines of recored user input. NumOfHistory = 1000 )
Variables ¶
var ( ExitIcli = errors.New("Exit the main icli loop.") // Function return this err to exit the mainloop CmdNotFound = errors.New("Command not found.") // Command not found. PrintDesc = errors.New("Print Description.") // Print description. )
Errors
Functions ¶
func AddCmd ¶
func AddCmd(cmds []CommandOption)
AddCmd adds cmd to icli, options of the same name will overwrites by the latest one.
Types ¶
type CommandLine ¶
type CommandLine struct {
// contains filtered or unexported fields
}
CommandLine handles the user inputs.
func (*CommandLine) AddCmd ¶
func (cmdline *CommandLine) AddCmd(cmds []CommandOption)
AddCmd a Command Option.
func (*CommandLine) Cell ¶
func (cmdline *CommandLine) Cell() []termbox.Cell
Cell return the CommandLine buffer on the screen.
func (*CommandLine) Cursor ¶
func (cmdline *CommandLine) Cursor() (X, Y int)
Cursor reports the cursor postion.
func (*CommandLine) DeleteRuneBackward ¶
func (cmdline *CommandLine) DeleteRuneBackward()
DeleteRuneBackward handles backspace key.
func (*CommandLine) DeleteRuneForward ¶
func (cmdline *CommandLine) DeleteRuneForward()
DeleteRuneForward handles del key.
func (*CommandLine) DeleteTheRestOfTheLine ¶
func (cmdline *CommandLine) DeleteTheRestOfTheLine()
DeleteTheRestOfTheLine like the name, handles CtrlK.
func (*CommandLine) Draw ¶
func (cmdline *CommandLine) Draw(x, y int)
Draw itcmdline on point(x, y). \t should not exist, but here is a good excise for tab process.
func (*CommandLine) HasCmd ¶
func (cmdline *CommandLine) HasCmd(cmd string) bool
HasCmd checks whether the Command Option exists.
func (*CommandLine) InsertRune ¶
func (cmdline *CommandLine) InsertRune(r rune)
InsertRune to the postion of cursor.
func (*CommandLine) KeyCompletion ¶
func (cmdline *CommandLine) KeyCompletion()
KeyCompletion based on existing Command Options.
func (*CommandLine) MoveCursorOneRuneBackward ¶
func (cmdline *CommandLine) MoveCursorOneRuneBackward()
MoveCursorOneRuneBackward moves the cursor one rune backward.
func (*CommandLine) MoveCursorOneRuneForward ¶
func (cmdline *CommandLine) MoveCursorOneRuneForward()
MoveCursorOneRuneForward moves the cursor one rune forward.
func (*CommandLine) MoveCursorTo ¶
func (cmdline *CommandLine) MoveCursorTo(boffset int)
MoveCursorTo the postion of byte.
func (*CommandLine) MoveCursorToBeginningOfTheLine ¶
func (cmdline *CommandLine) MoveCursorToBeginningOfTheLine()
MoveCursorToBeginningOfTheLine handles home key.
func (*CommandLine) MoveCursorToEndOfTheLine ¶
func (cmdline *CommandLine) MoveCursorToEndOfTheLine()
MoveCursorToEndOfTheLine handles end key.
func (*CommandLine) MoveDown ¶
func (cmdline *CommandLine) MoveDown()
MoveDown handles key arrow down.
func (*CommandLine) PrintDesc ¶
func (cmdline *CommandLine) PrintDesc()
PrintDesc prints the description of all options.
func (*CommandLine) RuneBeforeCursor ¶
func (cmdline *CommandLine) RuneBeforeCursor() (rune, int)
RuneBeforeCursor returns the rune before the cursor.
func (*CommandLine) RuneUnderCursor ¶
func (cmdline *CommandLine) RuneUnderCursor() (rune, int)
RuneUnderCursor returns the current rune under cursor.
func (*CommandLine) SetPromt ¶
func (cmdline *CommandLine) SetPromt(b []byte)
SetPromt sets the prefix of user command input line.
type CommandOption ¶
CommandOption is an option like "ls" or "cd". Stdout is redirected to screen buffer. Function can call fmt.Print directly
type StdBuffer ¶
type StdBuffer struct {
// contains filtered or unexported fields
}
StdBuffer is a standard buffer to handle stdout or other input to redirect it onto the screen.