import keyinput
from mode import Fundamental
from method import Method

class PipeInsertChr(Method):
    _is_method = False
    def __init__(self, i):
        self.name   = "pipe-insert-chr-%s" % i
        self.args   = []
        self.help   = "Insert chr(%d) into the current pipe-buffer." % i
        self.string = chr(i)
    def _execute(self, w, **vargs):
        w.buffer.pipe_write(self.string)

class Pipe(Fundamental):
    modename = 'pipe'
    def __init__(self, w):
        Fundamental.__init__(self, w)
        _codes = [1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14] + \
            [16, 18, 20, 23, 25] + list(range(32, 128))
        for i in _codes:
            sym = keyinput.MAP.get(i, chr(i))
            obj = PipeInsertChr(i)
            w.application.methods[obj.name] = obj
            self.add_binding(obj.name, sym)

install = Pipe.install