Skip to content

Commit 3fc330d

Browse files
committed
Added RestartTerm method to the control
1 parent 600cdda commit 3fc330d

File tree

9 files changed

+42
-6
lines changed

9 files changed

+42
-6
lines changed

EasyWindowsTerminalControl.WinUI/EasyWindowsTerminalControl.WinUI.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
77
<UseWinUI>true</UseWinUI>
88
<Platforms>AnyCPU;x64</Platforms>
9-
<Version>1.0.15-beta.1</Version>
9+
<Version>1.0.16-beta.1</Version>
1010
<Description>High performance WinUI3 native terminal/shell control. For WPF version see EasyWindowsTerminalControl alt package. It features full 24-bit color support with ANSI/VT escape sequences (and colors), hardware / GPU accelerated rendering, mouse support, and true console interaction. Support for command shells and key sequences, user interaction and programatic control. See GH for more details.</Description>
1111
<PackageReadmeFile>README.md</PackageReadmeFile>
1212
<Authors>MitchCapper</Authors>
@@ -39,9 +39,11 @@
3939
</ItemGroup>
4040
<ItemGroup>
4141
<PackageReference Include="CI.Microsoft.Windows.Console.ConPTY" Version="1.22.250314001" />
42-
<PackageReference Include="CI.Microsoft.Terminal.WinUI3.Unofficial" Version="1.0.15-beta.1" />
42+
<PackageReference Include="CI.Microsoft.Terminal.WinUI3.Unofficial" Version="1.0.16-beta.1" />
4343
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
4444
<PrivateAssets>all</PrivateAssets>
4545
</PackageReference>
4646
</ItemGroup>
4747
</Project>
48+
49+

EasyWindowsTerminalControl/EasyTerminalControl.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ private void Term_TermReady(object sender, EventArgs e) {
188188
ConPTYTerm.Resize(Terminal.Columns, Terminal.Rows);//fix the size being partially off on first load
189189
});
190190
}
191+
/// <summary>
192+
/// Restarts the command we are running in a brand new term and disposes of the old one
193+
/// </summary>
194+
/// <param name="useTerm">Optional term to use, note if useTerm.TermProcIsStarted this function will not do verry much</param>
195+
/// <param name="disposeOld">True if the old term should be killed off</param>
196+
public async Task RestartTerm(TermPTY useTerm = null, bool disposeOld=true){
197+
var oldTerm = ConPTYTerm;
198+
ConPTYTerm = useTerm ?? new TermPTY();
199+
if (disposeOld){
200+
try{
201+
oldTerm?.CloseStdinToApp();
202+
}catch{ }
203+
try{
204+
oldTerm?.StopExternalTermOnly();
205+
}catch{ }
206+
}
207+
await TermInit();
208+
}
191209
private void StartTerm(int column_width, int row_height) {
192210
if (ConPTYTerm == null)
193211
return;
@@ -206,11 +224,16 @@ private void StartTerm(int column_width, int row_height) {
206224
});
207225
}
208226
private async void Terminal_Loaded(object sender, RoutedEventArgs e) {
227+
await TermInit();
228+
//Terminal.Focus();
229+
}
230+
231+
private async Task TermInit() {
209232
StartTerm(Terminal.Columns, Terminal.Rows);
210233
SetTheme(Theme);
211234
SetCursor(IsCursorVisible);
212235
SetReadOnly(IsReadOnly);
213-
//Terminal.Focus();
236+
214237
await Task.Delay(1000);
215238
SetCursor(IsCursorVisible);
216239
}

EasyWindowsTerminalControl/EasyWindowsTerminalControl.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PlatformTarget>x64</PlatformTarget>
66
<Platforms>x64</Platforms>
77
<UseWpf>true</UseWpf>
8-
<Version>1.0.33</Version>
8+
<Version>1.0.34</Version>
99
<PackageReadmeFile>README.md</PackageReadmeFile>
1010
<PackageOutputPath>../Publish</PackageOutputPath>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -32,3 +32,4 @@
3232

3333

3434
</Project>
35+

