-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from wlsdms0122/develop
[RELEASE] Logma/1.7.0
- Loading branch information
Showing
9 changed files
with
202 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// String+Range.swift | ||
// | ||
// | ||
// Created by jsilver on 2022/01/31. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
var nsRange: NSRange { (self as NSString).range(of: self) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// String+Regex.swift | ||
// | ||
// | ||
// Created by jsilver on 2022/01/25. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
func regex( | ||
_ pattern: String, | ||
regexOptions: NSRegularExpression.Options = [], | ||
matchingOptions: NSRegularExpression.MatchingOptions = [] | ||
) -> [NSTextCheckingResult] { | ||
guard nsRange.length > 0 else { return [] } | ||
|
||
guard let regex = try? NSRegularExpression( | ||
pattern: pattern, | ||
options: regexOptions | ||
) else { return [] } | ||
|
||
return regex.matches( | ||
in: self, | ||
options: matchingOptions, | ||
range: nsRange | ||
) | ||
} | ||
|
||
func regex( | ||
_ pattern: String, | ||
regexOptions: NSRegularExpression.Options = [], | ||
matchingOptions: NSRegularExpression.MatchingOptions = [] | ||
) -> Bool { | ||
let match = regex( | ||
pattern, | ||
regexOptions: regexOptions, | ||
matchingOptions: matchingOptions | ||
) | ||
.first { $0.range == nsRange } | ||
|
||
return match != nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// LogFilterView.swift | ||
// | ||
// | ||
// Created by jsilver on 8/16/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct LogFilterView: View { | ||
// MARK: - View | ||
var body: some View { | ||
let canAddPattern = !pattern.isEmpty && !settings.filterPatterns.contains(pattern) | ||
|
||
List { | ||
Section { | ||
TextField("Regex Pattern", text: $pattern) | ||
.autocorrectionDisabled() | ||
.autocapitalization(.none) | ||
Button { | ||
settings.addFilterPattern(pattern) | ||
pattern = "" | ||
} label: { | ||
Text("Add Filter") | ||
} | ||
.disabled(!canAddPattern) | ||
} footer: { | ||
Text("Filters logs that match the regex pattern.") | ||
} | ||
|
||
if !settings.filterPatterns.isEmpty { | ||
Section { | ||
ForEach(settings.filterPatterns.reversed(), id: \.self) { pattern in | ||
HStack { | ||
Text(pattern) | ||
Spacer() | ||
Button { | ||
shouldRemovePattern = pattern | ||
} label: { | ||
Image(systemName: "trash") | ||
.foregroundColor(.primary) | ||
} | ||
} | ||
.alert(isPresented: .init { | ||
shouldRemovePattern != nil | ||
} set: { isShow in | ||
guard !isShow else { return } | ||
shouldRemovePattern = nil | ||
}) { [shouldRemovePattern] in | ||
Alert( | ||
title: Text("Remove filter pattern"), | ||
message: Text("Are you sure you want to remove filter pattern?"), | ||
primaryButton: .cancel(), | ||
secondaryButton: .destructive(Text("Remove")) { | ||
guard let shouldRemovePattern else { return } | ||
settings.removeFilterPattern(shouldRemovePattern) | ||
} | ||
) | ||
} | ||
} | ||
} header: { | ||
Text("Filters (\(settings.filterPatterns.count))") | ||
} | ||
} | ||
} | ||
.navigationTitle("Log Filter") | ||
.animation(.default, value: settings.filterPatterns) | ||
} | ||
|
||
// MARK: - Property | ||
@State | ||
private var shouldRemovePattern: String? | ||
|
||
@State | ||
private var pattern: String = "" | ||
@StateObject | ||
private var settings: Settings | ||
|
||
// MARK: - Initializer | ||
init(_ settings: Settings) { | ||
self._settings = .init(wrappedValue: settings) | ||
} | ||
|
||
// MARK: - Public | ||
|
||
// MARK: - Private | ||
} | ||
|
||
#if DEBUG | ||
#Preview { | ||
LogFilterView(.init()) | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters