CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ipython

IPython: Productive Interactive Computing - An advanced interactive computing environment and command shell for Python.

86

1.08x
Overview
Eval results
Files

terminal-interface.mddocs/

Terminal Interface and Embedding

Advanced terminal integration with syntax highlighting, tab completion, keyboard shortcuts, and embedding capabilities for interactive debugging. IPython provides rich terminal experiences and flexible embedding options for development workflows.

Capabilities

Terminal Interactive Shell

Advanced terminal-based interactive shell with rich features.

class TerminalInteractiveShell(InteractiveShell):
    """
    Terminal-based interactive shell with advanced terminal features.
    
    Provides syntax highlighting, keyboard shortcuts, multi-line editing,
    history navigation, and tab completion in terminal environments.
    """
    
    def __init__(self, **kwargs):
        """
        Initialize terminal shell.
        
        Parameters include configuration for colors, prompts, completion,
        history, and other terminal-specific features.
        """
    
    def interact(self):
        """Start the interactive terminal loop."""
    
    def mainloop(self):  
        """Main event loop for terminal interaction."""

Embedding Interactive Shells

Embed IPython shells within existing applications and code for debugging.

def embed(header='', compile_flags=None, **kwargs):
    """
    Call this to embed IPython at the current point in your program.
    
    Creates an interactive IPython shell that has access to the local
    namespace where embed() is called. Useful for debugging and
    interactive exploration of program state.
    
    Parameters:
    - header: str, optional - Custom header message
    - compile_flags: int, optional - Python compile flags
    - **kwargs: additional arguments for InteractiveShellEmbed
    
    Returns:
    None
    """

class InteractiveShellEmbed(TerminalInteractiveShell):
    """
    Interactive shell for embedding within other applications.
    
    Specialized shell that can be embedded in existing code,
    providing access to local variables and enabling interactive
    debugging and exploration.
    """
    
    def __init__(self, **kwargs):
        """Initialize embedded shell."""
    
    def __call__(self, header='', local_ns=None, module=None, **kwargs):
        """Activate the embedded shell."""

class EmbeddedMagics(Magics):
    """Magic commands specific to embedded shells."""
    
    @line_magic
    def kill_embedded(self, parameter_s=''):
        """Exit embedded shell and kill the embedded context."""
    
    @line_magic  
    def exit_raise(self, parameter_s=''):
        """Exit embedded shell by raising SystemExit."""

Usage examples:

# Basic embedding for debugging
import IPython

def process_data(data):
    processed = []
    for i, item in enumerate(data):
        # Debug specific iterations
        if i == 5:
            IPython.embed(header=f"Debugging iteration {i}")
        
        result = complex_operation(item)
        processed.append(result)
    
    return processed

# Conditional embedding
import IPython

def analyze_results(results):
    suspicious_results = [r for r in results if r.confidence < 0.5]
    
    if suspicious_results:
        print(f"Found {len(suspicious_results)} suspicious results")
        IPython.embed(header="Debug suspicious results - check 'suspicious_results' variable")
    
    return results

# Custom embedded shell configuration
from IPython.terminal.embed import InteractiveShellEmbed

# Create custom embedded shell
ipshell = InteractiveShellEmbed(
    banner1="Custom Debug Shell\n",
    exit_msg="Leaving debug mode"
)

def debug_function():
    local_var = "debug data"
    ipshell(header="Custom shell active", local_ns=locals())

Keyboard Shortcuts and Terminal Features

Terminal customization and keyboard shortcut management.

def create_ipython_shortcuts(shell):
    """
    Create IPython-specific keyboard shortcuts for terminal interface.
    
    Parameters:
    - shell: TerminalInteractiveShell instance
    
    Returns:
    KeyBindings object with IPython shortcuts
    """

# Common terminal features and shortcuts:
# Ctrl+D: Exit IPython
# Ctrl+C: Interrupt execution  
# Ctrl+L: Clear screen
# Ctrl+A: Move to beginning of line
# Ctrl+E: Move to end of line
# Ctrl+K: Kill to end of line
# Ctrl+U: Kill to beginning of line
# Ctrl+R: Reverse history search
# Tab: Code completion
# Shift+Tab: Show docstring
# Up/Down: History navigation
# Ctrl+P/Ctrl+N: History navigation (alternative)

