Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Show each line of what Homebrew found whole

Țugui Dragoșb93f6ba9e7f9
diff --git a/Peel/Views/Homebrew/HomebrewFindingRow.swift b/Peel/Views/Homebrew/HomebrewFindingRow.swift
index b8ed460a..96891bae 100644
--- a/Peel/Views/Homebrew/HomebrewFindingRow.swift
+++ b/Peel/Views/Homebrew/HomebrewFindingRow.swift
@@ -3,8 +3,8 @@ import SwiftUI
/// A row showing one thing `brew doctor` found.
///
-/// The first line of Homebrew's text is the summary, and the lines after it, usually paths, are listed under
-/// it. Then come Homebrew's advice and each command it suggests, with a Copy button beside each command.
+/// The first line of Homebrew's text is the summary, and the lines after it, paths or Homebrew's own sentences, are
+/// listed under it. Then come Homebrew's advice and each command it suggests, with a Copy button beside each command.
struct HomebrewFindingRow: View {
let finding: HomebrewFinding
@@ -19,12 +19,7 @@ struct HomebrewFindingRow: View {
.font(.callout.weight(.medium))
.textSelection(.enabled)
ForEach(Array(details.enumerated()), id: \.offset) { _, line in
- Text(verbatim: line)
- .font(.caption.monospaced())
- .foregroundStyle(.secondary)
- .lineLimit(1)
- .truncationMode(.middle)
- .textSelection(.enabled)
+ HomebrewFindingLine(line: line)
}
if let remedy {
Text(verbatim: remedy)
@@ -70,3 +65,16 @@ struct HomebrewFindingRow: View {
finding.remedy?.replacingOccurrences(of: "`", with: "")
}
}
+
+/// A line of Homebrew's text under a finding's summary, shown whole: it can be a sentence as well as a path.
+struct HomebrewFindingLine: View {
+ let line: String
+
+ var body: some View {
+ Text(verbatim: line)
+ .font(.caption.monospaced())
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ .textSelection(.enabled)
+ }
+}
diff --git a/PeelTests/HomebrewFindingRowTests.swift b/PeelTests/HomebrewFindingRowTests.swift
new file mode 100644
index 00000000..96bfe1e9
--- /dev/null
+++ b/PeelTests/HomebrewFindingRowTests.swift
@@ -0,0 +1,39 @@
+import AppKit
+@testable import Peel
+import SwiftUI
+import Testing
+
+@MainActor
+struct HomebrewFindingRowTests {
+ private final class Frame {
+ var size: CGSize = .zero
+ }
+
+ private static let line = "Command-line tools using this file may accept forged TLS certificates:"
+
+ @Test func aLineOfHomebrewsTextUnderItsSummaryIsShownWhole() async {
+ let frame = Frame()
+ let list = List {
+ HomebrewFindingLine(line: Self.line)
+ .onGeometryChange(for: CGSize.self) { $0.size } action: { frame.size = $0 }
+ }
+ let window = NSWindow(
+ contentRect: NSRect(x: 0, y: 0, width: ListColumn.width, height: 400), styleMask: [.titled],
+ backing: .buffered, defer: true
+ )
+ window.contentView = NSHostingView(rootView: list)
+
+ for _ in 0..<200 where frame.size == .zero {
+ window.layoutIfNeeded()
+ try? await Task.sleep(for: .milliseconds(5))
+ }
+
+ let caption = NSFont.preferredFont(forTextStyle: .caption1).pointSize
+ let needed = (Self.line as NSString).boundingRect(
+ with: CGSize(width: frame.size.width, height: 10_000), options: [.usesLineFragmentOrigin, .usesFontLeading],
+ attributes: [.font: NSFont.monospacedSystemFont(ofSize: caption, weight: .regular)]
+ ).height
+ #expect(frame.size.width > 0)
+ #expect(frame.size.height + 1 >= needed.rounded(.up))
+ }
+}