# Stdin Package Description

## usage

    package require stdin
    Stdin_Start

## Description

The stdin package provides a text console for entering Tcl commands to tclsh while allowing it to be event driven. To access the stdin package, include the code:

`package provide stdin`

in your script, and start the tcl event loop (and the stdin console) by entering:

`Stdin_Start`

that takes as an optional argument, a command prompt string. In addition to providing normal command entry, stdin provides a rudimentary command history, loosely inspired from csh. Any command that begins with (!) is looked up in the history list, allowing a previous command to be re-executed. The general for of a history command is:

!match-expression/replace-expression/replacement-string
- match-expression is a regular expression that is used to find the most recent command in the history list to re-executed. By default, this expression is anchored at the beginning of the line, so the command:
  `!s`
  will re-execute the most recent command that begins with "s". The command:
  `!s.*q`
  will re-execute the most recent command that begins with "s" and also contains the letter "q". The re-issued command is inserted onto the history list.
- The sequence:
  `/replace-expression/replacement-string`
  is optional, and permits part of a previous command to be re-issued with modifications. The replace-expression is a regular expression that matches some portion of the command string, which is then replaced by replacement-string before the command is re-issued. When a substitution succeeds, both the original command matched and the modified version are displayed on the console.

As an example, if the command:

`source ../lib/something.tcl`

is the most recent command on the history list beginning with "s", then:

`!s/g/g2/`

would run the command:

`source ../lib/something2.tcl`

## Variables

State for the stdin package is stored in the global array: Stdin.

## Author

Stephen Uhler