Overview | Index by: file name | procedure name | procedure call | annotation

cli.tcl Annotations

Created from source/cli.tcl
Procedures for dealing with CLI user interactions. This file covers the following functions: * Command line processing * Execution of commands * help via "?" * command completion with TAB * history * readline-style editing * and other editing conveniences We don't perform command and variable substitutions during command line editing. Substitutions are performed however when command is executed (either as a MirkoConf command or Tcl script). We introduce this limitation because in order to provide TAB expansions and ? feedback we need to know in advance the exact string of the command. With command substitution we would have to execute the subcommands before we can know what the command string really is. Variable substitutions, on the other hand, could trigger variable traces and change the state of the interpreter as a result of '?' or TAB. In effect, '?' & TAB cannot be used with MirkoConf commands that have subcommands or variables. Simply the will report unrecognized strings. However, if the user enters the command without this help facilities and executes it afterwards, substituions will be performed as normal and the result will be parsed again (first the subcommands and then going up to the root command). If the substituted command gives a legal MikroConf or Tcl command, it will be executed as normal. The result of these commands will take the place of [ ] as expected. Also notice that command line help facilities, like '?' and TAB can only be used when entering a MikroConf command. Neither incomplete Tcl commands, nor incomplete variable names are considered. @assume VT100/ANSI/xterm/linux terminal or compatible. References: http://foldoc.org/foldoc.cgi?ASCII+character+table http://www.termsys.demon.co.uk/vtansi.htm

Procedure Summary
appendHistory { cmdline }
          Add a command to the history buffer.
browseHistory { direction }
          Handle history action: go to the previous entry, next, first or
clear { }
          Clears screen, leaving the cursor at the last row, first
