Skip to content

Commit

Permalink
deps: upgrade rainbow from 3.0.0 to 4.0.0 (#47)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dominicegginton authored Nov 6, 2023
1 parent d47c588 commit 16ac0c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
15 changes: 11 additions & 4 deletions Sources/Spinner/Spinner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 16ac0c4

Please sign in to comment.