Skip to content

Terminal

abbaye edited this page Mar 8, 2026 · 2 revisions

Terminal Panel

The integrated terminal provides a command-line interface inside the IDE — 38 built-in HxTerminal commands, a full embedded PowerShell shell, .hxscript file execution, colored output, and a plugin API.


Opening

Method Action
Tools → Terminal Open / focus
openpanel terminal From another terminal command

Architecture

flowchart TD
    subgraph Core["WpfHexEditor.Core.Terminal"]
        Reg["TerminalCommandRegistry\n38 built-in commands + tab completion"]
        Hist["CommandHistory\npersistent cross-session"]
        Script["HxScriptEngine\n.hxscript file execution"]
        ICtx["ITerminalContext\nCWD · output · dispatch"]
        IOut["ITerminalOutput\nWriteLine · WriteTable · Clear"]
    end

    subgraph WPF["WpfHexEditor.Terminal"]
        Panel["TerminalPanel.xaml\nRichTextBox output · input row · toolbar"]
        VM["TerminalPanelViewModel\nITerminalContext + ITerminalOutput"]
        Export["TerminalExportService\n6 export formats"]
        Mode["TerminalMode\nHxTerminal · PowerShell"]
        PS["PowerShell process\npwsh.exe / powershell.exe\nstdin/stdout/stderr piped"]
    end

    subgraph SDKLayer["WpfHexEditor.SDK"]
        ITS["ITerminalService\nplugin-facing contract"]
    end

    VM --> Reg
    VM --> Hist
    VM --> Script
    VM --> Export
    VM --> PS
    Panel --> VM
    ITS --> VM
Loading

Shell Modes

The terminal has two independent shell modes selectable via the mode dropdown in the toolbar:

Mode Label Description
HxTerminal HxTerminal Built-in IDE command engine — 38 commands, .hxscript support, tab completion
PowerShell PowerShell Full embedded PowerShell process (pwsh.exe / powershell.exe) with stdin/stdout/stderr piping

PowerShell Integration

How it works

When you select PowerShell in the mode dropdown the terminal:

  1. Resolves pwsh.exe (PowerShell 7+) or falls back to powershell.exe (Windows PowerShell 5.x)
  2. Starts the process with -NoLogo -NoExit and fully redirected stdin / stdout / stderr
  3. Pipes your typed input directly to PowerShell's stdin — live interactive shell
  4. Streams stdout (white) and stderr (red) asynchronously into the output view
[PowerShell started: C:\Program Files\PowerShell\7\pwsh.exe]
PS C:\Users\you> Get-Item firmware.bin | Select-Object Length
PS C:\Users\you> [System.IO.File]::ReadAllBytes("firmware.bin")[0..15]

Encoding

Select the output encoding via the UTF-8 / Windows-1252 / ASCII toolbar dropdown. Default is UTF-8 (BOM-free). Change before switching to PowerShell mode if your profile uses a different code page.

Mode switching

Action Result
Dropdown → PowerShell Starts PS process; shows [PowerShell started: ...]
Dropdown → HxTerminal Sends exit to stdin, waits 300 ms, kills if needed; shows [Switched to HxTerminal]
PowerShell exits naturally Auto-reverts to HxTerminal

Requirements

Requirement Details
PowerShell 7+ (recommended) winget install Microsoft.PowerShell
Windows PowerShell 5.x (fallback) Built into Windows — no install needed

Editing .ps1 files

.ps1 / .psm1 / .psd1 files open in the Code Editor with syntax highlighting (PowerShell.whfmt + shell.whlang). Edit scripts in the IDE, run them from the PowerShell terminal tab:

PS C:\Scripts> .\analysis.ps1 -Target C:\Data\firmware.bin

HxTerminal Commands (38)

Naming convention: Commands are lowercase, no spaces (e.g. closefile, openpanel). Exceptions using hyphens: plugin-list, read-hex, run-script, list-open, send-error, send-output.

Core

Command Description
clear Clear terminal output
echo <text> Print text to the terminal
exit Close the terminal panel session
help [cmd] List all commands or show help for a specific command
history Show command history
version Show IDE and terminal version

File System

Command Description
copyfile <src> <dst> Copy a file from source to destination
deletefile <path> Delete a file from disk
listfiles [--filter <pat>] List files in a directory (default: working dir)
list-open List all currently open files in the IDE
open <path> Open a file in the active editor
openfolder <path> Open a folder in Solution Explorer