clearline { }
          Removes any character printed before the position of the cursor, and send the cursor at the beginning of the line (like
cmdline_insert { str pos }
          Insert a string into the specified position in CMDLINE, and update CMDLINE_CURSOR to point at the end of the inserted
event_not_found { }
          A helper procedure to display the "event not found" message and reset
execute_cmd { cmdline }
          Execute the provided command.
getinfo { name }
          Get formatted information about the system.
goto { row {col 1} }
          Set the cursor to (row, col) coordinates.
gotocol { col }
          Set the cursor to col; same row.
handleAction { action }
          Command line editing action
handleCompletion { }
          Implements TAB expansion and display of available options for command names and argument
handleControls { }
          Handle control characters (single byte characters with special meaning) @assume char variable exists on uplevel
handleEscapes { }
          Handle escape sequences: Sequences prepended by escape that have special meaning @assume keybuffer variable exists on uplevel
handleHelp { }
          Displays in-line help for MikroConf commands & arguments.
handleSpecial { char }
          Handle special sequences which start with Ctrl + ^ combination @assume keybuffer variable exists on uplevel
makePrompt { }
          Render the prompt from the prompt specifications set in PROMPT Shared Global Variable.
notEscaped { }
          We check if a '?' that is pressed is preceeded by '\', in which case it loses its special
pos2index { lst pos }
          Returns the index in the list of the item that the string position $pos points to.
prompt { type }
          This procedure prints the existing command text and command prompt.
readbuf { txt }
          Return and remove the first character from a FILO string.
ready { }
          The main procedure to listen and handle command line input.
remove_spaces { cmdline cursor }
          Remove unecessary spaces between words on the command line.

Procedure Detail

appendHistory

proc appendHistory { cmdline }
Add a command to the history buffer. The command itself might actually be already in the history, in a different position. No two same consecutive entries can be present.
Parameters:
cmdline - the command line to be stored in the history buffer
Defined in:
cli.tcl, line 1016

browseHistory

proc browseHistory { direction }
Handle history action: go to the previous entry, next, first or last
Parameters:
direction - action specification: one of "-back", "-forth", "-newest", "-oldest"
Defined in:
cli.tcl, line 962

clear

proc clear {  }
Clears screen, leaving the cursor at the last row, first column.
Defined in:
cli.tcl, line 133

clearline

proc clearline {  }
Removes any character printed before the position of the cursor, and send the cursor at the beginning of the line (like CTLR^U).
Defined in:
cli.tcl, line 141

cmdline_insert

proc cmdline_insert { str pos }
Insert a string into the specified position in CMDLINE, and update CMDLINE_CURSOR to point at the end of the inserted string
Parameters:
str - The string to insert
pos - The position to insert the string
Defined in:
cli.tcl, line 1120

event_not_found

proc event_not_found {  }
A helper procedure to display the "event not found" message and reset prompt.
Defined in:
cli.tcl, line 1132

execute_cmd

proc execute_cmd { cmdline }
Execute the provided command. Suspend stdin fileevent, and restore correct settings afterwards (using an execution trace).
Parameters:
cmdline - The command string to execute.
Returns:
The result and options of the evaluated command.
Defined in:
cli.tcl, line 1060

getinfo

proc getinfo { name }
Get formatted information about the system. @assume Parent scope has arrays Uname & Sysinfo defined, with expected contents.
Parameters:
name - A name that identifies the info to be requested
Returns:
The formatted info
Defined in:
cli.tcl, line 153

goto

proc goto { row {col 1} }
Set the cursor to (row, col) coordinates. Numbering starts from zero for both dimentions. @assume row and col values are sane with respect to maximum terminal height and width at the time of invocation (e.g. 80x24)
Parameters:
row - Send the cursor to absolute row $row; e.g from 0 to 24, for an 24 rows terminal.
col - Send the cursor to absolute col $col, or beginning of line if not specified; e.g from 0 to 79, for an 80 columns terminal.
Defined in:
cli.tcl, line 107

gotocol

proc gotocol { col }
Set the cursor to col; same row. @assume col value is sane with respect to maximum terminal width at the time of invocation (e.g. 80)
Parameters:
col - The column to place the cursor at. e.g from 0 to 79, for an 80 columns terminal.
Defined in:
cli.tcl, line 123

handleAction

proc handleAction { action }
Command line editing action handlers
Parameters:
action - the action to which we should respond
Defined in:
cli.tcl, line 403

handleCompletion

proc handleCompletion {  }
Implements TAB expansion and display of available options for command names and argument values.
Defined in:
cli.tcl, line 677

handleControls

proc handleControls {  }
Handle control characters (single byte characters with special meaning) @assume char variable exists on uplevel 1
Defined in:
cli.tcl, line 606

handleEscapes

proc handleEscapes {  }
Handle escape sequences: Sequences prepended by escape that have special meaning @assume keybuffer variable exists on uplevel 2
Defined in:
cli.tcl, line 540

handleHelp

proc handleHelp {  }
Displays in-line help for MikroConf commands & arguments. Help is not provided for anything else.
Defined in:
cli.tcl, line 877

handleSpecial

proc handleSpecial { char }
Handle special sequences which start with Ctrl + ^ combination @assume keybuffer variable exists on uplevel 2
Parameters:
The - special character.
Defined in:
cli.tcl, line 589

makePrompt

proc makePrompt {  }
Render the prompt from the prompt specifications set in PROMPT Shared Global Variable. Prompt is updated with every command execution (pressed Enter to execute command).
Defined in:
cli.tcl, line 228

notEscaped

proc notEscaped {  }
We check if a '?' that is pressed is preceeded by '\', in which case it loses its special function
Defined in:
cli.tcl, line 1044

pos2index

proc pos2index { lst pos }
Returns the index in the list of the item that the string position $pos points to. The space between list items is considered part of the item on the left. If pos points somewhere after the list, (including the space on the right of the last word) then the llength of the list + 1 is returned. @assume $lst is a list
Parameters:
lst - A list
pos - A number pointing in the list as a string. zero-based.
Returns:
The list index; zero-based.
Defined in:
cli.tcl, line 855

prompt

proc prompt { type }
This procedure prints the existing command text and command prompt. It can handle multiline commands, splitting lines as necessary to fit in the columns of the current terminal. Also It places the cursor at the right place. If the user merely moved the cursor, then the command string is not re-printed, otherwise (no matter how small the change is) the whole command will be re-printed (including the prompt - possibly different).
Parameters:
type - Type of prompt: "new" (prompt) or "redraw" (the existing).
Defined in:
cli.tcl, line 269

readbuf

proc readbuf { txt }
Return and remove the first character from a FILO string. @assume The variable named $txt exists in the context of the caller.
Parameters:
txt - The buffer to read from, passed by name for performance reasons.
Returns:
The first character of the string; if empty, the empty list is returned.
Defined in:
cli.tcl, line 94

ready

proc ready {  }
The main procedure to listen and handle command line input. It hooks on session's STDIN channel with a fileevent.
Defined in:
cli.tcl, line 1144

remove_spaces

proc remove_spaces { cmdline cursor }
Remove unecessary spaces between words on the command line. They need to be removed, because in pos2index we treat the command line string as a list, and spaces should not appear at first place. This function only operates when the command line is a Tcl list (regardless of any extra spaces and newlines). If it is not a list, it means that some brace is open, and we have to wait until it becomes a list again. Of course spaces within braces are fine, cause they are part of a single list item. Note that if the command contains backslashes, they are not substituted, meaning that an escaped newline, for example, will be treated as if it was a command name. @assume $cmdline is a well-formed Tcl command & list.
Parameters:
cmdline - Command line.
cursor - Cursor position in the command line
Returns:
A list: @error
Defined in:
cli.tcl, line 781

Overview | Index by: file name | procedure name | procedure call | annotation
File generated 2010-03-13 at 22:28.