Skip to content

Commit

Permalink
Add inverted grep
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrietS committed Oct 15, 2024
1 parent 5f98b75 commit feb7de6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/LogAlligator.App/Controls/FileView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public async void AddGrep()
try
{
_grepDialog = new GrepDialog();
var pattern = await _grepDialog.ShowDialog<SearchPattern?>((this.VisualRoot as Window)!);
Log.Debug("Grep pattern: {pattern}", pattern);
var (pattern, inverted) = await _grepDialog.ShowDialog<(SearchPattern?, bool)>((this.VisualRoot as Window)!);
Log.Debug("Grep pattern: {pattern}, inverted: {inverted}", pattern, inverted);
if (pattern != null)
SelectedLogView?.AddGrep(pattern);
SelectedLogView?.AddGrep(pattern, inverted);
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion src/LogAlligator.App/Controls/GrepDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Separator Height="6" Background="Transparent"/>
<CheckBox Name="RegexCheckBox">Regular expression</CheckBox>
<CheckBox Name="CaseInsensitiveCheckBox" IsChecked="True">Case insensitive</CheckBox>
<CheckBox Name="InvertedCheckBox" IsEnabled="False">Inverted</CheckBox>
<CheckBox Name="InvertedCheckBox">Inverted</CheckBox>
<StackPanel FlowDirection="RightToLeft" Orientation="Horizontal" Spacing="5">
<Button Click="OnCancelClick" Width="60">Cancel</Button>
<Button Click="OnOkClick" Width="60" IsDefault="True">OK</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/LogAlligator.App/Controls/GrepDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void OnOkClick(object? sender, RoutedEventArgs e)
Close(null);

SearchPattern pattern = new(GrepTextBox.Text.AsMemory(), caseSensitive: CaseSensitive, regex: Regex);
Close(pattern);
Close((pattern, Inverted));
}

private void OnCancelClick(object? sender, RoutedEventArgs e)
Expand Down
6 changes: 4 additions & 2 deletions src/LogAlligator.App/Controls/LogView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ internal void Initialize(ILineProvider lineProvider, Highlights highlights, Book
TextView.Initialize(lineProvider, highlights, bookmarks);
}

internal void AddGrep(SearchPattern pattern)
internal void AddGrep(SearchPattern pattern, bool inverted = false)
{
bool ShouldKeepLine(string line) => pattern.Match(line.AsMemory()) != inverted;

var logView = new LogView();
var newLineProvider = _lineProvider.Grep(line => pattern.Match(line.AsMemory()));
var newLineProvider = _lineProvider.Grep(ShouldKeepLine);
logView.Initialize(newLineProvider, _highlights!, _bookmarks!);
Tabs.Items.Add(new TabItem { Header = pattern, Content = logView });
}
Expand Down

0 comments on commit feb7de6

Please sign in to comment.