Editor

Command Description
closefile [name] Close the active file or a named open file
read-hex <offset> [count] Display hex bytes from the active HexEditor
savefile [name] Save the active file (or a named open file)
saveas <path> Save the active file under a new path
search <hex/text> Search hex pattern or text in the active HexEditor
selectfile <name> Select (highlight) a file in Solution Explorer
writehex <offset> <bytes> Write hex bytes to a position in the active HexEditor

Project / Solution

Command Description
closeproject <name> Close a project by name
closesolution Close the active solution
openproject <name> Activate a project node in Solution Explorer
opensolution <path> Open a solution file in the IDE
reloadsolution Reload the active solution from disk

Panels

Command Description
appendpanel <panel> <text> Append text to an IDE panel (output, errors)
clearpanel <panel> Clear the content of a named IDE panel
closepanel <uiId> Close (hide) a dockable panel by its UI id
focuspanel <uiId> Give keyboard focus to a dockable panel
openpanel <uiId> Show a dockable panel by its UI id
togglepanel <uiId> Toggle visibility of a dockable panel

Plugins

Command Description
plugin-list List all installed plugins and their state
runplugin <id> Execute a terminal command contributed by a plugin

Scripts

Command Description
run-script <path> Execute a .hxscript file

Diagnostics

Command Description
send-error <msg> Send an error message to the Error panel
send-output <msg> Send a message to the Output panel
showerrors [n] Display the last N error panel entries (default: 20)
showlogs [n] Display the last N output panel log lines (default: 20)
status Show current IDE state (active document, working dir, etc.)

Keyboard

Key Action
Enter Execute
/ History navigation
Tab Auto-complete (HxTerminal mode only)
Ctrl+C Copy selected
Ctrl+L Clear (same as clear)
Escape Clear input line

HxScript Files

.hxscript files contain HxTerminal commands executed sequentially. Use run-script to run them.

run-script C:\Scripts\analysis.hxscript

Example .hxscript:

open C:\Data\firmware.bin
search DE AD BE EF
read-hex 0x1000 256
send-output Analysis complete

Toolbar Options

Control Description
Mode dropdown Switch between HxTerminal and PowerShell
Encoding dropdown Output encoding for PowerShell mode (UTF-8 / Windows-1252 / ASCII)
Word wrap toggle Wrap long lines in output
Timestamps toggle Prefix each output line with [HH:mm:ss]
Font size +/− Increase or decrease output font size (8–28 pt)
Auto-scroll toggle Keep output scrolled to the latest line
Pause button Pause output streaming (buffered internally)
Export button Export session to file

Plugin API

ITerminalService terminal = context.Terminal;

// Execute a built-in HxTerminal command
terminal.Execute("listfiles --filter *.bin");

// Write with severity
terminal.WriteLine("File not found.", TerminalSeverity.Warning);

// Write a table
terminal.WriteTable(
    headers: new[] { "Offset", "Value", "Type" },
    rows:    fields.Select(f => new[] { f.Offset.ToString("X"), f.Value, f.Type }));

// Export session
terminal.ExportSession(@"C:\Logs\session.txt");

// Read history
var lines = terminal.HistoryLines;

Declare terminal capability in your plugin manifest:

{ "capabilities": ["Terminal"], "permissions": ["WriteOutput"] }

Export Formats

Format Extension Colors
Plain Text .txt No
HTML .html CSS span
RTF / Word .rtf Color table
ANSI .ansi Escape codes
Markdown .md Table
SpreadsheetML .xml Excel/LibreOffice

See Also

Navigation

Getting Started

IDE Documentation

HexEditor Control

Advanced

Development


v0.6.4.75 Highlights

  • whfmt.FileFormatCatalog v1.0.0 NuGet (cross-platform net8.0)
  • 690+ .whfmt definitions (schema v2.3)
  • Structure Editor — block DataGrid, drag-drop, validation, SmartComplete
  • WhfmtBrowser/Catalog panels — browse all embedded formats
  • AI Assistant (5 providers, 25 MCP tools)
  • Tab Groups, Document Structure, Lazy Plugin Loading
  • Window Menu + Win32 Fullscreen (F11)
  • Git Integration UI (changes, history, blame)
  • Shared Undo Engine (HexEditor ↔ CodeEditor)
  • Bracket pair colorization, sticky scroll, peek definition
  • Format detection hardening (thread-safe, crash guard)

Links

Clone this wiki locally