Class ::tycho::TclShell


Inherits: ::tycho::Edit - Source File - Contents: itk_options - destructor - public methods - protected methods - protected variables
This class defines a shell widget that accepts Tcl and Itcl commands from the keyboard and executes them. It tracks the command history, and provides both menu commands and emacs-like key bindings for scrolling through and editing that command history. It will also, on request, put the command history or a transcript of a session into a text editor. The -text option, inherited from the base class, specifies a welcome message. For example,
::tycho::view TclShell [list -text "A fresh Tcl Shell\n"]

.


Itk_options

-stdout 0
If the value of this option is non-zero, then this shell captures output produced by the Tcl "puts" command, emulating standard output. If more than one shell has set this option, then the most recently created such shell is the one that captures the output. Also, for interaction with Ptolemy, such a TclShell redefines the "monitorPtcl" command to display Ptcl commands in its window. The destructor will restore the "puts" and "monitorPtcl" to their original form if the shell window is destroyed. Note that destroying this widget is the only way to restore the puts command. Configuring the option to 0 after it is constructed is ignored.
-answerforeground black
Define the color of the result display.
-promptforeground black
Define the color of the prompt.

Destructor

destructor
If the console window is a master console window, then the user is queried about exiting the program. If the user declines to exit, the destruction is cancelled by triggering an error. Note that this fails to catch the case where the Tk "destroy windowname" is used instead of "delete object objectname". In the former case, the window is destroyed whatever the user responds to the query. In this case, the Tcl command "puts" will be restored to its original form, but the Ptcl command "monitorPtcl" will no longer work. Thus, a master console window should not be destroyed with the Tk "destroy windowname" command.

Public constructs

Public Methods

adjustInsertionCursor {point {}}
Adjust the insertion cursor so it stays on the current line. If the second argument, point is given, it must be a legal position on the current line; if not given, it defaults to the position after the prompt. If the insertion cursor is before the current line, then is it moved to point; if the cursor is on the current line but before the end of the prompt, it is moved to the end of the prompt; otherwise, it is not moved. This method should be called anytime Tk's default text bindings may move the cursor.
backChar
Move back one space, but not into the prompt.
backCommand dist
Move back a given number of commands in the history and display that previous command on the current line. A negative argument will move forward.
backSpace
If there is a selection, delete it and return. Otherwise, delete one character (backwards), but not into the prompt.
backWord
Move back one word, but not into the prompt.
clearHistory
Clear the recorded history.
deleteRange first last
Delete the specified range of text, but not before the prompt. Record the deletion for undoing. If either the beginning or the end of the range align with the contents of lastUndo, then the deleted range is appended to the undo buffer rather than replacing it. The deleted string is also copied to the clipboard. The arguments are indices in any form accepted by the Tk text widget.
displayHistory
Open a new window that displays the entire command history.
displayOutput args
Print like the Tcl "puts" command, but in the console window. The arguments are an optional -nonewline option, an optional fileid, and a required string to print. If the optional fileid argument is given, then the original Tcl "puts" is used to write to the file.
displayResult result
Display on the console the result passed as an argument. The printPrompt method should be called after to ensure that a prompt is printed. If the -nonewline option is given, then do not print a newline.
help
Open a help window.
indicateReadOnly bool
Indicate in the status bar and in the menus whether modifications are allowed on the buffer. This is redefined from the base class because the Format menu has been removed and the base class method refers to it. Also, we don't want to put a file status to the status bar, since this is bogus for a console window.
killLine
Kill the current command, saving it to the clipboard.
killToEndOfLine
Kill to the end of the current command, rather than just to the end of the current line, as in the base class.
markModified
Do nothing.
paste
Paste the selection from the clipboard and evaluate it as a Tcl command if it ends in a carriage return.
printPrompt {flag {}}
Print one of two possible prompts. If the optional argument is the string INCOMPLETE, then a prompt for incomplete commands is generated. Otherwise, the standard prompt is generated.
processReturn
Execute the current command.
recordCommand cmd
Display a command and add it to the history, but do not execute it. A prompt is also displayed after the command.
saveAsFile filename
Save a complete record of the transcript in the console window, including return values and prompts, to the specified file.
scroll direction
Scroll forward (or backwards) by one page. If direction is +1, scroll forward one page. If it is -1, scroll backward one page. Two lines of overlap are left between the old and new pages. Unlike the base class method, the insertion point is left in its original position.
search
Open or raise a search window. Unlike the base class method, the resulting search window will not allow replacing text. It behaves like the search window of a read-only text widget.
seeFragment point
Go to the specified point in the console, adjusting the view to see the point. The point can be specified in any of three ways:
   {line linenumber}
   {range startindex endindex}
   regexp
In the first two forms, the point is a list beginning with the keyword "line" or "range". If the point has neither of these forms, then it is interpreted as a regular expression, and the first match of the regular expression is taken to be the specified point. In all cases, the background color of the matching text is changed temporarily. Notice that this will not be visible if the "range" form is used and the two indices are equal. As a side effect, the selection (if there is one) is cleared.
stuff
Insert text from the selection and possibly execute a command. If the text ends in a Return, then execute it as a Tcl command.

Protected constructs

Protected Methods

evalCommand com
Evaluate a command in the global context and return the result. The main reason for this method is to ensure that a prompt gets printed on the console window even if an error occurs.
evalTextEntry
Evaluate a command that has been typed into the text widget, if it is a complete command, print its returned value, and print a prompt. If the command is not complete, append it to the partialCommand string and print a special prompt.
insertWithTags text args
Insert text into the console text widget and apply one or more tags to that text. The first argument is the text to insert (it is inserted at the "insert" mark). The second and subsequent arguments give one or more tags to apply to text. If there are no such arguments, then all tags are removed from the text.
preference mode args
Access the preferences associated with this widget. This method overrides the default method in ::tycho::TWidget to access the "console" preferences.

Protected Variables

commandList
The command history.
historypos 0
How far back we've scrolled through the command history.

Index of classes



Author: Edward A. Lee
Version: @(#)TclShell.itcl 1.20 12/14/96
Copyright: (c) 1995-1996 The Regents of the University of California.