Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
peel hides line separators and direction controls in names too
Țugui Dragoșe8564e1dad81
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swiftindex 309d9d41..09d12850 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift@@ -50,7 +50,7 @@ public struct PeelCommand: AsyncParsableCommand {}}- /// Writes a failure of Peel's own as a note, where every control character is shown as `?`: its message names+ /// Writes a failure of Peel's own as a note, where what could hide or reorder text is shown as `?`: it names/// apps and paths from other people's bundles. Any other error is left for ArgumentParser to print.@discardableResultstatic func report(_ error: any Error) -> Bool {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex f56e15a0..237f4eca 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -45,7 +45,8 @@ enum Output {write(plain(text) + "\n")}- /// Replaces every control character with `?` (`PlainText`), for names and paths from other people's bundles.+ /// Replaces every character that could hide or reorder text with `?` (`PlainText`), for names and paths from+ /// other people's bundles.static func plain(_ text: String) -> String {PlainText.of(text)}@@ -72,7 +73,7 @@ enum Output {}/// Writes `text` to standard error, which is for the person reading, not for a script. Newlines are kept, and- /// every other control character is replaced with `?`.+ /// every other character `plain` hides is replaced with `?`.static func note(_ text: String) {let lines = text.split(separator: "\n", omittingEmptySubsequences: false).map { plain(String($0)) }let written = lines.joined(separator: "\n") + "\n"diff --git a/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift b/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swiftindex ea3a02b9..40c7866c 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/PlainText.swift@@ -1,14 +1,20 @@/// Text from someone else's bundle made safe to show: a name, a version or a path can hold any character, and a/// line end in one would make a script read one row as two, while an escape sequence could rewrite on screen the-/// list the user is asked to confirm.+/// list the user is asked to confirm, and a direction control could show a path in another order than it has.public enum PlainText {- /// `text` with every control character replaced with `?`.+ /// `text` with every control character, format character, and line or paragraph separator replaced with `?`.public static func of(_ text: String) -> String {- guard text.unicodeScalars.contains(where: isControl) else { return text }- return String(text.unicodeScalars.map { isControl($0) ? "?" : Character($0) })+ guard text.unicodeScalars.contains(where: isHidden) else { return text }+ return String(text.unicodeScalars.map { isHidden($0) ? "?" : Character($0) })}- static func isControl(_ scalar: Unicode.Scalar) -> Bool {- scalar.value <= 0x1F || (0x7F...0x9F).contains(scalar.value)+ /// The zero width non-joiner and joiner stay: they only join the letters or emoji around them, which Persian,+ /// the Indic scripts and emoji sequences need.+ static func isHidden(_ scalar: Unicode.Scalar) -> Bool {+ switch scalar.properties.generalCategory {+ case .control, .lineSeparator, .paragraphSeparator: true+ case .format: scalar != "\u{200C}" && scalar != "\u{200D}"+ default: false+ }}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PlainTextTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PlainTextTests.swiftnew file mode 100644index 00000000..df6dccd9--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/PlainTextTests.swift@@ -0,0 +1,25 @@+@testable import PeelCore+import Testing++struct PlainTextTests {+ /// Unicode's own line and paragraph separators end a line for a script as a newline does, and the+ /// bidirectional controls can show a path in another order than it has.+ @Test func showsLineSeparatorsAndDirectionControlsAsQuestionMarks() {+ #expect(PlainText.of("Orphan\u{2028}com.apple.Mail") == "Orphan?com.apple.Mail")+ #expect(PlainText.of("Orphan\u{2029}Folder") == "Orphan?Folder")+ #expect(PlainText.of("/Users/me/\u{202E}gpj.app") == "/Users/me/?gpj.app")+ #expect(PlainText.of("\u{2066}Evil\u{2069}") == "?Evil?")+ #expect(PlainText.of("\u{200F}Evil\u{FEFF}") == "?Evil?")+ #expect(PlainText.of("Evil\u{E0041}\u{E0042}") == "Evil??")+ #expect(PlainText.of("Evil\u{1B}[2J\u{85}\t") == "Evil?[2J??")+ }++ /// The joiners only join the letters or emoji around them, which Persian, the Indic scripts and emoji+ /// sequences need, so they stay, as letters, marks and spaces do.+ @Test func keepsTheJoinersAndEverythingPrintable() {+ let names = ["می\u{200C}خواهم", "क्\u{200D}ष", "👩\u{200D}💻 Studio", "Café", "e\u{301}", "日本語 アプリ", "Editor Pro 2"]+ for name in names {+ #expect(PlainText.of(name) == name)+ }+ }+}