示例#1
0
 def spawn_shell(command):
     """ Run a SHELL subprocess. """
     cmd = shell_command
     if command:
         cmd += ' -c "' + command + '"'            
     p = pexpect.spawn(str(cmd))
     while True:
         try:
             c = state.console_state.keyb.get_char()
         except error.Break:
             # ignore ctrl+break in SHELL
             pass
         if c == '\b': # BACKSPACE
             p.send('\x7f')
         elif c != '':
             p.send(c)
         while True:
             try:
                 c = p.read_nonblocking(1, timeout=0)
             except: 
                 c = ''
             if c == '' or c == '\n':
                 break
             elif c == '\r':
                 console.write_line()    
             elif c == '\b':
                 if state.console_state.col != 1:
                     console.set_pos(state.console_state.row, 
                                     state.console_state.col-1)
             else:
                 console.write(c)
         if c == '' and not p.isalive(): 
             return
示例#2
0
def edit(from_line, bytepos=None):
    """ Output program line to console and position cursor. """
    if state.basic_state.protected:
        console.write(str(from_line)+'\r')
        raise error.RunError(error.IFC)
    # list line
    state.basic_state.bytecode.seek(state.basic_state.line_numbers[from_line]+1)
    _, output, textpos = tokenise.detokenise_line(state.basic_state.bytecode, bytepos)
    # no newline to avoid scrolling on line 24
    console.list_line(str(output), newline=False)
    # find row, column position for textpos
    newlines, c = 0, 0
    pos_row, pos_col = 0, 0
    if not output:
        return
    for i, byte in enumerate(output):
        c += 1
        if chr(byte) == '\n' or c > state.console_state.screen.mode.width:
            newlines += 1
            c = 0
        if i == textpos:
            pos_row, pos_col = newlines, c
    if textpos > i:
        pos_row, pos_col = newlines, c + 1
    if bytepos:
        console.set_pos(state.console_state.row-newlines+pos_row, pos_col)
    else:
        console.set_pos(state.console_state.row-newlines, 1)
示例#3
0
def edit(from_line, bytepos=None):
    """ Output program line to console and position cursor. """
    if state.basic_state.protected:
        console.write(str(from_line) + '\r')
        raise error.RunError(error.IFC)
    # list line
    state.basic_state.bytecode.seek(state.basic_state.line_numbers[from_line] +
                                    1)
    _, output, textpos = tokenise.detokenise_line(state.basic_state.bytecode,
                                                  bytepos)
    # no newline to avoid scrolling on line 24
    console.list_line(str(output), newline=False)
    # find row, column position for textpos
    newlines, c = 0, 0
    pos_row, pos_col = 0, 0
    for i, byte in enumerate(output):
        c += 1
        if chr(byte) == '\n' or c > state.console_state.screen.mode.width:
            newlines += 1
            c = 0
        if i == textpos:
            pos_row, pos_col = newlines, c
    if textpos > i:
        pos_row, pos_col = newlines, c + 1
    if bytepos:
        console.set_pos(state.console_state.row - newlines + pos_row, pos_col)
    else:
        console.set_pos(state.console_state.row - newlines, 1)
示例#4
0
文件: shell.py 项目: Yungzuck/pcbasic
 def spawn_shell(command):
     """ Run a SHELL subprocess. """
     cmd = shell_command
     if command:
         cmd += ' -c "' + command + '"'
     p = pexpect.spawn(str(cmd))
     while True:
         try:
             c = state.console_state.keyb.get_char()
         except error.Break:
             # ignore ctrl+break in SHELL
             pass
         if c == '\b':  # BACKSPACE
             p.send('\x7f')
         elif c != '':
             p.send(c)
         while True:
             try:
                 c = p.read_nonblocking(1, timeout=0)
             except:
                 c = ''
             if c == '' or c == '\n':
                 break
             elif c == '\r':
                 console.write_line()
             elif c == '\b':
                 if state.console_state.col != 1:
                     console.set_pos(state.console_state.row,
                                     state.console_state.col - 1)
             else:
                 console.write(c)
         if c == '' and not p.isalive():
             return