wpf: add a .NET Core WPF Test project for the WPF Control (#6441)

This commit introduces a new project that lets you F5 a working instance
of the Wpf Terminal Control.

To make the experience as seamless as possible, I've introduced another
solution platform called "DotNet_x64Test". It is set to build the WPF
projects for "Any CPU" and every project that PublicTerminalCore
requires (including itself) for "x64". This is the only way to ensure
that when you press F5, all of the native and managed dependencies get
updated.

It's all quite cool when it works.
This commit is contained in:
Dustin L. Howett 2020-06-09 13:41:42 -07:00 committed by GitHub
parent 8b201c1eb0
commit 48b99faed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 430 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,11 @@ try
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
CATCH_LOG()
catch (...)
{
LOG_CAUGHT_EXCEPTION();
return 0;
}
static bool RegisterTermClass(HINSTANCE hInstance) noexcept
{

View File

@ -0,0 +1,9 @@
<Application x:Class="WpfTerminalTestNetCore.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfTerminalTestNetCore"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,22 @@
// <copyright file="App.xaml.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// </copyright>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfTerminalTestNetCore
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@ -0,0 +1,15 @@
// <copyright file="AssemblyInfo.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// </copyright>
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,13 @@
<Window x:Class="WpfTerminalTestNetCore.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfTerminalTestNetCore"
xmlns:term="clr-namespace:Microsoft.Terminal.Wpf;assembly=Microsoft.Terminal.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<term:TerminalControl x:Name="Terminal" Focusable="true" />
</Grid>
</Window>

View File

@ -0,0 +1,96 @@
// <copyright file="MainWindow.xaml.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// </copyright>
using Microsoft.Terminal.Wpf;
using System;
using System.Windows;
namespace WpfTerminalTestNetCore
{
public class EchoConnection : Microsoft.Terminal.Wpf.ITerminalConnection
{
public event EventHandler<TerminalOutputEventArgs> TerminalOutput;
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;
public void WriteInput(string data)
{
if (data.Length > 0 && data[0] == '\x01') // ^A
{
_escapeMode = !_escapeMode;
TerminalOutput.Invoke(this, new TerminalOutputEventArgs($"Printable ESC mode: {_escapeMode}\r\n"));
}
else if (data.Length > 0 && 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.Length > 0 && data[0] == '\x03') // ^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"));
}
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");
}
TerminalOutput.Invoke(this, new TerminalOutputEventArgs(str));
}
}
public void Close()
{
return;
}
}
/// <summary>
/// Interaction logic for 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,
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();
}
}
}

View File

@ -0,0 +1,8 @@
{
"profiles": {
"Local Debugging": {
"commandName": "Project",
"nativeDebugging": true
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src\cascadia\PublicTerminalCore\PublicTerminalCore.vcxproj" />
<ProjectReference Include="$(SolutionDir)src\cascadia\WpfTerminalControl\WpfTerminalControl.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="$(SolutionDir)bin\x64\$(Configuration)\PublicTerminalCore.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>