Skip to content

Commit

Permalink
Merge pull request #28 from vapor/alpha
Browse files Browse the repository at this point in the history
updating console
  • Loading branch information
loganwright authored Feb 16, 2017
2 parents 88e7b23 + bb61263 commit eb11005
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ let package = Package(
// Target(name: "ConsoleExample", dependencies: ["Console"])
],
dependencies: [
.Package(url: "https://github.com/vapor/polymorphic.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/core.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/polymorphic.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"])),
.Package(url: "https://github.com/vapor/core.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"])),
],
exclude: [
"Sources/ConsoleExample"
Expand Down
21 changes: 6 additions & 15 deletions Sources/Console/Bar/Loading/LoadingBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import Core
finish()
Loading Item [Done]
*/
public class LoadingBar: Bar {
var thread: Strand?
public final class LoadingBar: Bar {
var current: Int
var inc: Int
let cycles: Int
var running: Bool
private var running: Bool

public override init(console: ConsoleProtocol, title: String, width: Int, barStyle: ConsoleStyle, titleStyle: ConsoleStyle) {
current = -1
Expand Down Expand Up @@ -55,11 +54,6 @@ public class LoadingBar: Bar {

func stop() {
running = false
do {
try thread?.cancel()
} catch {
//
}
}

override var bar: String {
Expand All @@ -86,14 +80,11 @@ public class LoadingBar: Bar {

public func start() {
#if !NO_ANIMATION
do {
thread = try Strand { [weak self] in
while true {
self?.update()
}
background { [weak self] in
guard let welf = self else { return }
while welf.running {
self?.update()
}
} catch {
console.info("[Loading]")
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Console/Console/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ extension ConsoleProtocol {
} catch ConsoleError.execute(let result) {
close(error.fileHandleForWriting.fileDescriptor)
close(output.fileHandleForWriting.fileDescriptor)
let error = try error.fileHandleForReading.readDataToEndOfFile().makeBytes()
let output = try output.fileHandleForReading.readDataToEndOfFile().makeBytes()
let error = error.fileHandleForReading.readDataToEndOfFile().makeBytes()
let output = output.fileHandleForReading.readDataToEndOfFile().makeBytes()

throw ConsoleError.backgroundExecute(code: result, error: error, output: output)
}

close(output.fileHandleForWriting.fileDescriptor)
return try output.fileHandleForReading.readDataToEndOfFile().makeBytes()
return output.fileHandleForReading.readDataToEndOfFile().makeBytes()
}

public func backgroundExecute<Type: BytesInitializable>(program: String, arguments: [String]) throws -> Type {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Console/Utilities/Bool+Polymorphic.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Polymorphic

extension Bool: Polymorphic {
public var bytes: [UInt8]? {
return self ? [0x01] : [0x00]
}

public var isNull: Bool {
return false
}
Expand Down

0 comments on commit eb11005

Please sign in to comment.