Class ConsoleWindowSystem
- Namespace
- SharpConsoleUI
- Assembly
- SharpConsoleUI.dll
The main window system that manages console windows, input processing, and rendering. Provides window management, focus handling, theming, and event processing for console applications.
public class ConsoleWindowSystem
- Inheritance
-
ConsoleWindowSystem
- Inherited Members
- Extension Methods
Constructors
ConsoleWindowSystem(IConsoleDriver, PluginConfiguration?, ConsoleWindowSystemOptions?, RegistryConfiguration?)
Initializes a new instance of the ConsoleWindowSystem class with the default theme.
public ConsoleWindowSystem(IConsoleDriver driver, PluginConfiguration? pluginConfiguration = null, ConsoleWindowSystemOptions? options = null, RegistryConfiguration? registryConfiguration = null)
Parameters
driverIConsoleDriverPre-configured console driver.
pluginConfigurationPluginConfigurationOptional plugin configuration for auto-loading plugins.
optionsConsoleWindowSystemOptionsOptional configuration options for system behavior.
registryConfigurationRegistryConfigurationOptional registry configuration for persistent key-value storage.
ConsoleWindowSystem(IConsoleDriver, ITheme, PluginConfiguration?, ConsoleWindowSystemOptions?, RegistryConfiguration?)
Initializes a new instance of the ConsoleWindowSystem class with a specific theme instance.
public ConsoleWindowSystem(IConsoleDriver driver, ITheme theme, PluginConfiguration? pluginConfiguration = null, ConsoleWindowSystemOptions? options = null, RegistryConfiguration? registryConfiguration = null)
Parameters
driverIConsoleDriverPre-configured console driver.
themeIThemeThe theme instance to use.
pluginConfigurationPluginConfigurationOptional plugin configuration for auto-loading plugins.
optionsConsoleWindowSystemOptionsOptional configuration options for system behavior.
registryConfigurationRegistryConfigurationOptional registry configuration for persistent key-value storage.
ConsoleWindowSystem(IConsoleDriver, string, PluginConfiguration?, ConsoleWindowSystemOptions?, RegistryConfiguration?)
Initializes a new instance of the ConsoleWindowSystem class with a theme specified by name.
public ConsoleWindowSystem(IConsoleDriver driver, string themeName, PluginConfiguration? pluginConfiguration = null, ConsoleWindowSystemOptions? options = null, RegistryConfiguration? registryConfiguration = null)
Parameters
driverIConsoleDriverPre-configured console driver.
themeNamestringThe name of the theme to use.
pluginConfigurationPluginConfigurationOptional plugin configuration for auto-loading plugins.
optionsConsoleWindowSystemOptionsOptional configuration options for system behavior.
registryConfigurationRegistryConfigurationOptional registry configuration for persistent key-value storage.
ConsoleWindowSystem(RenderMode, PluginConfiguration?, ConsoleWindowSystemOptions?, RegistryConfiguration?)
Initializes a new instance with a render mode.
public ConsoleWindowSystem(RenderMode renderMode, PluginConfiguration? pluginConfiguration = null, ConsoleWindowSystemOptions? options = null, RegistryConfiguration? registryConfiguration = null)
Parameters
renderModeRenderModeThe rendering mode to use.
pluginConfigurationPluginConfigurationOptional plugin configuration for auto-loading plugins.
optionsConsoleWindowSystemOptionsOptional configuration options for system behavior.
registryConfigurationRegistryConfigurationOptional registry configuration for persistent key-value storage.
Fields
Performance
Gets the performance tracker for monitoring frame rates and render times.
public PerformanceTracker Performance
Field Value
Properties
ActiveWindow
Gets the currently active window, or null if no window is active.
public Window? ActiveWindow { get; }
Property Value
Animations
Gets the animation manager for creating and controlling tweened animations.
public AnimationManager Animations { get; }
Property Value
BottomPanel
Gets the bottom panel (desktop bar) if configured, or null.
public Panel? BottomPanel { get; }
Property Value
ConsoleDriver
Gets or sets the console driver used for low-level console operations.
public IConsoleDriver ConsoleDriver { get; set; }
Property Value
DesktopBackground
Gets or sets the desktop background configuration.
public DesktopBackgroundConfig? DesktopBackground { get; set; }
Property Value
DesktopBackgroundColor
Gets or sets the desktop background color directly. This is a convenience property — it creates/updates the DesktopBackgroundConfig. Set to Color.Transparent for terminal-level transparency.
public Color? DesktopBackgroundColor { get; set; }
Property Value
DesktopBackgroundService
Gets the desktop background service.
public DesktopBackgroundService DesktopBackgroundService { get; }
Property Value
DesktopBottomRight
Gets the bottom-right coordinate of the usable desktop area (excluding status bars).
public Point DesktopBottomRight { get; }
Property Value
DesktopDimensions
Gets the dimensions of the usable desktop area (excluding status bars).
public Size DesktopDimensions { get; }
Property Value
DesktopPortalService
Gets the desktop portal service for managing desktop-level overlay portals.
public DesktopPortalService DesktopPortalService { get; }
Property Value
DesktopUpperLeft
Gets the upper-left coordinate of the usable desktop area (excluding status bars).
public Point DesktopUpperLeft { get; }
Property Value
IsIdle
Gets a value indicating whether the input system is currently idle (no input for the configured threshold).
public bool IsIdle { get; }
Property Value
IsRunning
Gets a value indicating whether the window system is currently running.
public bool IsRunning { get; }
Property Value
LogService
Gets the library-managed logging service. Subscribe to LogAdded event or call GetRecentLogs() to access internal logs.
public ILogService LogService { get; }
Property Value
ModalStateService
Gets the modal state service for managing modal window behavior.
public ModalStateService ModalStateService { get; }
Property Value
NotificationStateService
Gets the notification state service for managing notifications and toasts.
public NotificationStateService NotificationStateService { get; }
Property Value
Options
Gets or sets the current console window system options.
public ConsoleWindowSystemOptions Options { get; set; }
Property Value
PanelStateService
Gets the panel state service for managing panels, Start menu, and panel visibility.
public PanelStateService PanelStateService { get; }
Property Value
PipedInput
Gets the text that was piped into the application via stdin, or null if stdin is a TTY. Automatically captured at construction time — available throughout the app lifecycle.
public string? PipedInput { get; }
Property Value
PipedLines
Gets the piped stdin split into lines, or null if stdin is a TTY.
public string[]? PipedLines { get; }
Property Value
- string[]
PluginStateService
Gets the plugin state service for managing plugins and their contributions.
public PluginStateService PluginStateService { get; }
Property Value
RegistryStateService
Gets the registry state service for persistent key-value storage. Null if no RegistryConfiguration was provided at construction.
public RegistryStateService? RegistryStateService { get; }
Property Value
SettingsRegistrationService
Gets the settings registration service for adding custom settings pages.
public SettingsRegistrationService SettingsRegistrationService { get; }
Property Value
Theme
Gets the theme used for styling windows and controls. Use ThemeStateService.CurrentTheme or ThemeStateService.SetTheme() for theme management.
public ITheme Theme { get; }
Property Value
ThemeStateService
Gets the theme state service for managing theme application.
public ThemeStateService ThemeStateService { get; }
Property Value
TopPanel
Gets the top panel (desktop bar) if configured, or null.
public Panel? TopPanel { get; }
Property Value
WindowStateService
Gets the window state service for managing window lifecycle and state.
public WindowStateService WindowStateService { get; }
Property Value
Windows
Gets a read-only dictionary of all windows in the system, keyed by their GUID.
public IReadOnlyDictionary<string, Window> Windows { get; }
Property Value
Methods
AddWindow(Window, bool)
Adds a window to the window system.
public Window AddWindow(Window window, bool activateWindow = true)
Parameters
windowWindowThe window to add.
activateWindowboolWhether to activate the window after adding. Defaults to true.
Returns
- Window
The added window.
CloseModalWindow(Window?)
Closes a modal window and optionally activates its parent window.
public void CloseModalWindow(Window? modalWindow)
Parameters
modalWindowWindowThe modal window to close. If null or not a modal window, the method returns without action.
CloseWindow(Window?, bool, bool)
Closes a window and removes it from the window system.
public bool CloseWindow(Window? window, bool activateParent = true, bool force = false)
Parameters
windowWindowThe window to close. If null or not in the system, returns false.
activateParentboolWhether to activate the parent window after closing. Defaults to true.
forceboolIf true, forces the window to close even if IsClosable is false or OnClosing cancels.
Returns
- bool
True if the window was closed successfully; false otherwise.
CycleActiveWindow()
Cycles to the next active window (Ctrl+T handler).
public void CycleActiveWindow()
EnqueueOnUIThread(Action)
Enqueues an action to be executed on the UI thread during the next main loop iteration. Safe to call from any thread. Actions run between input processing and rendering.
public void EnqueueOnUIThread(Action action)
Parameters
actionActionThe action to execute on the UI thread.
ForceFullRedraw()
Forces a full screen clear and desktop repaint. Used when desktop bounds change (e.g., panel visibility toggle).
public void ForceFullRedraw()
ForceRender()
Forces an immediate render cycle, bypassing frame rate limiting. Intended for benchmarking and testing scenarios.
public void ForceRender()
GetWindowAtPoint(Point)
Finds the topmost window at the specified point.
public Window? GetWindowAtPoint(Point point)
Parameters
pointPointThe point in absolute screen coordinates.
Returns
- Window
The topmost window at the point, or null if none found.
ProcessOnce()
Processes one iteration of the main loop (input, display, cursor). This is useful for modal dialogs that need to block while still processing UI events.
public void ProcessOnce()
RegisterGlobalShortcut(ConsoleModifiers, ConsoleKey, Action)
Registers a global keyboard shortcut that is handled before routing to windows.
public void RegisterGlobalShortcut(ConsoleModifiers modifiers, ConsoleKey key, Action action)
Parameters
modifiersConsoleModifiersThe modifier keys (e.g. Control, Alt, Shift).
keyConsoleKeyThe key to bind.
actionActionThe action to invoke when the shortcut is pressed.
RegisterSettingsGroup(string, Color, Action<SettingsGroupBuilder>)
Registers a settings group with multiple pages, shown in the Settings dialog.
public void RegisterSettingsGroup(string name, Color accentColor, Action<SettingsGroupBuilder> configure)
Parameters
namestringThe display name of the settings group.
accentColorColorThe accent color used for this group in the navigation sidebar.
configureAction<SettingsGroupBuilder>Action that configures the group's pages via a builder.
RegisterSettingsPage(string, string?, string?, Action<ScrollablePanelControl>?)
Registers a single settings page under the "Extensions" group in the Settings dialog.
public void RegisterSettingsPage(string name, string? icon = null, string? subtitle = null, Action<ScrollablePanelControl>? content = null)
Parameters
namestringThe display name of the settings page.
iconstringOptional icon character or string shown beside the page name.
subtitlestringOptional subtitle shown below the page name.
contentAction<ScrollablePanelControl>Factory that populates the page content panel.
RequestExit(int)
Requests the window system to exit with the specified exit code.
public void RequestExit(int exitCode)
Parameters
exitCodeint
Run()
Starts the main event loop of the window system. Blocks until Shutdown(int) is called.
public int Run()
Returns
- int
The exit code set by Shutdown(int) or 1 if an unhandled exception occurred.
SetActiveWindow(Window)
Sets the specified window as the active window, handling modal window logic and focus.
public void SetActiveWindow(Window window)
Parameters
windowWindowThe window to activate. If null, the method returns without action.
Shutdown(int)
Gracefully shuts down the console window system with the specified exit code
public void Shutdown(int exitCode = 0)
Parameters
exitCodeintThe exit code to return
Events
IdleStateChanged
Raised when the input idle state changes (idle started or ended).
public event EventHandler<IdleStateEventArgs>? IdleStateChanged