-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
165 lines (137 loc) · 4.87 KB
/
MainWindow.xaml.cs
File metadata and controls
165 lines (137 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using EasyWindowsTerminalControl;
using Microsoft.Terminal.Wpf;
#if WPF
using System.Windows.Media;
using System.Windows;
using System.Windows.Input;
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Windows.System;
using Windows.UI;
using Windows.UI.Core;
using WinUIEx;
using Key = Windows.System.VirtualKey;
using Color = System.Drawing.Color;
using Colors = System.Drawing.Color;
using Microsoft.UI.Xaml.Controls;
#endif
#if WPF
namespace TermExample {
#else
namespace TermExample.WinUI {
internal static class Keyboard {
public static void Focus(this UIElement elem) => elem.Focus(FocusState.Programmatic);
public static bool IsKeyDown(VirtualKey key) => Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
}
#endif
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
/// <summary>
/// when mirror mode is on the duplicate new button still shows the terminal attached to the old window too
/// </summary>
private const bool MirrorMode = false;
public MainWindow() {
InitializeComponent();
#if WPF
DataContext = binds;
#endif
}
DataBinds binds { get; set; } = new();
public MainWindow(TermPTY existingTerm) {
InitializeComponent();
#if WPF
DataContext = binds;
#endif
basicTermControl.DisconnectConPTYTerm();//This should be used but only after the TerminalContainer patch is applied
basicTermControl.ConPTYTerm = existingTerm;
}
public class DataBinds : INotifyPropertyChanged {
public void TriggerPropChanged(string prop) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
public string StartupCommand => "pwsh.exe";
public string WorkingDirectory => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
private static Color AlphaOverrideColor(Color color, byte alphaOverride) => Color.FromArgb(alphaOverride, color.R, color.G, color.B);
private static readonly Color BackroundColor = Color.FromArgb(255, 0, 0, 30);
private static Windows.UI.Color BackroundColorUI => Windows.UI.Color.FromArgb(BackroundColor.A, BackroundColor.R, BackroundColor.G, BackroundColor.B);
public event PropertyChangedEventHandler PropertyChanged;
public SolidColorBrush BackroundColorBrush => new(
#if WPF
BackroundColor
#else
BackroundColorUI
#endif
);
//private TerminalTheme _Theme;
public TerminalTheme Theme { get; set; } = new() {
DefaultBackground = EasyTerminalControl.ColorToVal(BackroundColor),
DefaultForeground = EasyTerminalControl.ColorToVal(Colors.LightYellow),
DefaultSelectionBackground = 0xcccccc,
//SelectionBackgroundAlpha = 0.5f,
CursorStyle = CursorStyle.BlinkingBar,
ColorTable = new uint[] { 0x0C0C0C, 0x1F0FC5, 0x0EA113, 0x009CC1, 0xDA3700, 0x981788, 0xDD963A, 0xCCCCCC, 0x767676, 0x5648E7, 0x0CC616, 0xA5F1F9, 0xFF783B, 0x9E00B4, 0xD6D661, 0xF2F2F2 },
};
}
private async void RefocusKB() {
await Task.Delay(50);
basicTermControl.Focus();
Keyboard.Focus(basicTermControl);
}
private void ShowBufferClicked(object sender, RoutedEventArgs e) {
var msg = basicTermControl.ConPTYTerm.GetConsoleText();
if (Keyboard.IsKeyDown(Key.LeftShift))
basicTermControl.ConPTYTerm.ConsoleOutputLog.Clear();
else
MessageBoxShow(msg);
RefocusKB();
}
private void ClearTermClicked(object sender, RoutedEventArgs e) {
basicTermControl.ConPTYTerm.ClearUITerminal();
RefocusKB();
}
private void RestartTermClicked(object sender, RoutedEventArgs e) {
basicTermControl.RestartTerm();
RefocusKB();
}
private void DuplicateClicked(object sender, RoutedEventArgs e) {
// Don't really recommend doing this basic cloning we will sync our size at least so the positionings are correct.
var wind = new MainWindow(basicTermControl.ConPTYTerm);
if (MirrorMode)
wind.SizeChanged += (sender, _) => MirrorSizeChanged(sender);
else
basicTermControl.DisconnectConPTYTerm();
wind.Show();
}
private void MirrorSizeChanged(object sender) {
var wind = sender as MainWindow;
#if WPF
Width = wind.Width;
Height = wind.Height;
#else
this.AppWindow.Resize(wind.AppWindow.Size);
#endif
}
#if WPF
private void ShowProcessOutputClicked(object sender, RoutedEventArgs e) {
var wind = new ProcessOutput();
wind.Show();
}
private void MessageBoxShow(string msg) => MessageBox.Show(msg);
#else
private async void MessageBoxShow(string msg) {
var dialog = new ContentDialog {
Content = new TextBlock { Text = msg.Replace("\n","\r\n"), TextWrapping = TextWrapping.Wrap },
CloseButtonText = "OK"
};
dialog.XamlRoot = gridMain.XamlRoot;
basicTermControl.Visibility = Visibility.Collapsed;
await dialog.ShowAsync();
basicTermControl.Visibility = Visibility.Visible;
}
#endif
}
}