Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Header file of SwiftShell (https://github.com/kareman/SwiftShell)
import Foundation
class NSFileHandle {
}
struct String {
}
protocol Streamable {
}
protocol OutputStreamType {
}
extension NSFileHandle : WriteableStreamType {
func write(string: String)
func writeln(string: String)
func writeln()
func closeStream()
}
extension NSFileHandle : ReadableStreamType {
func readSome() -> String?
func read() -> String
func lines() -> SequenceOf<String>
func writeTo<Target : OutputStreamType>(inout target: Target)
}
extension String {
func replace(oldString: String, _ newString: String) -> String
/** Replace the first `limit` occurrences of oldString with newString. */
func replace(oldString: String, _ newString: String, limit: Int) -> String
func split(sep: String) -> [String]
func trim() -> String
func countOccurrencesOf(substring: String) -> Int
/** A lazy sequence of the ranges of `findstring` in this string. */
func findAll(findstring: String) -> SequenceOf<Range<String.Index>>
/**
Split the string at the first occurrence of separator, and return a 3-tuple containing the part
before the separator, the separator itself, and the part after the separator. If the separator is
not found, return a 3-tuple containing the string itself, followed by two empty strings.
*/
func partition(separator: String) -> (String, String, String)
}
infix operator |>> {
associativity left
precedence 50
}
infix operator |> {
associativity left
precedence 50
}
/** Shortcut for in-line command, returns output as String. */
func $(shellcommand: String) -> String
/** Allows for `"/directory" / "file.extension"` etc. */
func /(leftpath: String, rightpath: String) -> String
let File: NSFileManager
typealias FileHandle = NSFileHandle
/** A stream of text. Does as much as possible lazily. */
protocol ReadableStreamType : Streamable {
/**
Whatever amount of text the stream feels like providing.
If the source is a file this will read everything at once.
:returns: more text from the stream, or nil if we have reached the end.
*/
func readSome() -> String?
/** Read everything at once. */
func read() -> String
/** Lazily split the stream into lines. */
func lines() -> SequenceOf<String>
/** Enable stream to be used by "println" and "toString". */
func writeTo<Target : OutputStreamType>(inout target: Target)
}
/** An output stream, like standard output and standard error. */
protocol WriteableStreamType : OutputStreamType {
func write(string: String)
func writeln(string: String)
func writeln()
/** Must be called on local streams when finished writing. */
func closeStream()
}
/** Discard all elements in `tobedropped` from sequence. */
func drop<S : SequenceType, T : Equatable where T == T>(tobedropped: [T])(sequence: S) -> LazySequence<FilterSequenceView<S>>
let environment: [String : String]
/** Lazily return a sequence containing the elements of source, in order, that satisfy the predicate includeElement */
func filter<S : SequenceType>(includeElement: (S.Generator.Element) -> Bool)(source: S) -> LazySequence<FilterSequenceView<S>>
/** Insert separator between each item in elements. */
func join<C : ExtensibleCollectionType, S : SequenceType where C == C>(separator: C)(elements: S) -> C
/** Lazily return a sequence containing the results of mapping transform over source. */
func map<S : SequenceType, T>(transform: (S.Generator.Element) -> T)(source: S) -> LazySequence<MapSequenceView<S, T>>
/**
Open a file for writing, create it if it doesn't exist, and exit if an error occurs.
If the file already exists and overwrite=false, the writing will begin at the end of the file.
:param: overwrite If true, replace the file if it exists.
*/
func open(forWriting path: String, overwrite: Bool = default) -> WriteableStreamType
/** Open a file for reading, and exit if an error occurs. */
func open(path: String) -> ReadableStreamType
/** Turn a sequence into valid parameters for a shell command, properly quoted */
func parameters<S : SequenceType>(sequence: S) -> String
/** Print message to standard error and halt execution. */
@noreturn func printErrorAndExit(errormessage: String)
/**
Return the result of repeatedly calling combine with an accumulated value
initialized to initial and each element of sequence, in turn.
*/
func reduce<S : SequenceType, U>(initial: U, combine: (U, S.Generator.Element) -> U)(sequence: S) -> U
/**
Run a shell command synchronously with no standard input,
or if to the right of a "ReadableStreamType |> ", use the stream on the left side as standard input.
:returns: Standard output
*/
func run(shellcommand: String) -> ReadableStreamType
/**
Return an `Array` containing the sorted elements of `source` according to 'isOrderedBefore'.
Requires: `isOrderedBefore` is a `strict weak ordering
<http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>` over `elements`.
*/
func sorted<S : SequenceType>(isOrderedBefore: (S.Generator.Element, S.Generator.Element) -> Bool)(source: S) -> [S.Generator.Element]
/** Split text over delimiter, returning an array. */
func split(_ delimiter: String = default)(text: String) -> [String]
/** Split a stream lazily */
func split(delimiter: String = default)(stream: ReadableStreamType) -> SequenceOf<String>
let standarderror: WriteableStreamType
let standardinput: ReadableStreamType
let standardoutput: WriteableStreamType
/** Create a stream from a sequence of Strings. */
func stream<Seq : SequenceType where String == String>(sequence: Seq) -> ReadableStreamType
/**
Create a stream from a function returning a generator function, which is called every time the stream is asked for more text.
stream {
// initialisation...
return {
// called repeatedly by the resulting stream
// return text, or return nil when done.
}
}
:returns: The output stream.
*/
func stream(closure: () -> () -> String?) -> ReadableStreamType
/** Create a stream from a String. */
func stream(text: String) -> ReadableStreamType
var streamencoding: UInt
/**
Return a writable stream and a readable stream. What you write to the 1st one can be read from the 2nd one.
Make sure to call closeStream() on the writable stream before you call read() on the readable one.
*/
func streams() -> (WriteableStreamType, ReadableStreamType)
/** Return at most the first `numbertotake` elements of sequence */
func take<S : SequenceType, T where T == T>(numbertotake: Int)(sequence: S) -> [T]
let tempdirectory: String
/** Turn a sequence into an array. For use after the |> operator. */
func toArray<S : SequenceType>(sequence: S) -> [S.Generator.Element]
var workdirectory: String
/**
Write something to a stream.
something |> writeTo(writablestream)
*/
func writeTo<T>(stream: WriteableStreamType)(input: T)
/** Write a String to a writable stream. */
func writeTo(stream: WriteableStreamType)(input: String)
/** Write a sequence to a stream. */
func writeTo<S : SequenceType>(stream: WriteableStreamType)(seq: S)
func |><T, U>(lhs: T, rhs: T -> U) -> U
/**
Specific handling of func run (shellcommand: String) -> ReadableStreamType on the right side using the stream on the
left side as standard input.
Warning: is only meant to be used with the "run" command, but could also unintentionally catch other uses of
"ReadableStreamType |> ReadableStreamType", though that statement doesn't make any sense.
*/
func |>(lhs: ReadableStreamType, rhs: @autoclosure () -> ReadableStreamType) -> ReadableStreamType
/**
Write something to a stream.
something |>> writablestream
*/
func |>><T>(input: T, stream: WriteableStreamType)
/** Write a String to a writable stream. */
func |>>(text: String, stream: WriteableStreamType)
/** Write a sequence to a stream. */
func |>><S : SequenceType>(seq: S, stream: WriteableStreamType)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment