Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dariooddenino/purescript-charm
Browse files Browse the repository at this point in the history
  • Loading branch information
dariooddenino committed Aug 24, 2017
2 parents 0074257 + 46f8af8 commit 10fcf90
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Purescript Charm
================

A PureScript wrapper for [Charm](https://github.com/substack/node-charm).

Use ansi terminal characters to write colors and cursor positions.

Example
=======

```purescript
import Prelude
import Node.Charm
main :: Eff (charm :: CHARM) Unit
main = do
let c = charm []
render c do
reset
right 16
write "beep"
down 1
right 32
foreground $ Left Magenta
write "boop\n"
display Reset
end
```

Missing
=======

- Right now `purescript-charm` only works with the default `process.stdin` / `process.stdout`.

- `getPosition` doesn't work.
5 changes: 5 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"name": "purescript-charm",
"description": "A PureScript wrapper for Charm",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"output"
],
"repository": {
"type": "git",
"url": "https://github.com/dariooddenino/purescript-charm"
},
"dependencies": {
"purescript-prelude": "^3.1.0",
"purescript-console": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "purescript-charm",
"version": "0.5.0",
"description": "",
"version": "0.4.0",
"description": "A PureScript wrapper for Charm",
"main": "index.js",
"directories": {
"test": "test"
Expand Down
14 changes: 7 additions & 7 deletions src/Node/Charm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ exports._setPosition = function (x, y, charm) {
}
}

exports._getPosition = function (cb, charm) {
return function () {
charm.position(function (x, y) {
cb(x)();
})
}
}
// exports._getPosition = function (cb, charm) {
// return function () {
// charm.position(function (x, y) {
// cb(x)();
// })
// }
// }

exports._move = function (x, y, charm) {
return function () {
Expand Down
39 changes: 34 additions & 5 deletions src/Node/Charm.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
module Node.Charm where

module Node.Charm (
CHARM,
Charm,
CharmM,
Region(..),
Mode(..),
Display(..),
Colors(..),
Color,
charm,
render,
reset,
destroy,
end,
write,
setPosition,
move,
up,
down,
left,
right,
push,
pop,
erase,
delete,
insert,
display,
foreground,
background,
cursor
) where

import Prelude (class Show, Unit, flip, show, (<<<), (>>=))
import Control.Monad.Trans.Class (lift)
import Prelude
import Control.Monad.Eff (Eff, kind Effect)
Expand Down Expand Up @@ -73,7 +104,7 @@ foreign import _destroy :: forall eff. ChF1 eff
foreign import _end :: forall eff. ChF1 eff
foreign import _write :: forall eff. ChF2 eff String
foreign import _setPosition :: forall eff. ChF3 eff Int Int
foreign import _getPosition :: forall eff. Fn2 (Int -> CharmEff eff Unit) Charm (CharmEff eff Unit)
-- foreign import _getPosition :: forall eff. Fn2 (Int -> CharmEff eff Unit) Charm (CharmEff eff Unit)
foreign import _move :: forall eff. ChF3 eff Int Int
foreign import _up :: forall eff. ChF2 eff Int
foreign import _down :: forall eff. ChF2 eff Int
Expand Down Expand Up @@ -184,7 +215,6 @@ erase r = ask >>= lift <<< runFn2 _erase (show r)
-- -- | Deletes lines or chars. Differs from erase because it does not write over deleted characters with whitespace.
-- -- | LineMode | CharMode
-- -- | The cursor position is not updated.
-- -- | @FIXME: not working?
delete :: forall eff. Mode -> Int -> CharmM eff
delete m n = ask >>= lift <<< runFn3 _delete (show m) n

Expand All @@ -195,7 +225,6 @@ insert m n = ask >>= lift <<< runFn3 _insert (show m) n


-- -- | Sets the display mode to Display
-- -- | @FIXME: not working?
display :: forall eff. Display -> CharmM eff
display d = ask >>= lift <<< runFn2 _display (show d)

Expand Down

0 comments on commit 10fcf90

Please sign in to comment.