Tools
Description
Ashen // Swift Text UI
During a hackathon at the try! Swift conference, way back in 2015 I thought it would be useful for Swift to gain a Terminal application framework, and I was very much into Elm at that time, and so I started work on "Ashen".
There was a v1 that wasn't purely functional, then a rewrite... and then I moved on to writing React Native and TypeScript day-to-day, so this project has sadly languished. But it's actually really quite good (if it still compiles). But my attention has shifted to TeaUI, which is optimized for rendering via React or Preact instead of modeling itself after Elm... but I may change my mind on that, because the Elm Architecture is so good.
example:
case received(Result<(Int, Headers, Data), HttpError>)
case quit
}
func initial() -> Initial<Model, Message> {
let url = URL(string: "http://example.com")!
let cmd = Http.get(url) { result in
Message.received(result)
}
return Initial(Model(), cmd)
}
func update(model: Model, message: Message)
-> State<Model, Message>
{
switch message {
case let .received(result):
// swift doesn't have a great "merge" mechanism
// for structs
return .model(model.withResult(result))
case .quit
return .quit
}
}
func view(model: Model) -> [View<Message>] {
[
OnKeyPress(.enter, { Message.quit }),
Frame(Spinner(), .alignment(.middleCenter)),
])
}
try ashen(Program(initial, update, view))
[G] https://github.com/colinta/Ashen
Video tutorial