Beispiel #1
0
 def refresh_rest_of_line(self, is_delete=False):
     rest = self.chars[self.cursor:]
     term.puts(''.join(rest))
     to_back_up = len(rest)
     if is_delete:
         term.puts(' ')
         to_back_up += 1
     if to_back_up:
         term.cursor_left(to_back_up)
Beispiel #2
0
def ascii_to_zscii(string):
    result = []
    i = 0
    while i < len(string):
        c = string[i]
        if c == '\n':
            result.append(ord('\r'))
        # NOTE: gargoyle just ignores the tab key, S 3.8.2.3 says
        # output only. But since I want to keep expected tab behavior,
        # I make this compromise.
        elif c == '\t':
            result.append(ord(' '))
        elif c in ('\r', '\b') or (len(c) == 1 and ord(c) > 31
                                   and ord(c) < 127):
            result.append(ord(c))
            # TODO (?): unicode for input (translate codes to zscii using the unicode table(s))
            # TODO: keypad digits
        elif c == '\x1b':
            esc_key_tbl = {
                # arrow keys
                '[A': 129,
                '[B': 130,
                '[C': 132,
                '[D': 131,
                # fkeys
                'OP': 133,
                'OQ': 134,
                'OR': 135,
                'OS': 136,
                '[15~': 137,
                '[17~': 138,
                '[18~': 139,
                '[19~': 140,
                '[20~': 141,
                '[21~': 142,
                '[23~': 143,
                '[24~': 144,
            }
            found = False
            next_few = string[i + 1:i + 5]
            for seq in esc_key_tbl:
                if next_few.startswith(seq):
                    result.append(esc_key_tbl[seq])
                    i += len(seq)
                    found = True
                    break
            if not found:
                result.append(ord(c))
        else:
            if DBG:
                term.puts('\nthis ascii char not yet implemented in zscii: ' +
                          str(c) + ' / ' + str(ord(c)) + '\n')
                term.puts('\nHIT ENTER TO CONTINUE\n')
                term.getch_or_esc_seq()
            result.append(ord('?'))
        i += 1
    return result
def ascii_to_zscii(string):
    result = []
    i = 0
    while i < len(string):
        c = string[i]
        if c == '\n':
            result.append(ord('\r'))
        # NOTE: gargoyle just ignores the tab key, S 3.8.2.3 says
        # output only. But since I want to keep expected tab behavior,
        # I make this compromise.
        elif c == '\t':
            result.append(ord(' '))
        elif c in ('\r','\b') or (len(c) == 1 and ord(c) > 31 and ord(c) < 127):
            result.append(ord(c))
            # TODO (?): unicode for input (translate codes to zscii using the unicode table(s))
            # TODO: keypad digits
        elif c == '\x1b':
            esc_key_tbl = {
                # arrow keys
                '[A': 129, '[B': 130, '[C': 132, '[D':131,
                # fkeys
                'OP': 133, 'OQ': 134, 'OR': 135, 'OS': 136, '[15~': 137,
                '[17~': 138, '[18~': 139, '[19~' :140, '[20~': 141,
                '[21~': 142, '[23~': 143, '[24~': 144,
            }
            found = False
            next_few = string[i+1:i+5]
            for seq in esc_key_tbl:
                if next_few.startswith(seq):
                    result.append(esc_key_tbl[seq])
                    i += len(seq)
                    found = True
                    break
            if not found:
                result.append(ord(c))
        else:
            if DBG:
                term.puts('\nthis ascii char not yet implemented in zscii: '+str(c)+' / '+str(ord(c)) + '\n')
                term.puts('\nHIT ENTER TO CONTINUE\n')
                term.getch_or_esc_seq()
            result.append(ord('?'))
        i += 1
    return result
Beispiel #4
0
 def insert(self, c):
     self.chars.insert(self.cursor, c)
     term.puts(c)
     self.cursor += 1
     self.refresh_rest_of_line()