Terminal Application Framework

Framework for building terminal-based IPython applications.

class TerminalIPythonApp(BaseIPythonApplication):
    """
    Terminal IPython application.
    
    Main application class for running IPython in terminal mode.
    Handles configuration, initialization, and application lifecycle.
    """
    
    def initialize(self, argv=None):
        """Initialize the application with command-line arguments."""
    
    def start(self):
        """Start the IPython terminal application."""

def launch_new_instance(argv=None, **kwargs):
    """
    Launch a new IPython terminal instance.
    
    Parameters:
    - argv: list, optional - Command-line arguments
    - **kwargs: additional application arguments
    
    Returns:
    TerminalIPythonApp instance
    """

Terminal Customization

Configuration options for terminal appearance and behavior.

# Terminal color schemes
# Available schemes: 'NoColor', 'Linux', 'Neutral'
ipython.colors = 'Linux'

# Prompt customization
ipython.prompt_in1 = 'In [\\#]: '
ipython.prompt_in2_template = '   .\\D.: '
ipython.prompt_out_template = 'Out[\\#]: '

# History configuration
ipython.history_length = 10000
ipython.history_load_length = 1000

# Completion configuration  
ipython.readline_use = True
ipython.readline_omit__names = 2

# Auto-indentation
ipython.autoindent = True

# Syntax highlighting
ipython.highlighting_style = 'default'  # or 'emacs', 'vim', etc.

Terminal usage examples:

# Start IPython with custom configuration
import IPython
from traitlets.config import Config

c = Config()
c.TerminalInteractiveShell.colors = 'Linux'
c.TerminalInteractiveShell.autoindent = True
c.TerminalInteractiveShell.history_length = 5000

IPython.start_ipython(config=c)

# Advanced embedding with context management
class DebugContext:
    def __init__(self, name):
        self.name = name
        
    def __enter__(self):
        print(f"Entering debug context: {self.name}")
        return self
        
    def __exit__(self, exc_type, exc_val, exc_tb):
        print(f"Exiting debug context: {self.name}")
        
    def embed(self, **kwargs):
        IPython.embed(header=f"Debug: {self.name}", **kwargs)

# Usage
with DebugContext("data_processing") as debug:
    data = process_complex_data()
    if data is None:
        debug.embed()  # Drop into shell for debugging

Types

class TerminalInteractiveShell(InteractiveShell):
    """
    Terminal-based interactive shell.
    
    Extends InteractiveShell with terminal-specific features like
    syntax highlighting, keyboard shortcuts, and prompt formatting.
    """
    
    def __init__(self, **kwargs):
        """Initialize with terminal-specific configuration."""
    
    def interact(self):
        """Start interactive terminal session."""
    
    def prompt_for_code(self):
        """Display prompt and read code input."""

class InteractiveShellEmbed(TerminalInteractiveShell):
    """
    Embeddable interactive shell.
    
    Shell that can be embedded in existing applications,
    providing access to local namespace and debugging capabilities.
    """
    
    def __call__(self, header='', local_ns=None, module=None, **kwargs):
        """Activate embedded shell in current context."""

class TerminalIPythonApp(BaseIPythonApplication):
    """
    Terminal IPython application.
    
    Main application for running IPython in terminal mode,
    handling configuration and application lifecycle.
    """
    
    def initialize(self, argv=None):
        """Initialize application."""
        
    def start(self):  
        """Start terminal application."""

# Configuration classes
class TerminalInteractiveShellConfig:
    """Configuration for terminal shell features."""
    colors = 'Linux'  # Color scheme
    autoindent = True  # Auto-indentation
    history_length = 10000  # History size
    completion_use_history = True  # Use history for completion

Install with Tessl CLI

npx tessl i tessl/pypi-ipython

docs

configuration-utilities.md

core-shell.md

display-system.md

extension-system.md

index.md

magic-system.md

terminal-interface.md

tile.json