-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dd620ad
Showing
47 changed files
with
2,551 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
attic/* | ||
dist | ||
dist-newstyle | ||
result* | ||
.stack-work | ||
.ghc.environment* | ||
cabal.project.local | ||
*.cast |
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,30 @@ | ||
Copyright Richard Marko (c) 2020 | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Author name here nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,96 @@ | ||
# polytype | ||
|
||
**🚧 Work in progress 🚧** | ||
|
||
## What is this? | ||
|
||
* Polymorphic [Teletype][teletype] | ||
* Library for interacting with | ||
* programs | ||
* programs running in POXIS pseudo terminals via [posix-pty][hackage:posix-pty] | ||
* serial terminals via [serialport][hackage:serialport] | ||
* Expect on steroids | ||
* Program interaction library with [Asciinema][asciinema] recorder | ||
* My first [polysemy] endeavour and a playground (for now) | ||
* Collection of useful effects related to the topic | ||
|
||
## What is it good for? | ||
|
||
* Interacting with and testing other programs | ||
* Testing of terminal UIs | ||
* Making demos of terminal UIs with [Asciinema][asciinema] [asciicast][asciicast] output | ||
* Testing hardware (or virtual machines) over serial connection | ||
* Streaming inputs and outputs of programs, terminals, serial connections | ||
* Variations of the previous ones | ||
|
||
## Why? | ||
|
||
To explore effect systems and polymorphic IO automation framework. Originally the project | ||
was called `multitype`, based on `Free` monads which proved difficult to interpret with | ||
all the required bits like `async` and `timeout`. | ||
Later it was rewritten using `transformers` but never released because it still felt too | ||
opinionated about the use of e.g. character vs line based input or `Text` vs `ByteString` | ||
specialization. | ||
|
||
This library tries to be much less picky about the type of its inputs and outputs | ||
allowing the user to choose what types to work with or convert between different | ||
[Teletypes](src/Polytype/Teletype.hs). | ||
[polysemy]s effect system allows the user to write programs using | ||
the same eDSL and choosing interpreters according to the target environment. | ||
|
||
## Examples | ||
|
||
```haskell | ||
import Polytype | ||
|
||
main :: IO () | ||
main = | ||
. runM | ||
. teletypeToIO | ||
. runLogShow | ||
. teletypeLog | ||
$ do | ||
writeTTY "Type something" | ||
i <- readTTY | ||
writeTTY $ "You wrote: " ++ i | ||
``` | ||
|
||
### Provided examples | ||
|
||
* [bash](src/Polytype/Examples/Bash.hs) | ||
* [echo](src/Polytype/Examples/Echo.hs) | ||
* [htop demo](src/Polytype/Examples/HtopAsciinema.hs) | ||
* [ircbridge test](src/Polytype/Examples/IRCBridge.hs) | ||
* [process](src/Polytype/Examples/Process.hs) | ||
* [safe process](src/Polytype/Examples/SafeProcess.hs) | ||
* [streaming](src/Polytype/Examples/Streaming.hs) | ||
|
||
### Asciinema output | ||
|
||
* Watch the htop demo [recording](https://asciinema.org/a/343380) | ||
|
||
## Development status | ||
|
||
Types of effects are in pretty good shape. Names and interpreters are subject to change. | ||
|
||
The library grew quite a bit since the work started and some parts will be split into | ||
sub-packages. | ||
|
||
## Related work | ||
|
||
Inspired by: | ||
|
||
* [teletype] | ||
* [polysemy] | ||
* [polysemys Teletype example][hackage:polysemy] | ||
* [co-log]s polymorphic logger effect | ||
* and few other bits credited in source files | ||
|
||
[co-log]: https://github.com/kowainik/co-log/ | ||
[polysemy]: https://github.com/polysemy-research/polysemy | ||
[hackage:polysemy]: https://github.com/polysemy-research/polysemy | ||
[hackage:serialport]: https://hackage.haskell.org/package/serialport | ||
[hackage:posix-pty]: https://hackage.haskell.org/package/posix-pty | ||
[teletype]: http://www.haskellforall.com/2012/07/purify-code-using-free-monads.html | ||
[asciinema]: https://asciinema.org/ | ||
[asciicast]: https://github.com/asciinema/asciinema/blob/master/doc/asciicast-v2.md |
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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
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,12 @@ | ||
module Main where | ||
|
||
import Options.Applicative | ||
|
||
import Polytype | ||
import Polytype.Examples.HtopAsciinema | ||
|
||
main = execParser opts >>= htopAsciinemaExample | ||
where | ||
opts = info (argument str (metavar "FILE") <**> helper) | ||
( fullDesc | ||
<> progDesc "Record htop demo using asciicast output") |
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,2 @@ | ||
packages: | ||
./polytype.cabal |
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,2 @@ | ||
{ nixpkgs ? import <nixpkgs> {} }: | ||
nixpkgs.haskellPackages.callCabal2nix "polytype" ./. { } |
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,151 @@ | ||
name: polytype | ||
version: 0.1.0.0 | ||
synopsis: Polymorphic teletype | ||
description: Library and tooling for interacting with character devices | ||
homepage: https://github.com/sorki/polytype | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Richard Marko | ||
maintainer: [email protected] | ||
copyright: 2020 Richard Marko | ||
category: System | ||
build-type: Simple | ||
cabal-version: >=1.10 | ||
extra-source-files: | ||
CHANGELOG.md | ||
LICENSE | ||
README.md | ||
|
||
flag examples | ||
default: | ||
False | ||
description: | ||
Builds example applications | ||
|
||
library | ||
ghc-options: | ||
-Wall | ||
-Wunused-packages | ||
-O2 | ||
-flate-specialise | ||
-fspecialise-aggressively | ||
-- -fplugin=Polysemy.Plugin | ||
-- plugin is not enabled globally | ||
-- as it causes trouble for some files | ||
default-extensions: | ||
DataKinds | ||
FlexibleContexts | ||
GADTs | ||
LambdaCase | ||
BlockArguments | ||
PolyKinds | ||
RecordWildCards | ||
RankNTypes | ||
ScopedTypeVariables | ||
TypeApplications | ||
TypeOperators | ||
TypeFamilies | ||
TemplateHaskell | ||
NumericUnderscores | ||
QuantifiedConstraints | ||
FlexibleInstances | ||
hs-source-dirs: src | ||
exposed-modules: Polytype | ||
, Polytype.Ansi | ||
, Polytype.Asciinema | ||
, Polytype.Combinators | ||
, Polytype.Debug | ||
, Polytype.Delay | ||
, Polytype.Env | ||
, Polytype.Examples.Bash | ||
, Polytype.Examples.Echo | ||
, Polytype.Examples.HtopAsciinema | ||
, Polytype.Examples.IRCBridge | ||
, Polytype.Examples.Process | ||
, Polytype.Examples.SafeProcess | ||
, Polytype.Examples.Streaming | ||
, Polytype.Experiments | ||
, Polytype.Log | ||
, Polytype.Process | ||
, Polytype.Pty | ||
, Polytype.Race | ||
, Polytype.Readline | ||
, Polytype.Serial | ||
, Polytype.StdStreams | ||
, Polytype.Teletype | ||
, Polytype.Teletype.String | ||
, Polytype.Teletype.Text | ||
, Polytype.Test | ||
, Polytype.Timeout | ||
, Polytype.Types | ||
, Polytype.Types.Time | ||
, Polytype.Util | ||
, Polysemy.Input.Streaming | ||
, Polysemy.Output.Streaming | ||
build-depends: base >= 4.7 && < 5 | ||
, attoparsec | ||
, bytestring | ||
, aeson | ||
, scientific | ||
, containers | ||
, vector | ||
, data-default | ||
, text | ||
, async | ||
, process | ||
, polysemy | ||
, polysemy-plugin | ||
, posix-pty | ||
, streaming | ||
, serialport | ||
, string-conversions | ||
, time | ||
, haskeline | ||
, co-log-core | ||
, co-log-polysemy | ||
default-language: Haskell2010 | ||
|
||
executable polytype-htop-demo | ||
if !flag(examples) | ||
buildable: False | ||
hs-source-dirs: app | ||
main-is: HtopDemo.hs | ||
ghc-options: -threaded -rtsopts -with-rtsopts=-N | ||
build-depends: base | ||
, bytestring | ||
, text | ||
, polysemy-plugin | ||
, polysemy | ||
, polytype | ||
, optparse-applicative | ||
default-language: Haskell2010 | ||
|
||
test-suite polytype-tests | ||
type: exitcode-stdio-1.0 | ||
hs-source-dirs: test | ||
main-is: Spec.hs | ||
other-modules: SpecHelper | ||
PtySpec | ||
SerialSpec | ||
StdStreamsSpec | ||
TeletypeSpec | ||
build-depends: base >= 4.7 && < 5 | ||
, attoparsec | ||
, bytestring | ||
, data-default | ||
, text | ||
, polysemy | ||
, polysemy-plugin | ||
, polytype | ||
, hspec | ||
, hspec-discover | ||
default-language: Haskell2010 | ||
ghc-options: -threaded -rtsopts -with-rtsopts=-N | ||
default-extensions: | ||
DataKinds | ||
TypeApplications | ||
TypeOperators | ||
|
||
source-repository head | ||
type: git | ||
location: https://github.com/sorki/polytype |
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,2 @@ | ||
{ nixpkgs ? import <nixpkgs> {} }: | ||
(import ./default.nix { inherit nixpkgs; }).env |
Oops, something went wrong.