Komodo's interactive shell implements individual language shells within Komodo. Shells are used to directly communicate with the specified language interpreter.
Statements, expressions, and code fragments can be entered independent of program files. The shell can be used as a stand-alone interactive tool or as a shell that interacts from within a debugging session.
When the interactive shell is started as a stand-alone tool, use the shell to help test modules and experiment with new languages or programs. Other uses for a stand-alone interactive shell include:
The interactive shell supports history recall, AutoComplete and CallTips (Tcl only), and custom colors and fonts.
When the interactive shell is started from within a debug session, use the shell to access all functions and code being debugged. When the shell is closed from within a debug session, continue the debug process where you left off. Depending on the language used, changes made in the shell remain in effect for the duration of the debug session. Other uses for an interactive shell within a debug session include:
The interactive shell supports history recall, AutoComplete and CallTips (Tcl only), and custom colors and fonts.
Each Komodo interactive shell is associated with a corresponding interpreter and is thus language-specific. Each time a command or multi-line string is entered into the Shell tab, that code is sent to the corresponding interpreter for evaluation. The interpreter evaluates the command, and then returns output and error text.
Use the Preferences dialog box to specify the default language to use within an interactive shell. Other shells can still be accessed via Tools|Interactive Shell.
To set the default shell preference:
The interactive shell can be opened as a stand-alone tool or as a shell inside of a debugging session.
To start the shell as a stand-alone tool:
The interactive shell opens in a Shell tab in the Bottom Pane beside the Command Output and Breakpoint tabs.
To start the shell from within a debug session:
View debugging and code inspection functions by clicking the "Collapse/Expand Pane" button at the left side of the Bottom Pane. This splits the shell into a left and right pane. The left pane performs debugging functions while the right pane contains the interactive shell.
Open multiple interactive shells to interact with various code snippets from a single language or use many shells to simultaneously explore a different language in each shell.
The Tcl interactive shell displays AutoComplete and CallTips when recognized code and commands are entered into the shell. Use autocomplete and calltips to limit the amount of typing in each session. To select a suggested item, press Enter. Use the up and down arrow keys to scroll through the various options on the screen. To cancel or ignore the suggested autocomplete or calltip, press Esc.
Komodo can also detect when further data is required at the command prompt. When insufficient programming data is entered at the prompt, Komodo displays a language-dependent "more" prompt. This prompt indicates that the language interpreter requires more information before the code can run. Once enough data is entered, Komodo executes the code and the standard language-dependent input prompt returns.
The Shell tab displays commands, variables, error messages, and all language syntax in the same scheme as specified in Edit|Preferences|Fonts and Colors. See Customizing Fonts and Colors for more information.
The code history consists of the ordered, numbered sets of commands entered in the lifetime of the shell, including interleaved output and error messages. Use the up and down arrow keys to cycle through the history of all entered commands. When viewing a multi-line command or function, use the 'Enter' key to select the desired function and then use the arrow keys to cycle through the multiple lines within that function.
To stop an interactive shell session and close the Shell tab, click the X button located in the upper-right corner of the Shell tab. To stop the interactive shell and keep the Shell tab open, click the square button, or use the associated key binding.
To clear the shell buffer, click the Clear Buffer button. There is no limit to buffer size; unless it is manually cleared, the buffer will continue to increment until the interactive shell session is closed. Manually clearing the buffer only removes the command history and command results, and has no effect on the buffer state (such as changes to the working directory, etc).
The Python shell prompt is a group of three angle brackets
>>>. A ... prompt is displayed if
Komodo determines that more information is required before the code can
execute. A '%' prompt is displayed when input
from stdin
is required (for example, in a Python shell, enter
help()
). No prompt is displayed when program output is sent to
the screen. Code errors are displayed in italics. When a Python interactive
shell session begins, a welcome message is printed stating a version number
and copyright notice. The first prompt is printed as follows:
Python 2.2.2 (#37, Nov 25 2002, 13:15:27) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. >>>
The following example shows a series of Python statements with resulting output:
>>> # Comment: my hello world test >>> print "Hello World" Hello World >>> x=12**2 >>> x/2 72 >>>
To start a Python shell from within a debug session, click the Interact button, located in the upper-right corner of the Debug tab. Starting a shell within a debug session enables Interact Mode. In Interact Mode, view debugging and code inspection functions by clicking the "Collapse/Expand Pane" button at the left side of the Bottom Pane. This splits the shell into a left and right pane. The left pane performs debugging functions while the right pane contains the interactive shell. In Interact Mode, debugging functionality (for example, Run, Step In, Step Out) is not available. To return to the debugger, click the Interact button again to exit Interact Mode.
The Tcl interactive shell supports the tclsh interpreter. The
Tcl shell prompt is a percent character %. A
> prompt is displayed if Komodo determines
that more information is required before the code executes. A
% prompt is displayed when input
from stdin
is required. No prompt is displayed when
program output is sent to the screen. Code errors are displayed
in italics. The following examples show how input, output, and
errors are displayed in the Tcl shell:
%puts "Hello World" Hello World %
With an error:
%put "hello world" invalid command name "put" %puts "hello world" hello world %
To start a Tcl shell from within a debug session, click the Interact (>>)button, located in the upper-right corner of the Debug tab. Starting a shell within a debug session enables Interact Mode. In Interact Mode, view debugging and code inspection functions by clicking the "Collapse/Expand Pane" button at the left side of the Bottom Pane. This splits the shell into a left and right pane. The left pane performs debugging functions while the right pane contains the interactive shell. In Interact Mode, debugging functionality (for example, Run, Step In, Step Out) is not available. To return to the debugger, click the Interact button again to exit Interact Mode.
The Perl interactive shell prompt is a percent character %. A > prompt is displayed if Komodo determines that more information is required before the code executes. No prompt is displayed when program output is sent to the screen. Code errors are displayed in italics. The following examples show how input, output, and errors are displayed in the Perl shell:
%print "Hello World! \n"; Hello World! %
With an error:
%prin "Hello World! \n"; syntax error %print "Hello World!!! \n"; Hello World!!! %
Using Strings, Function Definitions, and Multiple Line Input
Use the Perl shell to enter function definitions, long
strings, and specify if
and while
blocks interactively. The Perl shell also handles multiple line
input delimited by braces, curly braces, single quotes, and
double quotes. The following examples demonstrate this usage.
Example: Using single quotes "''" to enter multiple line input.
% $b = 'abc > def > ghi > jkl' abc def ghi jkl %
Example: Using curly braces "{}" to define a function and enter multiple line input.
% sub foo { > my $arg = shift; > my $arg2 = shift; > return $arg + $arg2; > } % foo(10, 12) 22 %
Example: Using braces to enter a multiple line string.
% $name = 'Bob' Bob % print qq(<html><head><title> > Browser Window Caption Text > </title></head><body bg="white"> > <p>Welcome to my fine web site, $name > </body> > </html>) <html><head><title> Browser Window Caption Text </title></head><body bg="white"> <p>Welcome to my fine web site, Bob </body> </html> %
Example: Using a backslash to continue a statement.
% print 'abc ', 'def ', \ > 'ghi' abc def ghi %
Example: Using a backslash to continue a statement.
% $first_long_variable_name = 3 3 % $second_long_variable_name = 4 4 % $third_long_variable_name_to_store_result = $first_long_variable_name + \ > $second_long_variable_name 7
Example: Using a braced construct
% foreach $var (sort keys %ENV) { > print "$var = $ENV{$var}\n"; > } ALLUSERSPROFILE = C:\Documents and Settings\All Users COMMONPROGRAMFILES = C:\Program Files\Common Files COMSPEC = C:\winnt\system32\cmd.exe LESS = --quit-at-eof --quit-if-one-screen --ignore-case --status-column --hilite-unread --no-init MSDEVDIR = C:\PROGRA~1\MICROS~3\Common\msdev98 MSVCDIR = C:\PROGRA~1\MICROS~3\VC98 NETSAMPLEPATH = C:\PROGRA~1\MICROS~1.NET\FRAMEW~1\Samples OS = Windows_NT OS2LIBPATH = C:\winnt\system32\os2\dll; PATH = C:\PROGRA~1\MICROS~3\Common\msdev98\BIN; PROCESSOR_ARCHITECTURE = x86 PROCESSOR_IDENTIFIER = x86 Family 6 Model 7 Stepping 3, GenuineIntel PROCESSOR_LEVEL = 6 PROCESSOR_REVISION = 0703 PROGRAMFILES = C:\Program Files PROMPT = $P$G SYSTEMDRIVE = C: SYSTEMROOT = C:\winnt TEMP = C:\DOCUME~1\toto\LOCALS~1\Temp TMP = C:\DOCUME~1\toto\LOCALS~1\Temp USERNAME = toto USERPROFILE = C:\Documents and Settings\toto WINDIR = C:\winnt
To start a Perl shell from within a debug session, click the Interact button, located in the upper-right corner of the Debug tab. Starting a shell within a debug session enables Interact Mode. In Interact Mode, view debugging and code inspection functions by clicking the "Collapse/Expand Pane" button at the left side of the Bottom Pane. This splits the shell into a left and right pane. The left pane performs debugging functions while the right pane contains the interactive shell. In Interact Mode, debugging functionality (for example, Run, Step In, Step Out) is not available. To return to the debugger, click the Interact button again to exit Interact Mode.
The JavaScript interactive shell is currently only available from within a JavaScript debugging session. To start an interactive shell from within a JavaScript debug session, click the Interact (>>) button.
In Interact Mode, the left section of the bottom pane shows the variable viewer tabs while the right section contains the interactive shell. Debugger stepping functionality (e.g. Run, Step In, Step Out) is not available.
In this mode, you can enter expressions, define new local and global variables, create functions, and modify the DOM of the HTML document loaded in the browser.
Example: Entering a simple expression
> 2 + 2 4 >
Example: Setting variables
> a1 = "testing 123" testing 123 > var a2 = "check check" >
When variables are declared without a var
statement, they are echoed in the shell and appear in the
globals variable tab on the left. When the
var
statement is used, they are not echoed by the
shell and appear in the locals tab.
Example: Interacting with the browser
> alert(a1 + ", " + a2)
This will cause the browser to spawn an alert pop-up. To change the Title of the page you are viewing in the browser:
> document.title = "My new title" My new title >
Example: Defining a function
> function my_alert(s) { * alert("Testing: " + s); * } > my_alert(document.title) >
The "*" character in place of the ">" in the left margin indicates a multi-line statement. The interactive shell usually doesn't need any special escaping to let you enter a multi-line statement, but you can put a backslash at the end of a line to explicitly specify line continuation. For example:
> var a2 = 1 \ * + 2 + \ * 3 > a2 6
While debugging, click Interact to stop the interactive shell, then Go/Continue to run the JavaScript event from the browser to completion. Once the debugger finishes, Komodo and the JavaScript interpreter are still connected, so you can resume your interactive shell.
Once you've established a link between Komodo and Firefox, you can use the interactive shell at any time by switching to Komodo and clicking the Interact (>>) button. Press Interact button to re-enter the interactive shell. Variables defined in the previous session should still be present.
You're free to keep using the browser, however, the shell does not "follow" the browser as you move from window to window.
When using the interactive shell at a true breakpoint, you can use XPath and DOM functions to quickly find and manipulate parts of the document. In the non-debugging interactive shell, the shell has access to a subset of the DOM, such as the title.
Subscribe to http://blogs.activestate.com/ericp/ for future postings on DHTML tricks in the interactive shell.
Starting a Ruby shell session displays the interpreter version and platform information. The standard shell prompt for entering statements is a single ">" symbol:
Ruby 1.8.6 [powerpc-darwin8.10.0] >
When more information is required for execution (e.g. within any flow control construct) or when requesting user input, a "*" is displayed. No prompt is displayed when program output is sent to the screen.
> mylist = [] [] > for x in (0..3) * puts "Enter a value:" * mylist[x] = gets.chomp! * end Enter a value: *
Code errors are displayed in italics.
> mylist[wrong]
undefined local variable or method `wrong' for main:Object
To start a Ruby shell from within a debug session, click the Interact button, located in the upper-right corner of the Debug tab. Starting a shell within a debug session enables Interact Mode. In Interact Mode, view debugging and code inspection functions by clicking the "Collapse/Expand Pane" button at the left side of the Bottom Pane. This splits the shell into a left and right pane. The left pane performs debugging functions while the right pane contains the interactive shell. In Interact Mode, debugging functionality (for example, Run, Step In, Step Out) is not available. To return to the debugger, click the Interact button again to exit Interact Mode.