Base Shell Class (xonsh.base_shell)

The base class for xonsh shell

class xonsh.base_shell.BaseShell(execer, ctx, **kwargs)[source]

The xonsh shell.


Returns the current color map.


Returns an iterable of all available style names.

compile(self, src)[source]

Compiles source code and returns the (possibly modified) source and a valid code object.

default(self, line)[source]

Implements code execution.


Called when an empty line has been entered.

format_color(self, string, hide=False, force_string=False, **kwargs)[source]

Formats the colors in a string. BaseShell’s default implementation of this method uses colors based on ANSI color codes.

precmd(self, line)[source]

Called just before execution of line.

print_color(self, string, hide=False, **kwargs)[source]

Prints a string in color. This base implementation’s colors are based on ANSI color codes if a string was given as input. If a list of token pairs is given, it will color based on pygments, if available. If pygments is not available, it will print a colorless string.

push(self, line)[source]

Pushes a line onto the buffer and compiles the code in a way that enables multiline input.


Resets the line buffer.


An interface for resetting the TTY stdin mode. This is highly dependent on the shell backend. Also it is mostly optional since it only affects ^Z backgrounding behaviour.


Sets terminal title.

singleline(self, **kwargs)[source]

Reads a single line of input from the shell.


Obtains the current prompt string.

class xonsh.base_shell.Tee(buffer=None, encoding=None, errors=None, newline=None, line_buffering=False, write_through=False)[source]

Class that merges tee’d stdout and stderr into a single stream.

This represents what a user would actually see on the command line. This class has the same interface as io.TextIOWrapper, except that the buffer is optional.


Closes the buffer as well as the stdout and stderr tees.


Gets the current contents of the in-memory buffer.