Microsoft.Terminal.WinUI3/Microsoft.Terminal.WinUI3.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<BeforePack>CollectNativePackContents</BeforePack>
1111
<Authors>MitchCapper</Authors>
1212
<PackageProjectUrl>https://github.com/MitchCapper/EasyWindowsTerminalControl</PackageProjectUrl>
13-
<Version>1.0.15-beta.1</Version>
13+
<Version>1.0.16-beta.1</Version>
1414
<Description>This is an unofficial WinUI3 recreation of the official Microsoft.Terminal.WPF package. Highly recommend using this with the "EasyWindowsTerminalControl.WinUI".</Description>
1515
<PackageOutputPath>../Publish</PackageOutputPath>
1616
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -96,3 +96,4 @@
9696
</ItemGroup>
9797
</Target>
9898
</Project>
99+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The control has all the standard UserControl properties but it has the following
5959
### Methods
6060
#### EasyTerminalControl
6161
- `DisconnectConPTYTerm()` - Mostly useful if you plan to connect another ConPTYTerm to the frontend
62+
- `RestartTerm(TermPTY useTerm = null, bool disposeOld=true)` - Restarts the process in a clean term with a new TermPTY instance. Can set `useTerm` to use your own TermPTY instance rather than ours. Any properties (ie StartupCommandLine) that have been changed the new version is used.
6263

6364
#### TermPTY
6465
- `TermPTY(int READ_BUFFER_SIZE = 1024 * 16, bool USE_BINARY_WRITER = false, IProcessFactory ProcessFactory=null)` - The read buffer is the maximum that can be read at once, rarely would it need to be changed. By default data is transmitted as UTF8 text however conpty does support binary reading and writing. No matter what mode you use, you can use the `WriteToTerm` or `WriteToTermBinary` functions and it will automatically transform them to bytes/text automatically. Of course if you are working with binary data but don't have binary writing on you will run into problems when it attempts to call Encoding.UTF8.GetString on those bytes. IProcessFactory interface is responsible for creating the actual process. If you need more control you can implement this but please review the default implementation first. There are some [specific things](https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session#preparing-for-creation-of-the-child-process) that must be set or else the console interaction may not work properly.

TermExample.WinUI/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<Button Content="Duplicate New" Click="DuplicateClicked" Margin="5" />
2424
<Button Content="Clear Term" Click="ClearTermClicked" Margin="5" />
25+
<Button Content="Restart Term" Click="RestartTermClicked" Margin="5" />
2526
<Button Content="Show Buffer" Click="ShowBufferClicked" Margin="5" />
2627
</StackPanel>
2728
</Grid>

TermExample.WinUI/TermExample.WinUI.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ItemGroup>
3838
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
3939
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250310001" />
40-
<PackageReference Include="EasyWindowsTerminalControl.WinUI" Version="1.0.15-beta.1" />
40+
<PackageReference Include="EasyWindowsTerminalControl.WinUI" Version="1.0.16-beta.1" />
4141

4242
</ItemGroup>
4343
<ItemGroup>
@@ -72,3 +72,4 @@
7272
<None Remove="Package.appxmanifest" />
7373
</ItemGroup>
7474
</Project>
75+

TermExample/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" >
2424
<Button Content="Duplicate New" Click="DuplicateClicked" Margin="5" />
2525
<Button Content="Clear Term" Click="ClearTermClicked" Margin="5" />
26+
<Button Content="Restart Term" Click="RestartTermClicked" Margin="5" />
2627
<Button Content="Show Buffer" Click="ShowBufferClicked" Margin="5" />
2728
<Button Content="Process Output Sample" Click="ShowProcessOutputClicked" Margin="5" />
2829
</StackPanel>

TermExample/MainWindow.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ private void ClearTermClicked(object sender, RoutedEventArgs e) {
107107
RefocusKB();
108108

109109
}
110+
private void RestartTermClicked(object sender, RoutedEventArgs e) {
111+
basicTermControl.RestartTerm();
112+
RefocusKB();
113+
114+
}
110115

111116

112117
private void DuplicateClicked(object sender, RoutedEventArgs e) {

0 commit comments

Comments
 (0)