def open_file(self) -> Optional[EditResult]: response = self.prompt('enter filename', history='open') if response is not PromptResult.CANCELLED: opened = File(response, 0, self.color_manager, self.hl_factories) self.files.append(opened) return EditResult.OPEN else: return None
def c_main(stdscr: 'curses._CursesWindow', args: argparse.Namespace) -> None: screen = Screen(stdscr, [File(f) for f in args.filenames or [None]]) with screen.perf.log(args.perf_log), screen.history.save(): while screen.files: screen.i = screen.i % len(screen.files) res = _edit(screen) if res == EditResult.EXIT: del screen.files[screen.i] screen.status.clear() elif res == EditResult.NEXT: screen.i += 1 screen.status.clear() elif res == EditResult.PREV: screen.i -= 1 screen.status.clear() else: raise AssertionError(f'unreachable {res}')
def test_position_repr(): ret = repr(File('f.txt')) assert ret == ( 'File(\n' " filename='f.txt',\n" ' modified=False,\n' ' lines=[],\n' " nl='\\n',\n" ' file_y=0,\n' ' y=0,\n' ' x=0,\n' ' x_hint=0,\n' ' sha256=None,\n' ' undo_stack=[],\n' ' redo_stack=[],\n' ' select_start=None,\n' ')' )
def __init__( self, stdscr: 'curses._CursesWindow', filenames: List[Optional[str]], initial_lines: List[int], perf: Perf, ) -> None: self.stdscr = stdscr self.color_manager = ColorManager.make() self.hl_factories = (Syntax.from_screen(stdscr, self.color_manager), ) self.files = [ File(filename, line, self.color_manager, self.hl_factories) for filename, line in zip(filenames, initial_lines) ] self.i = 0 self.history = History() self.perf = perf self.status = Status() self.margin = Margin.from_current_screen() self.cut_buffer: Tuple[str, ...] = () self.cut_selection = False self._buffered_input: Union[int, str, None] = None