-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/5.x'
- Loading branch information
Showing
77 changed files
with
1,528 additions
and
745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Process.swift | ||
// PHP Monitor | ||
// | ||
// Created by Nico Verbruggen on 23/02/2022. | ||
// Copyright © 2022 Nico Verbruggen. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Process { | ||
|
||
/** | ||
When a process is running in the background, it can send content to standard | ||
output or standard error, just like it would in a terminal. Using `listen` | ||
allows us to react whenever data is received by running a particular closure, | ||
depending on which type of data is received. | ||
*/ | ||
public func listen( | ||
didReceiveStandardOutputData: @escaping (String) -> Void, | ||
didReceiveStandardErrorData: @escaping (String) -> Void | ||
) { | ||
let outputPipe = Pipe() | ||
let errorPipe = Pipe() | ||
|
||
self.standardOutput = outputPipe | ||
self.standardError = errorPipe | ||
|
||
[ | ||
(outputPipe, didReceiveStandardOutputData), | ||
(errorPipe, didReceiveStandardErrorData) | ||
].forEach { (pipe: Pipe, callback: @escaping (String) -> Void) in | ||
pipe.fileHandleForReading.waitForDataInBackgroundAndNotify() | ||
NotificationCenter.default.addObserver( | ||
forName: NSNotification.Name.NSFileHandleDataAvailable, | ||
object: pipe.fileHandleForReading, | ||
queue: nil | ||
) { notification in | ||
if let outputString = String(data: pipe.fileHandleForReading.availableData, encoding: String.Encoding.utf8) { | ||
callback(outputString) | ||
} | ||
pipe.fileHandleForReading.waitForDataInBackgroundAndNotify() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
After the process is done running, you'll want to stop listening. | ||
*/ | ||
public func haltListening() { | ||
if let pipe = self.standardOutput as? Pipe { | ||
NotificationCenter.default.removeObserver(pipe.fileHandleForReading) | ||
} | ||
if let pipe = self.standardError as? Pipe { | ||
NotificationCenter.default.removeObserver(pipe.fileHandleForReading) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.