mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-06 03:20:09 +02:00
🔧 Tweak brew output parsing
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.)
This commit is contained in:
@ -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..<text.endIndex, in: text)
|
||||
if let match = regex.firstMatch(in: text, options: [], range: range) {
|
||||
if let formulaRange = Range(match.range(at: 1), in: text) {
|
||||
return String(text[formulaRange])
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -38,10 +38,12 @@ struct BlockingOverlayView<Content: View>: View {
|
||||
.bold()
|
||||
.foregroundColor(.primary)
|
||||
.padding(.top, 8)
|
||||
.multilineTextAlignment(.center)
|
||||
Text(detailText)
|
||||
.font(.system(size: 11))
|
||||
.foregroundColor(.primary)
|
||||
.padding(.top, -4)
|
||||
.multilineTextAlignment(.center)
|
||||
}.padding(60)
|
||||
}
|
||||
}
|
||||
|
@ -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.";
|
||||
|
Reference in New Issue
Block a user