Skip to content

Latest commit

 

History

History
171 lines (125 loc) · 3.68 KB

File metadata and controls

171 lines (125 loc) · 3.68 KB

TerminalPanel

A terminal-style panel with a scrollable output area and a command input line. Maintains a configurable output buffer and raises events for command submission.

Basic usage

<TerminalPanel Title="Terminal"
              Prompt="$"
              IsRunning="True" />

Properties

Property Type Default Description
Title string "Terminal" Panel title shown in the header
IsRunning bool Whether the terminal session is active
StatusText string? Status text shown in the header
StatusColor IBrush? Brush used for the status indicator dot
InputText string? Current input line text
OutputText string? Full output text displayed in the terminal
Prompt string "$" Prompt string shown before the input box
MaxOutputLines int 5000 Maximum number of output lines to retain
ShowCloseButton bool true Whether the close button is visible

Events

Event Description
CommandSubmitted Raised when the user submits a command (presses Enter)
CloseRequested Raised when the user clicks the close button

Appending output

Add text to the terminal output:

terminalPanel.AppendOutput("Hello, World!\n");
terminalPanel.AppendOutput("Command completed successfully.\n");

Clearing output

Clear all output:

terminalPanel.ClearOutput();

Command handling

Handle command submissions:

terminalPanel.CommandSubmitted += (sender, command) =>
{
    // Process the command
    terminalPanel.AppendOutput($"Executing: {command}\n");
    
    // Simulate command execution
    var result = ProcessCommand(command);
    terminalPanel.AppendOutput($"{result}\n");
};

Prompt

Customize the prompt string:

<TerminalPanel Prompt=">" />
terminalPanel.Prompt = "#";

Status

Set status text and color:

<TerminalPanel StatusText="Connected"
              StatusColor="Green" />
terminalPanel.StatusText = "Disconnected";
terminalPanel.StatusColor = Brushes.Red;

Running state

Control whether the terminal is active:

<TerminalPanel IsRunning="True" />
terminalPanel.IsRunning = false;

Max output lines

Set the maximum number of lines to retain (older lines are removed):

<TerminalPanel MaxOutputLines="10000" />

Close button

Control the visibility of the close button:

<TerminalPanel ShowCloseButton="False" />

Focus input

Focus the input box programmatically:

terminalPanel.FocusInput();

Example

var terminal = new TerminalPanel
{
    Title = "Command Line",
    Prompt = ">",
    IsRunning = true
};

terminal.CommandSubmitted += (sender, cmd) =>
{
    terminal.AppendOutput($"{terminal.Prompt} {cmd}\n");
    
    switch (cmd.ToLower())
    {
        case "help":
            terminal.AppendOutput("Available commands: help, clear, echo [text]\n");
            break;
        case "clear":
            terminal.ClearOutput();
            break;
        default:
            terminal.AppendOutput($"Unknown command: {cmd}\n");
            break;
    }
};

Pseudo-classes

The control applies pseudo-classes based on state:

  • :running - Applied when the terminal is running
  • :hasOutput - Applied when there is output text

Template parts

The control template must provide:

  • PART_OutputBox - TextBox that displays output
  • PART_InputBox - TextBox for command input
  • PART_ClearButton - Button to clear output
  • PART_CloseButton - Button to close the panel
  • PART_ScrollViewer - SmoothScrollViewer for output scrolling