From f9ea654ffc289a9cd78010ce2dfc56220bffba00 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sat, 22 Mar 2025 11:15:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Tweak=20brew=20output=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improved the accuracy of the brew output. Often, when multiple console messages were returned, the progress prompt in the PHP version manager would display the earliest found step, not the latest, thus unfortunately misrepresenting the progress of the installation steps. This fixes that by reversing the return order, but also extracts relevant information from the commands, too, so that contextual info is now included (for pouring, installing and downloading steps). (This makes it a little bit more transparent for the end user to find out what is taking up all this time. I wish that Homebrew was faster, too, but there's a reason I'm not using statically compiled PHP for this project. Either way, this is a nice QoL change.) --- .../Homebrew/Commands/BrewCommand.swift | 66 +++++++++++++++---- .../SwiftUI/Common/BlockingOverlayView.swift | 2 + phpmon/en.lproj/Localizable.strings | 4 +- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/phpmon/Domain/Integrations/Homebrew/Commands/BrewCommand.swift b/phpmon/Domain/Integrations/Homebrew/Commands/BrewCommand.swift index 2fb1d67..e8a6863 100644 --- a/phpmon/Domain/Integrations/Homebrew/Commands/BrewCommand.swift +++ b/phpmon/Domain/Integrations/Homebrew/Commands/BrewCommand.swift @@ -16,21 +16,65 @@ protocol BrewCommand { extension BrewCommand { internal func reportInstallationProgress(_ text: String) -> (Double, String)? { - if text.contains("Fetching") { + // Special cases: downloading a manifest is effectively fetching metadata + if text.contains("==> Downloading") && text.contains("/manifests/") { return (0.1, "phpman.steps.fetching".localized) } - if text.contains("Downloading") { - return (0.25, "phpman.steps.downloading".localized) - } - if text.contains("Installing") { - return (0.60, "phpman.steps.installing".localized) - } - if text.contains("Pouring") { - return (0.80, "phpman.steps.pouring".localized) - } - if text.contains("Summary") { + + // Logical progress evaluation (reverse order for accuracy) + if text.contains("==> Summary") { return (0.90, "phpman.steps.summary".localized) } + if text.contains("==> Pouring") { + if let subject = extractContext(from: text) { + return (0.80, "phpman.steps.pouring".localized + "\n(\(subject))") + } + return (0.80, "phpman.steps.pouring".localized) + } + if text.contains("==> Installing") { + if let subject = extractContext(from: text) { + return (0.60, "phpman.steps.installing".localized + "\n(\(subject))") + } + return (0.60, "phpman.steps.installing".localized) + } + if text.contains("==> Downloading") { + if let subject = extractContext(from: text) { + return (0.25, "phpman.steps.downloading".localized + "\n(\(subject))") + } + return (0.25, "phpman.steps.downloading".localized) + } + if text.contains("==> Fetching") { + return (0.1, "phpman.steps.fetching".localized) + } + return nil + } + + internal func extractContext(from text: String) -> String? { + var pattern = #""# + if text.contains("==> Fetching") { + pattern = #"==> Fetching (\S+)"# + } + if text.contains("==> Downloading") { + pattern = #"==> Downloading (\S+)"# + } + if text.contains("==> Installing") { + pattern = #"==> Installing (\S+)"# + } + if text.contains("==> Pouring") { + pattern = #"==> Pouring (\S+)"# + } + + guard let regex = try? NSRegularExpression(pattern: pattern) else { + return nil + } + + let range = NSRange(text.startIndex..: View { .bold() .foregroundColor(.primary) .padding(.top, 8) + .multilineTextAlignment(.center) Text(detailText) .font(.system(size: 11)) .foregroundColor(.primary) .padding(.top, -4) + .multilineTextAlignment(.center) }.padding(60) } } diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index d1265ad..cbca9cb 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -201,11 +201,11 @@ You may be asked for your password during the uninstallation process if file per "phpman.operations.updating" = "Installing updates..."; "phpman.operations.installing" = "Installing %@..."; -"phpman.steps.fetching" = "Fetching..."; +"phpman.steps.fetching" = "Fetching some package metadata..."; "phpman.steps.downloading" = "Downloading package data..."; "phpman.steps.installing" = "Installing some package data..."; "phpman.steps.pouring" = "Pouring... This can take a while..."; -"phpman.steps.summary" = "Some package has finished installing..."; +"phpman.steps.summary" = "Please wait a moment..."; "phpman.services.loading" = "Loading..."; "phpman.services.not_installed" = "A key service is not installed.";