Oakrey.Applications.Terminals
2.0.3
dotnet add package Oakrey.Applications.Terminals --version 2.0.3
NuGet\Install-Package Oakrey.Applications.Terminals -Version 2.0.3
<PackageReference Include="Oakrey.Applications.Terminals" Version="2.0.3" />
<PackageVersion Include="Oakrey.Applications.Terminals" Version="2.0.3" />
<PackageReference Include="Oakrey.Applications.Terminals" />
paket add Oakrey.Applications.Terminals --version 2.0.3
#r "nuget: Oakrey.Applications.Terminals, 2.0.3"
#:package Oakrey.Applications.Terminals@2.0.3
#addin nuget:?package=Oakrey.Applications.Terminals&version=2.0.3
#tool nuget:?package=Oakrey.Applications.Terminals&version=2.0.3
Oakrey.Applications.Terminals
A .NET 10 WPF library for building terminal-like interfaces in MVVM applications. It provides command history, message management, reactive updates, file export, and built-in integration with Oakrey.Log and Oakrey.Telemetry.
Main features
- Command history - navigable history of submitted commands with duplicate deduplication and a configurable capacity (default 20 entries).
- Generic message collection -
IMessageCollection<TMessage>backed by aReplaySubjectfor reactive change notifications. - Built-in message types -
StringMessageandStringAndDirectionMessage(withDirection) ship out of the box; custom types require only implementingIMessage. - Sorting and display settings -
IMessageViewSettingscontrols sort order (OldestOnTop/NewestOnTop), displayed message count, and timestamp visibility. - File export -
SaveToFilecommand writes messages to a.txtfile via a standard save dialog with a configurable file name prefix. - Context menu integration -
ContextCommandscollection is data-bindable and ships with "Clear" and "Save to file" entries. - Logging and telemetry - all commands and file operations are traced through
Oakrey.LogandOakrey.Telemetryautomatically.
Architecture
classDiagram
class IMessage {
+DateTime Timestamp
}
class StringMessage {
+string Message
+DateTime Timestamp
}
class StringAndDirectionMessage {
+string Message
+Direction Direction
+DateTime Timestamp
}
class IMessageCollection~TMessage~ {
+List~TMessage~ Messages
+AddMessage(TMessage)
+ClearMessages()
+Subscribe(IObserver)
}
class MessageCollection~TMessage~
class IMessageViewSettings {
+SortOrder SortOrder
+int DisplayedMessages
+bool ShowTimestamp
}
class HistoryViewModel {
+string Command
+IStringHistoryProvider History
+AddCommandToHistory()
+HistoryUp()
+HistoryDown()
+Export() string
}
class TerminalViewModel~TMessage~ {
+ObservableCollection~TMessage~ Messages
+ObservableCollection~TMessage~ TerminalMessages
+ObservableCollection~ContextMenuForViewModel~ ContextCommands
+ICommand SendCommand
+ICommand ClearMessages
+ICommand SaveToFile
#DefaultCommand()*
#TraceLine(TMessage)*
+string FilePrefix*
}
IMessage <|.. StringMessage
IMessage <|.. StringAndDirectionMessage
IMessageCollection <|.. MessageCollection
HistoryViewModel <|-- TerminalViewModel
TerminalViewModel o-- IMessageCollection
TerminalViewModel o-- IMessageViewSettings
Key types
| Type | Description |
|---|---|
IMessage |
Minimal contract for a timestamped message. |
StringMessage |
Simple string message with a DateTime timestamp. |
StringAndDirectionMessage |
Message with an additional Direction (e.g. inbound/outbound). |
MessageCollection<TMessage> |
Default in-memory IMessageCollection<TMessage> using System.Reactive. |
IMessageViewSettings / MessageViewSettings |
Controls sort order, display count, and timestamp visibility. |
IStringHistoryProvider / CommandHistory |
Navigable, deduplicated command history (capacity 20). |
HistoryViewModel |
WPF ViewModel base with command input and history navigation. |
TerminalViewModel<TMessage> |
Abstract ViewModel base combining history, messages, export, and context menu. |
ContextMenuForViewModel |
Bindable context menu entry pairing a display name with an ICommand. |
Requirements
- .NET 10 (Windows)
- WPF (Windows Presentation Foundation)
Installation
NuGet Package Manager
Search for Oakrey.Applications.Terminals in Visual Studio under
Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
.NET CLI
dotnet add package Oakrey.Applications.Terminals
Package Manager Console
Install-Package Oakrey.Applications.Terminals
Configuration
Inject or create an IMessageViewSettings instance and pass it to your TerminalViewModel subclass:
MessageViewSettings settings = new()
{
SortOrder = SortOrder.NewestOnTop,
DisplayedMessages = 200,
ShowTimestamp = true
};
Example usage
Implement TerminalViewModel<TMessage> to create a concrete terminal:
public sealed class MyTerminalViewModel : TerminalViewModel<StringMessage>
{
public override string FilePrefix => "my-terminal";
protected override string TraceLine(StringMessage message)
=> $"[{message.Timestamp:HH:mm:ss}] {message.Message}";
protected override void DefaultCommand()
{
if (string.IsNullOrWhiteSpace(Command))
{
return;
}
devices.AddMessage(new StringMessage(Command));
}
}
Bind in XAML:
<ItemsControl ItemsSource="{Binding TerminalMessages}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Message}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBox Text="{Binding Command, UpdateSourceTrigger=PropertyChanged}" />
<Button Content="Send" Command="{Binding SendCommand}" />
<ContextMenu ItemsSource="{Binding ContextCommands}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header" Value="{Binding DisplayName}" />
<Setter Property="Command" Value="{Binding MessageContextMenuCommand}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
Development notes
TerminalViewModel<TMessage>implementsIDisposable. Always dispose instances that are no longer needed to unsubscribe from the reactive pipeline.CommandHistorycapacity is fixed at 20 entries. Provide a customIStringHistoryProviderto change this behaviour.MessageCollection<TMessage>.ClearMessages()callsmessageSubject.OnNext(messages.Last())after clearing; ensure the collection is non-empty before clearing or guard accordingly in derived code.- Logging uses
Oakrey.Log.LoggerFactoryand tracing usesOakrey.Telemetry.TracingFactory, both resolved by the concreteTypeof the ViewModel subclass.
License
MIT - Copyright (c) Oakrey 2016-2025. See LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Oakrey.Log (>= 2.0.0)
- Oakrey.Telemetry (>= 2.0.1)
- Oakrey.ViewModels (>= 2.1.0)
- System.Reactive (>= 6.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.