LogTerminal 1.1.0

Requires NuGet 3.3.0 or higher.

dotnet add package LogTerminal --version 1.1.0
NuGet\Install-Package LogTerminal -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LogTerminal" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LogTerminal --version 1.1.0
#r "nuget: LogTerminal, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LogTerminal as a Cake Addin
#addin nuget:?package=LogTerminal&version=1.1.0

// Install LogTerminal as a Cake Tool
#tool nuget:?package=LogTerminal&version=1.1.0

#How to use

1/ In MainWidow.xaml

Add namespace

<Window
    ...
    xmlns:term="clr-namespace:Microsoft.Terminal.Wpf;assembly=Microsoft.Terminal.Wpf"
    ...
>
<Grid>
<term:TerminalControl
    x:Name="Terminal"
    BuffSzie="512"
    Focusable="true" />
</Grid>
</Window>

2/ In MainWindow.xaml.cs

using Microsoft.Terminal.Wpf;
using System;
using System.Windows;

namespace WpfApp1
{
    public class EchoConnection : Microsoft.Terminal.Wpf.ITerminalConnection
    {
        public event EventHandler<TerminalOutputEventArgs> TerminalOutput;

        public event EventHandler<TerminalLogOutputEventArgs> TerminalLogOutput;

        public void Resize(uint rows, uint columns)
        {
            return;
        }

        public void Start()
        {
            TerminalOutput.Invoke(this, new TerminalOutputEventArgs("ECHO CONNECTION\r\n^A: toggle printable ESC\r\n^B: toggle SGR mouse mode\r\n^C: toggle win32 input mode\r\n\r\n"));
            return;
        }

        private bool _escapeMode;
        private bool _mouseMode;
        private bool _win32InputMode;
        int count = 0;

        public void WriteInput(string data)
        {
            if (data.Length == 0)
            {
                return;
            }

            if (data[0] == '\x01') // ^A
            {
                _escapeMode = !_escapeMode;
                TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"Printable ESC mode: {_escapeMode}\r\n"));
            }
            else if (data[0] == '\x02') // ^B
            {
                _mouseMode = !_mouseMode;
                var decSet = _mouseMode ? "h" : "l";
                TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"\x1b[?1003{decSet}\x1b[?1006{decSet}"));
                TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"SGR Mouse mode (1003, 1006): {_mouseMode}\r\n"));
            }
            else if ((data[0] == '\x03') ||(data == "\x1b[67;46;3;1;8;1_")) // ^C
            {
                _win32InputMode = !_win32InputMode;
                var decSet = _win32InputMode ? "h" : "l";
                TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"\x1b[?9001{decSet}"));
                TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"Win32 input mode: {_win32InputMode}\r\n"));

                // If escape mode isn't currently enabled, turn it on now.
                if (_win32InputMode && !_escapeMode)
                {
                    _escapeMode = true;
                    TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"Printable ESC mode: {_escapeMode}\r\n"));
                }
            }
            else
            {
                // Echo back to the terminal, but make backspace/newline work properly.
                var str = data.Replace("\r", "\r\n").Replace("\x7f", "\x08 \x08");
                if (_escapeMode)
                {
                    str = str.Replace("\x1b", "\u241b");
                }
                //direct output
                //TerminalOutput.Invoke(this, new TerminalOutputEventArgs(str));
                TerminalLogOutput.Invoke(this, new TerminalLogOutputEventArgs(TerminalLogOutputEventArgs.LogLevel.Verbose, "Verbose test log. User input:" + str));
                TerminalLogOutput.Invoke(this, new TerminalLogOutputEventArgs(TerminalLogOutputEventArgs.LogLevel.Info, "Info test log. User input:" + str));
                TerminalLogOutput.Invoke(this, new TerminalLogOutputEventArgs(TerminalLogOutputEventArgs.LogLevel.Warning, "Warning test log. User input:" + str));
                TerminalLogOutput.Invoke(this, new TerminalLogOutputEventArgs(TerminalLogOutputEventArgs.LogLevel.Error, "Error test log. User input:" + str));
                TerminalLogOutput.Invoke(this, new TerminalLogOutputEventArgs(TerminalLogOutputEventArgs.LogLevel.Fatel, "Fatel test log. User input:" + str));
            }
        }

        public void Close()
        {
            return;
        }

    }

    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Terminal.Loaded += Terminal_Loaded;
        }

        private void Terminal_Loaded(object sender, RoutedEventArgs e)
        {
            var theme = new TerminalTheme
            {
                DefaultBackground = 0x0c0c0c,
                DefaultForeground = 0xcccccc,
                DefaultSelectionBackground = 0xcccccc,
                SelectionBackgroundAlpha = 0.5f,
                CursorStyle = CursorStyle.BlinkingBar,
                // This is Campbell.
                ColorTable = new uint[] { 0x0C0C0C, 0x1F0FC5, 0x0EA113, 0x009CC1, 0xDA3700, 0x981788, 0xDD963A, 0xCCCCCC, 0x767676, 0x5648E7, 0x0CC616, 0xA5F1F9, 0xFF783B, 0x9E00B4, 0xD6D661, 0xF2F2F2 },
            };
            Terminal.Connection = new EchoConnection();
            Terminal.SetTheme(theme, "Cascadia Code", 12);
            Terminal.Focus();
        }

    }
    
}
Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 186 11/11/2023
1.0.0 122 8/29/2023
0.1.5 235 8/28/2023
0.1.4 223 8/28/2023
0.1.3 215 8/28/2023
0.1.2 224 8/28/2023
0.1.1 229 8/28/2023
0.1.0 244 8/28/2023