3. Pypsi Builtin Plugins¶
Pypsi ships with several useful plugins that enhance the shell.
3.1. Block Commands¶
-
class
pypsi.plugins.block.BlockPlugin(end_cmd='end', preprocess=20, **kwargs)[source]¶ Bases:
pypsi.core.PluginProvide the ability to record multiple statements for future processing and execution. By itself, the
BlockPlugindoesn’t do anything. Rather, newBlockCommandare developed that leverage this plugin’s preprocessor to record multiple statements from the user. Blocks are terminated the user inputs the value ofend_cmd, at which point, the activeBlockCommandis retrieved andBlockCommand.end_block()is called.Parameters: end_cmd (str) – the statement that will terminate the active block -
begin_block(shell, cmd)[source]¶ Begin recording a new block.
Parameters: - shell (pypsi.shell.Shell) – the active shell
- cmd (BlockCommand) – the active block command
-
end_block(shell)[source]¶ End the block. Calls the active block command’s
BlockCommand.end_block()method.
-
-
class
pypsi.plugins.block.BlockCommand(prompt='> ', **kwargs)[source]¶ Bases:
pypsi.core.CommandBase class for any block commands that accept multiple statements from the user. Block commands allow the user to input several individual statement lines and postpone processing and execution until a later time. For example, the
pypsi.commands.macro.MacroCommandis a block command that allows the user to record several statements and then execute them when the macro is called.-
begin_block(shell)[source]¶ Begin a block command and record subsequent statements to the block buffer.
-
end_block(shell, lines)[source]¶ Called when a block has ended recording. Subclasses must implement this method.
Parameters: - shell (pypsi.shell.Shell) – the active shell
- lines (list) – the list of unprocessed statements (
str)
-
3.2. Escape Sequence Processors¶
-
class
pypsi.plugins.hexcode.HexCodePlugin(preprocess=5, **kwargs)[source]¶ Bases:
pypsi.core.PluginAllows the user to input hex code escape sequences. Hex code sequences will be converted to a raw UTF8 character after processing. Escape sequences are in the format of:
\xDD, whereDDis a 2-digit hex value. This plugin can be used, for example, to print ANSI escape codes to the screen. To print the color red, for example, the user would input the sequence\x1b[1;31m.
-
class
pypsi.plugins.multiline.MultilinePlugin(prompt='> ', preprocess=30, **kwargs)[source]¶ Bases:
pypsi.core.PluginProvides the ability to input and execute multiline statements. Input lines that end in the escape character
\can be continued on the subsequent input line. This allows for the user to type the following and produces the the statement:echo this is a multiline \statement=>
echo this is a multiline statementParameters: prompt (str) – the prompt when recording a multiline statement
3.3. Shell History¶
-
class
pypsi.plugins.history.HistoryPlugin(history_cmd='history', **kwargs)[source]¶ Bases:
pypsi.core.PluginProvides access to the shell’s statement history.
-
class
pypsi.plugins.history.HistoryCommand(name='history', brief='manage shell history', topic='shell', **kwargs)[source]¶ Bases:
pypsi.core.CommandInteract with and manage the shell’s history.
-
class
pypsi.plugins.history.History[source]¶ Bases:
objectWraps the
readlinemodule. Provides the following abilities:- Accessing and manipulating history items via
__getitem__(),__setitem__(),__delitem__(), and__iter__(). Indexes must beintand negative indexes are handled and automatically normalized before passing them toreadline.__getitem__()also supports slicing, which also normalizes negative indexes. - Appending new history items via
append(). - Clearing all history items via
clear().
Methods that access an index (or slice) will raise an
IndexErrorif the index is invalid or out of range of the history.- Accessing and manipulating history items via
3.4. Variables¶
-
class
pypsi.plugins.variable.VariablePlugin(var_cmd='var', prefix='$', locals=None, env=True, topic='shell', case_sensitive=True, preprocess=10, postprocess=90, **kwargs)[source]¶ Bases:
pypsi.core.PluginProvides variable management and substitution in user input.
Parameters: -
setup(shell)[source]¶ Register the
VariableCommandand add thevarsattribute (pypsi.namespace.ScopedNamespace) to the shell’s context.
-
-
class
pypsi.plugins.variable.VariableCommand(name='var', brief='manage local variables', topic='shell', **kwargs)[source]¶ Bases:
pypsi.core.CommandManage variables.
-
class
pypsi.plugins.variable.ManagedVariable(getter, setter=None)[source]¶ Bases:
objectRepresents a variable that is managed by the shell. Managed variables have get and set hooks that allow for input validation or read-only enforcement. Each variable needs a
getter, which is called to retrieve the value, and possibly asetter, which is called to set the value. If the setter isNone, the variable is read-only. The setter must accept two arguments when it is called: the activeShellinstance, and thestrvalue.Parameters:
3.5. Cmd¶
-
class
pypsi.plugins.cmd.CmdPlugin(cmd_args=0, **kwargs)[source]¶ Bases:
pypsi.core.PluginWraps existing
cmd-based shell commands to be pypsi compatible. This plugin is designed to ease the transition from thecmdmodule and isn’t intended to be used in production. Tab completion is not supported forcmdcommands.Parameters: cmd_args (int) – determines how the command arguments are passed to the wrapped command (see CmdArgsListandCmdArgsString)
-
class
pypsi.plugins.cmd.CommandFunction(func, completer=None, cmd_args=0, **kwargs)[source]¶ Bases:
pypsi.core.CommandWraps a function as a pypsi command.
Parameters:
-
pypsi.plugins.cmd.CmdArgsList= 0¶ Keep command arguments as a list of strings
-
pypsi.plugins.cmd.CmdArgsString= 1¶ Turn the list of arguments to a single string