var EventSinks = require('event-sinks/geval')
var uuid = require('uuid')

var onKey = require('./lib/on-key.js')

/* Input takes RAW input sources and converts them to
    a set of Events

*/
module.exports = createInputs

function createInputs(stdin) {
    var events = EventSinks(uuid(), [
        'exit', 'help', 'moveForward', 'moveForwardPage'
    ])
    var sinks = events.sinks

    if (typeof stdin.setRawMode === 'function') {
        stdin.setRawMode(true)
    }

    onKey(stdin, {
        'Ctrl-c|Ctrl-d|q': onExit,
        'h|H': onHelp,
        'enter|return|e|j|Ctrl-N|Ctrl-E|Ctrl-J': onMoveForward,
        'space|f|Ctrl-V|Ctrl-F': onMoveForwardPage
    })

    return { events: events, sinks: sinks }

    function onHelp() {
        sinks.help.write({})
    }

    function onExit() {
        sinks.exit.write({})
    }

    function onMoveForward() {
        sinks.moveForward.write(1)
    }

    function onMoveForwardPage() {
        sinks.moveForwardPage.write(1)
    }
}

@@ -621,41 +621,133 @@
    '
-space%7Cf%7CCtrl-V%7CCtrl-F': onMoveFor
+y%7CCtrl+Y%7CCtrl+P%7Cl%7CCtrl+K': onMoveBackward,%0A        'space%7Cf%7CCtrl-V%7CCtrl-F': onMoveForwardPage,%0A        'b%7CCtrl+B': onMoveBack
 ward
@@ -1076,11 +1076,169 @@
 1)%0A    %7D
+%0A%0A    function onMoveBackward() %7B%0A        sinks.moveForward.write(-1)%0A    %7D%0A%0A    function onMoveBackwardPage() %7B%0A        sinks.moveForwardPage.write(-1)%0A    %7D
 %0A%7D%0A

allow moving forward & back