Skip to content

Commit 655e384

Browse files
committed
Add RegexFilter config option
1 parent ee51b2e commit 655e384

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

Background-Terminal/BackgroundTerminalSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class BackgroundTerminalSettings
1717
public double PosY { get; set; }
1818
public double Width { get; set; }
1919
public double Height { get; set; }
20+
public string RegexFilter { get; set; }
2021
public List<NewlineTrigger> NewlineTriggers { get; set; }
2122
}
2223
}

Background-Terminal/MainWindow.xaml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:tb="http://www.hardcodet.net/taskbar"
88
Title="Background Terminal"
99
Width="400"
10-
Height="450"
10+
Height="480"
1111
AllowsTransparency="True"
1212
Background="Transparent"
1313
Closed="MainWindow_Closed"
@@ -180,6 +180,7 @@
180180
<RowDefinition Height="30" />
181181
<RowDefinition Height="30" />
182182
<RowDefinition Height="30" />
183+
<RowDefinition Height="30" />
183184
<RowDefinition Height="10" />
184185
<RowDefinition Height="30" />
185186
<RowDefinition Height="30" />
@@ -188,7 +189,7 @@
188189
<RowDefinition Height="100" />
189190
<RowDefinition Height="30" />
190191
</Grid.RowDefinitions>
191-
<Border Grid.RowSpan="11" Background="#F5F5F5" />
192+
<Border Grid.RowSpan="12" Background="#F5F5F5" />
192193
<Grid Grid.Row="0">
193194
<Grid.ColumnDefinitions>
194195
<ColumnDefinition Width="1*" />
@@ -290,13 +291,30 @@
290291
VerticalContentAlignment="Center" />
291292
</Grid>
292293
<Grid Grid.Row="5">
294+
<Grid.ColumnDefinitions>
295+
<ColumnDefinition Width="1*" />
296+
<ColumnDefinition Width="1*" />
297+
</Grid.ColumnDefinitions>
298+
<Label
299+
Grid.Column="0"
300+
VerticalAlignment="Center"
301+
HorizontalContentAlignment="Center"
302+
Content="Regex Filter:"
303+
FontFamily="Yu Gothic UI Light" />
304+
<TextBox
305+
x:Name="RegexFilter_TextBox"
306+
Grid.Column="1"
307+
Margin="10,5,10,5"
308+
VerticalContentAlignment="Center" />
309+
</Grid>
310+
<Grid Grid.Row="6">
293311
<Border
294312
Height="1"
295313
Margin="10,0,10,0"
296314
BorderBrush="Gray"
297315
BorderThickness="1" />
298316
</Grid>
299-
<Grid Grid.Row="6">
317+
<Grid Grid.Row="7">
300318
<Grid.ColumnDefinitions>
301319
<ColumnDefinition Width="1*" />
302320
<ColumnDefinition Width="1*" />
@@ -317,7 +335,7 @@
317335
Style="{StaticResource StandardButton1}" />
318336
</Grid>
319337
</Grid>
320-
<Grid Grid.Row="7">
338+
<Grid Grid.Row="8">
321339
<Grid.ColumnDefinitions>
322340
<ColumnDefinition Width="1*" />
323341
<ColumnDefinition Width="1*" />
@@ -360,7 +378,7 @@
360378
FontFamily="Yu Gothic UI" />
361379
</Grid>
362380
</Grid>
363-
<Grid Grid.Row="8">
381+
<Grid Grid.Row="9">
364382
<Grid.ColumnDefinitions>
365383
<ColumnDefinition Width="1*" />
366384
<ColumnDefinition Width="1*" />
@@ -403,14 +421,14 @@
403421
FontFamily="Yu Gothic UI" />
404422
</Grid>
405423
</Grid>
406-
<Grid Grid.Row="9">
424+
<Grid Grid.Row="10">
407425
<Border
408426
Height="1"
409427
Margin="10,0,10,0"
410428
BorderBrush="Gray"
411429
BorderThickness="1" />
412430
</Grid>
413-
<Grid Grid.Row="10">
431+
<Grid Grid.Row="11">
414432
<Grid.RowDefinitions>
415433
<RowDefinition Height="30" />
416434
<RowDefinition Height="1*" />
@@ -489,7 +507,7 @@
489507
</ListBox.ItemTemplate>
490508
</ListBox>
491509
</Grid>
492-
<Grid Grid.Row="11">
510+
<Grid Grid.Row="12">
493511
<Grid.ColumnDefinitions>
494512
<ColumnDefinition Width="1*" />
495513
<ColumnDefinition Width="1" />

Background-Terminal/MainWindow.xaml.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.IO;
1010
using System.Linq;
1111
using System.Management;
12+
using System.Text;
1213
using System.Text.RegularExpressions;
1314
using System.Threading.Tasks;
1415
using System.Windows;
@@ -67,6 +68,9 @@ public partial class MainWindow : Window {
6768
private Key? _key1 = null;
6869
private Key? _key2 = null;
6970

71+
// Filter to apply to output
72+
private Regex _regex;
73+
7074
#region Constructor
7175
public MainWindow() {
7276
InitializeComponent();
@@ -83,7 +87,11 @@ public MainWindow() {
8387
{
8488
foreach (string newItem in target.NewItems)
8589
{
86-
_terminalWindow.TerminalData_TextBox.AppendText(newItem + Environment.NewLine);
90+
if (_regex != null) {
91+
_terminalWindow.TerminalData_TextBox.AppendText(_regex.Replace(newItem, "") + Environment.NewLine);
92+
} else {
93+
_terminalWindow.TerminalData_TextBox.AppendText(newItem + Environment.NewLine);
94+
}
8795
}
8896

8997
_terminalWindow.TerminalData_TextBox.ScrollToEnd();
@@ -119,6 +127,7 @@ public MainWindow() {
119127
PosY_TextBox.Text = _settings.PosY.ToString();
120128
Width_TextBox.Text = _settings.Width.ToString();
121129
Height_TextBox.Text = _settings.Height.ToString();
130+
RegexFilter_TextBox.Text = _settings.RegexFilter;
122131

123132
if (_settings.NewlineTriggers == null)
124133
_settings.NewlineTriggers = new List<NewlineTrigger>();
@@ -506,6 +515,14 @@ private void ApplyChangesButton_Click(object sender, RoutedEventArgs e) {
506515
return;
507516
}
508517

518+
try {
519+
_regex = new Regex(RegexFilter_TextBox.Text);
520+
} catch {
521+
System.Windows.MessageBox.Show("There was an error interpreting the regex filter");
522+
return;
523+
}
524+
525+
509526
_settings.Key1 = KeyInterop.VirtualKeyFromKey((Key)_key1);
510527
_settings.Key2 = KeyInterop.VirtualKeyFromKey((Key)_key2);
511528
_settings.FontSize = fontSize;
@@ -514,6 +531,7 @@ private void ApplyChangesButton_Click(object sender, RoutedEventArgs e) {
514531
_settings.PosY = posY;
515532
_settings.Width = width;
516533
_settings.Height = height;
534+
_settings.RegexFilter = RegexFilter_TextBox.Text;
517535

518536
_settings.NewlineTriggers = new List<NewlineTrigger>(NewlineTriggers);
519537

0 commit comments

Comments
 (0)