The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tk::Terminal - Running system commands in a Tk::Text widget.

SYNOPSIS

 require Tk::Terminal;
 my $text= $window->Terminal(@options)->pack;

DESCRIPTION

Inherits Tk::TextANSIColor.

This module works as a modest command shell. You can enter a command and go into dialog with the program you are running, if the program does not buffer it's output.

It is in no way a replacement for the standard command shell on your system. It handles ANSI colored output, but only colours.

This module will install but not work on Windows.

OPTIONS

If you change any of the color options while running, you should call configureTags to see the changes.

Switch -buffering

Default value: 1 (boolean flag)

Used when a process is running.

If buffering is set you have the opportunity to edit your response line before sending it to the process with return. If buffering is not set every key stroke will be sent to the process immediately.

Switch -dircall

Callback, called when you change directory.

Name errorbg
Class Errorbg
Switch -errorbg

Default value: #FF0000 (red)

Background color for text tagged as 'error'.

Name errorfg
Class Errorfg
Switch -errorfg

Default value: #FFFF00 (yellow)

Foreground color for text tagged as 'error'.

Switch -historyfile

File where the hisory commands given is stored. If you specify this option the file will be loaded at startup and kept up to date.

Switch -historymax

Default value: 64

Maximum size of the command history. If it is full, the oldest entry is removed when one is added.

Name linkbg
Class Linkbg
Switch -linkbg

Default value: undef

Background color for text tagged as 'link'.

Switch -linkcall

Callback to execute when the user clicks a link. It gets the link text as parameter.

Name linkfg
Class Linkfg
Switch -linkfg

Default value: #0000FF (blue)

Foreground color for text tagged as 'link'.

Switch -linkreg

Default value: undef

Regular expression used to search for links in the text. Searching for links is done every time a process finishes.

Name messagebg
Class Messagebg
Switch -messagebg

Default value: undef

Background color for text tagged as 'message'.

Name messagefg
Class Messagefg
Switch -messagefg

Default value: #FFFF00 (blue)

Foreground color for text tagged as 'message'.

Name tbackground
Class Tbackground
Switch -tbackground

Default value: #143B57 (some deep marine blue with a touch of spinache)

Background color for the Tk::Terminal widget.

Name tfont
Class Tfont
Switch -tfont

Default value: Mono 12

Font for the Tk::Terminal widget.

Name tforeground
Class Tforeground
Switch -tforeground

Default value: #F0F0F0 (almost white)

Background color for the Tk::Terminal widget.

Switch -usercommands

User defined commands. You can specify a hash with keys that are the commands and standard Tk callbacks as their value.

 $term->configure(-usercommands => {
    exit => ['destroy', $app],
 });
Switch -workdir

Default value: current working directory.

Acting working directory for commands launched. Shows up in the prompt.

KEYBOARD BINDINGS

Most of the keyboard bindings you expect with a command shell apply. Besides that we have:

CTRL+U

Toggles buffering.

CTRL+W

Performs a clear.

CTRL+Z

Kills the currently running process.

INTERNAL COMMANDS

Commands that are handled internally and not launched as a process:

cd

Change your working directory. The -dircall callback is called when you use this command.

clear

Performs a clear.

METHODS

clear

Kills the current process if one is running and deletes all text.

configureTags

Configures all tags for this package. Call this if you make changes to any of them.

launch($command)

Launches a process with $command as command string.

processKill

Kills the currently running process. Does nothing if no process runs.

send($message)

Sends $message to the input of the process. Does nothing if no process is running.

write($text)

Appends $text to the end.

writeError($text)

Appends $text to the end and tags it as error.

writeMessage($text)

Appends $text to the end and tags it as message.

LICENSE

Same as Perl.

AUTHOR

Hans Jeuken (hanje at cpan dot org)

BUGS AND CAVEATS

If you find any bugs, please contact the author.