Start displaying text
This commit is contained in:
17
babi.py
17
babi.py
@@ -2,6 +2,7 @@ import _curses
|
|||||||
import argparse
|
import argparse
|
||||||
import curses
|
import curses
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
from typing import List
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
VERSION_STR = 'babi v0'
|
VERSION_STR = 'babi v0'
|
||||||
@@ -92,6 +93,15 @@ def _write_status(stdscr: '_curses._CursesWindow', status: str) -> None:
|
|||||||
stdscr.addstr(curses.LINES - 1, offset, status, curses.A_REVERSE)
|
stdscr.addstr(curses.LINES - 1, offset, status, curses.A_REVERSE)
|
||||||
|
|
||||||
|
|
||||||
|
def _write_lines(stdscr: '_curses._CursesWindow', lines: List[str]) -> None:
|
||||||
|
lines_to_display = min(len(lines), curses.LINES - 2)
|
||||||
|
for i in range(lines_to_display):
|
||||||
|
stdscr.addstr(i + 1, 0, lines[i][:curses.COLS])
|
||||||
|
blankline = ' ' * curses.COLS
|
||||||
|
for i in range(lines_to_display, curses.LINES - 2):
|
||||||
|
stdscr.addstr(i + 1, 0, blankline)
|
||||||
|
|
||||||
|
|
||||||
def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None:
|
def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None:
|
||||||
_init_colors(stdscr)
|
_init_colors(stdscr)
|
||||||
|
|
||||||
@@ -103,6 +113,12 @@ def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None:
|
|||||||
status_action_counter = -1
|
status_action_counter = -1
|
||||||
position_y, position_x = 0, 0
|
position_y, position_x = 0, 0
|
||||||
|
|
||||||
|
if args.filename is not None:
|
||||||
|
with open(args.filename) as f:
|
||||||
|
lines = list(f)
|
||||||
|
else:
|
||||||
|
lines = []
|
||||||
|
|
||||||
def _set_status(s: str) -> None:
|
def _set_status(s: str) -> None:
|
||||||
nonlocal status, status_action_counter
|
nonlocal status, status_action_counter
|
||||||
status = s
|
status = s
|
||||||
@@ -115,6 +131,7 @@ def c_main(stdscr: '_curses._CursesWindow', args: argparse.Namespace) -> None:
|
|||||||
|
|
||||||
_write_header(stdscr, filename, modified=False)
|
_write_header(stdscr, filename, modified=False)
|
||||||
_write_status(stdscr, status)
|
_write_status(stdscr, status)
|
||||||
|
_write_lines(stdscr, lines)
|
||||||
stdscr.move(position_y + 1, position_x)
|
stdscr.move(position_y + 1, position_x)
|
||||||
|
|
||||||
wch = stdscr.get_wch()
|
wch = stdscr.get_wch()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
coverage
|
coverage
|
||||||
git+https://github.com/ionelmc/python-remote-pdb@a5469c2d
|
|
||||||
git+https://github.com/mjsir911/hecate@092f811
|
git+https://github.com/mjsir911/hecate@092f811
|
||||||
pytest
|
pytest
|
||||||
|
remote-pdb
|
||||||
|
|||||||
@@ -4,17 +4,29 @@ import sys
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from hecate import Runner
|
from hecate import Runner
|
||||||
|
from hecate.hecate import AbnormalExit
|
||||||
|
|
||||||
import babi
|
import babi
|
||||||
|
|
||||||
|
|
||||||
|
class PrintsErrorRunner(Runner):
|
||||||
|
def await_exit(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return super().await_exit(*args, **kwargs)
|
||||||
|
except AbnormalExit: # pragma: no cover
|
||||||
|
print('=' * 79, flush=True)
|
||||||
|
print(self.screenshot(), end='', flush=True)
|
||||||
|
print('=' * 79, flush=True)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def run(*args, color=True, **kwargs):
|
def run(*args, color=True, **kwargs):
|
||||||
cmd = (sys.executable, '-mcoverage', 'run', '-m', 'babi', *args)
|
cmd = (sys.executable, '-mcoverage', 'run', '-m', 'babi', *args)
|
||||||
quoted = ' '.join(shlex.quote(p) for p in cmd)
|
quoted = ' '.join(shlex.quote(p) for p in cmd)
|
||||||
term = 'screen-256color' if color else 'screen'
|
term = 'screen-256color' if color else 'screen'
|
||||||
cmd = ('bash', '-c', f'export TERM={term}; exec {quoted}')
|
cmd = ('bash', '-c', f'export TERM={term}; exec {quoted}')
|
||||||
with Runner(*cmd, **kwargs) as h:
|
with PrintsErrorRunner(*cmd, **kwargs) as h:
|
||||||
h.await_text(babi.VERSION_STR)
|
h.await_text(babi.VERSION_STR)
|
||||||
yield h
|
yield h
|
||||||
|
|
||||||
@@ -86,6 +98,7 @@ def test_window_bounds(tmpdir):
|
|||||||
f.write(f'{"x" * 40}\n' * 40)
|
f.write(f'{"x" * 40}\n' * 40)
|
||||||
|
|
||||||
with run(str(f), width=30, height=30) as h, and_exit(h):
|
with run(str(f), width=30, height=30) as h, and_exit(h):
|
||||||
|
h.await_text('x' * 30)
|
||||||
# make sure we don't go off the top left of the screen
|
# make sure we don't go off the top left of the screen
|
||||||
h.press('LEFT')
|
h.press('LEFT')
|
||||||
h.press('UP')
|
h.press('UP')
|
||||||
|
|||||||
Reference in New Issue
Block a user