Skip to content

Commit

Permalink
[#560] Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
markgravity committed Aug 7, 2024
1 parent 21baae2 commit 5d7cb8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import ANSITerminal

enum WriteStyle {

case section
case success
case error
case warning
}

func write(_ text: String, style: WriteStyle) {
switch style {
case .section:
writeln("-------------------".green)
writeln(text.green)
writeln("-------------------".green)
case .success:
writeln(text.green)
case .error:
Expand Down Expand Up @@ -105,23 +100,27 @@ private func getWroteLineCount(_ text: String) -> Int {
private func unexpand(text: String) -> String {
var result = ""
var spaceCount = 0

func appendSpacesAndTabs() {
result.append(String(repeating: "\t", count: spaceCount / 8))
result.append(String(repeating: " ", count: spaceCount % 8))
spaceCount = 0
}

for char in text {
if char == " " {
spaceCount += 1
} else {
if spaceCount > 0 {
let tabs = String(repeating: "\t", count: spaceCount / 8)
let spaces = String(repeating: " ", count: spaceCount % 8)
result += tabs + spaces
spaceCount = 0
appendSpacesAndTabs()
}
result += String(char)
}
}

if spaceCount > 0 {
let tabs = String(repeating: "\t", count: spaceCount / 8)
let spaces = String(repeating: " ", count: spaceCount % 8)
result += tabs + spaces
appendSpacesAndTabs()
}

return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct SetUpCICDService {
var title: String {
switch self {
case .github:
"Github"
"GitHub"
case .bitrise:
"Bitrise"
case .codemagic:
Expand All @@ -47,7 +47,7 @@ struct SetUpCICDService {
init?(_ name: String) {
let mappings: [String: Self] = [
"m": .macOSLatest,
"macos": .macOSLatest,
"macos-latest": .macOSLatest,
"s": .selfHosted,
"self-hosted": .selfHosted,
"l": .later,
Expand All @@ -65,7 +65,7 @@ struct SetUpCICDService {
var title: String {
switch self {
case .macOSLatest:
"macos"
"macos-latest"
case .selfHosted:
"self-hosted"
case .later:
Expand Down

0 comments on commit 5d7cb8c

Please sign in to comment.