From 16ac0c404320005936579f1d6454bb88dbd8d71a Mon Sep 17 00:00:00 2001 From: Dom Egginton Date: Mon, 6 Nov 2023 09:42:59 +0000 Subject: [PATCH] deps: upgrade rainbow from 3.0.0 to 4.0.0 (#47) The `Rainbow.extractModes` method is now depreceted. We should use `Rainbow.extractModes(from:)` instead. This returns a `Rainbow.Entry` object that contains the nodes. We implment an internal `Spinner.entryLength` that returns the length of the `Rainbow.Entry` object to enable us to us to calulate the padding of messages and animations. --- Package.swift | 2 +- Sources/Spinner/Spinner.swift | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index bbb48ff..5e1858e 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/dominicegginton/Nanoseconds", from: "1.1.2"), - .package(url: "https://github.com/onevcat/Rainbow", from: "3.0.0"), + .package(url: "https://github.com/onevcat/Rainbow", from: "4.0.0"), .package(url: "https://github.com/IBM-Swift/BlueSignals.git", from: "1.0.0") ], targets: [ diff --git a/Sources/Spinner/Spinner.swift b/Sources/Spinner/Spinner.swift index 9411dc9..70a6186 100644 --- a/Sources/Spinner/Spinner.swift +++ b/Sources/Spinner/Spinner.swift @@ -201,9 +201,16 @@ public final class Spinner { self.stop(frame: "ℹ", message: message, color: .blue) } + func entryLength(entry: Rainbow.Entry) -> Int { + if let segment = entry.segments.first { + return segment.text.count + } + return 0 + } + func padding(_ message: String) -> Int { - let new = Rainbow.extractModes(for: message).text.count - let old = Rainbow.extractModes(for: self.message).text.count + let new = entryLength(entry: Rainbow.extractEntry(for: message)) + let old = entryLength(entry: Rainbow.extractEntry(for: self.message)) let diff: Int = old - new if diff > 0 { return diff @@ -213,8 +220,8 @@ public final class Spinner { } func padding(_ animation: SpinnerAnimation) -> Int { - let new: Int = Rainbow.extractModes(for: animation.frames[0]).text.count - let old: Int = Rainbow.extractModes(for: self.animation.frames[0]).text.count + let new = entryLength(entry: Rainbow.extractEntry(for: animation.frames[0])) + let old = entryLength(entry: Rainbow.extractEntry(for: self.animation.frames[0])) let diff: Int = old - new if diff > 0 { return diff