Example #1
0
 def __init__(self, greet, load):
     """ Initialise the interpreter session. """
     # true if a prompt is needed on next cycle
     self.prompt = True
     # input mode is AUTO (used by AUTO)
     state.basic_state.auto_mode = False
     # interpreter is executing a command
     state.basic_state.parse_mode = False
     # interpreter is waiting for INPUT or LINE INPUT
     state.basic_state.input_mode = False
     # previous interpreter mode
     self.last_mode = False, False
     # syntax error prompt and EDIT
     state.basic_state.edit_prompt = False
     # initialise the display
     display.init()
     # initialise the console
     console.init_mode()
     # set up event handlers
     state.basic_state.events = events.Events()
     # load initial program
     if load:
         # on load, accept capitalised versions and default extension
         with disk.open_native_or_dos_filename(load) as progfile:
             program.load(progfile)
     # set up interpreter and memory model state
     reset.clear()
     # greeting and keys
     if greet:
         console.clear()
         console.write_line(greeting.format(version=plat.version, free=var.fre()))
         console.show_keys(True)
Example #2
0
def bluescreen(e):
    """ Display a modal exception message. """
    state.console_state.screen.screen(0, 0, 0, 0, new_width=80)
    console.clear()
    console.init_mode()
    exc_type, exc_value, exc_traceback = sys.exc_info()
    # log the standard python error
    logging.error(''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
    # format the error more readably on the screen
    state.console_state.screen.set_border(4)
    state.console_state.screen.set_attr(0x70)
    console.write_line('EXCEPTION')
    state.console_state.screen.set_attr(15)
    if state.basic_state.run_mode:
        state.basic_state.bytecode.seek(-1, 1)
        program.edit(program.get_line_number(state.basic_state.bytecode.tell()),
                                         state.basic_state.bytecode.tell())
        console.write_line('\n')
    else:
        state.basic_state.direct_line.seek(0)
        console.write_line(str(tokenise.detokenise_compound_statement(state.basic_state.direct_line)[0])+'\n')
    stack = traceback.extract_tb(exc_traceback)
    for s in stack[-4:]:
        stack_line = '{0}:{1}, {2}'.format(
            os.path.split(s[0])[-1], s[1], s[2])
        stack_line_2 = '    {0}'.format(s[3])
        state.console_state.screen.set_attr(15)
        console.write_line(stack_line)
        state.console_state.screen.set_attr(7)
        console.write_line(stack_line_2)
    exc_message = traceback.format_exception_only(exc_type, exc_value)[0]
    state.console_state.screen.set_attr(15)
    console.write('{0}:'.format(exc_type.__name__))
    state.console_state.screen.set_attr(7)
    console.write_line(' {0}'.format(str(exc_value)))
    state.console_state.screen.set_attr(0x70)
    console.write_line(
        '\nThis is a bug in PC-BASIC.')
    state.console_state.screen.set_attr(7)
    console.write(
        'Sorry about that. Please send the above messages to the bugs forum\nby e-mail to ')
    state.console_state.screen.set_attr(15)
    console.write(
        '*****@*****.**')
    state.console_state.screen.set_attr(7)
    console.write(
        ' or by filing a bug\nreport at ')
    state.console_state.screen.set_attr(15)
    console.write(
        'https://github.com/robhagemans/pcbasic/issues')
    state.console_state.screen.set_attr(7)
    console.write_line(
        '. Please include')
    console.write_line('as much information as you can about what you were doing and how this happened.')
    console.write_line('Thank you!')
    state.console_state.screen.set_attr(7)
    flow.set_pointer(False)
Example #3
0
def bluescreen(e):
    """ Display a modal exception message. """
    state.console_state.screen.screen(0, 0, 0, 0, new_width=80)
    console.clear()
    console.init_mode()
    exc_type, exc_value, exc_traceback = sys.exc_info()
    # log the standard python error
    logging.error(''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
    # format the error more readably on the screen
    state.console_state.screen.set_border(4)
    state.console_state.screen.set_attr(0x70)
    console.write_line('EXCEPTION')
    state.console_state.screen.set_attr(15)
    if state.basic_state.run_mode:
        state.basic_state.bytecode.seek(-1, 1)
        program.edit(program.get_line_number(state.basic_state.bytecode.tell()),
                                         state.basic_state.bytecode.tell())
        console.write_line('\n')
    else:
        state.basic_state.direct_line.seek(0)
        console.write_line(str(tokenise.detokenise_compound_statement(state.basic_state.direct_line)[0])+'\n')
    stack = traceback.extract_tb(exc_traceback)
    for s in stack[-4:]:
        stack_line = '{0}:{1}, {2}'.format(
            os.path.split(s[0])[-1], s[1], s[2])
        stack_line_2 = '    {0}'.format(s[3])
        state.console_state.screen.set_attr(15)
        console.write_line(stack_line)
        state.console_state.screen.set_attr(7)
        console.write_line(stack_line_2)
    exc_message = traceback.format_exception_only(exc_type, exc_value)[0]
    state.console_state.screen.set_attr(15)
    console.write('{0}:'.format(exc_type.__name__))
    state.console_state.screen.set_attr(7)
    console.write_line(' {0}'.format(str(exc_value)))
    state.console_state.screen.set_attr(0x70)
    console.write_line(
        '\nThis is a bug in PC-BASIC.')
    state.console_state.screen.set_attr(7)
    console.write(
        'Sorry about that. Please send the above messages to the bugs forum\nby e-mail to ')
    state.console_state.screen.set_attr(15)
    console.write(
        '*****@*****.**')
    state.console_state.screen.set_attr(7)
    console.write(
        ' or by filing a bug\nreport at ')
    state.console_state.screen.set_attr(15)
    console.write(
        'https://github.com/robhagemans/pcbasic/issues')
    state.console_state.screen.set_attr(7)
    console.write_line(
        '. Please include')
    console.write_line('as much information as you can about what you were doing and how this happened.')
    console.write_line('Thank you!')
    state.console_state.screen.set_attr(7)
    flow.set_pointer(False)
Example #4
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import display
    import sound
    import console
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import inputs
    interface = config.get('interface') or 'graphical'
    display.init(interface)
    sound.init('none' if config.get('nosound') else interface)
    if not state.loaded:
        console.init_mode()
    return backend, console
Example #5
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import display
    import sound
    import console
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import inputs
    interface = config.get('interface') or 'graphical'
    display.init(interface)
    sound.init('none' if config.get('nosound') else interface)
    if not state.loaded:
        console.init_mode()
    return backend, console
Example #6
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import sound
    # load backend modules
    # this can't be done in backend.py as it would create circular dependency
    import console
    import error
    import fp
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import redirect
    # hack: mark modules for inclusion by pyinstaller
    # see https://groups.google.com/forum/#!topic/pyinstaller/S8QgHXiGJ_A
    if False:
        import video_none
        import video_curses
        import video_ansi
        import video_cli
        import video_pygame
        import audio_none
        import audio_beep
        import audio_pygame
    backends = {
        'none': ('video_none', 'audio_none'),
        'cli': ('video_cli', 'audio_beep'),
        'text': ('video_curses', 'audio_beep'),
        'ansi': ('video_ansi', 'audio_beep'),
        'graphical': ('video_pygame', 'audio_pygame'),
    }
    if not config.get('interface'):
        config.options['interface'] = 'graphical'
    # select interface
    video_name, audio_name = backends[config.get('interface')]
    # initialise video backend before console
    while True:
        try:
            # __name__ global is needed when calling from setuptools package
            video = __import__(video_name, globals={"__name__": __name__})
        except ImportError as e:
            video = None
        if not video:
            if not video_name or video_name == 'video_none':
                logging.error('Failed to initialise interface.')
                raise error.Exit()
            logging.error('Could not load module %s.', video_name)
            video_name = 'video_none'
            continue
        if backend.init_video(video):
            break
        else:
            video_name = video.fallback
            if video:
                video.close()
            if video_name:
                logging.info('Falling back to %s interface.', video_name)
    if config.get('nosound'):
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
    else:
        sound.audio = __import__(audio_name, globals={"__name__": __name__})
    if not sound.init():
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
        sound.init()
        logging.warning(
            'Failed to initialise sound. Sound will be disabled.\r')
    if not state.loaded:
        console.init_mode()
    # set the output for maths error messages
    fp.init(error_stream=console)
    return backend, console
Example #7
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import sound
    # load backend modules
    # this can't be done in backend.py as it would create circular dependency
    import console
    import error
    import fp
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import redirect
    # hack: mark modules for inclusion by pyinstaller
    # see https://groups.google.com/forum/#!topic/pyinstaller/S8QgHXiGJ_A
    if False:
        import video_none
        import video_curses
        import video_ansi
        import video_cli
        import video_pygame
        import audio_none
        import audio_beep
        import audio_pygame
    backends = {
        'none': ('video_none', 'audio_none'),
        'cli': ('video_cli', 'audio_beep'),
        'text': ('video_curses', 'audio_beep'),
        'ansi': ('video_ansi', 'audio_beep'),
        'graphical': ('video_pygame', 'audio_pygame'),
        }
    if not config.get('interface'):
        config.options['interface'] = 'graphical'
    # select interface
    video_name, audio_name = backends[config.get('interface')]
    # initialise video backend before console
    while True:
        try:
            # __name__ global is needed when calling from setuptools package
            video = __import__(video_name, globals={"__name__": __name__})
        except ImportError as e:
            video = None
        if not video:
            if not video_name or video_name == 'video_none':
                logging.error('Failed to initialise interface.')
                raise error.Exit()
            logging.error('Could not load module %s.', video_name)
            video_name = 'video_none'
            continue
        if backend.init_video(video):
            break
        else:
            video_name = video.fallback
            if video:
                video.close()
            if video_name:
                logging.info('Falling back to %s interface.', video_name)
    if config.get('nosound'):
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
    else:
        sound.audio = __import__(audio_name, globals={"__name__": __name__})
    if not sound.init():
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
        sound.init()
        logging.warning('Failed to initialise sound. Sound will be disabled.\r')
    if not state.loaded:
        console.init_mode()
    # set the output for maths error messages
    fp.init(error_stream=console)
    return backend, console