move Margin to its own module

This commit is contained in:
Anthony Sottile
2020-02-22 12:55:35 -08:00
parent e2b5d533b6
commit b7bb28bd76
2 changed files with 28 additions and 25 deletions

View File

@@ -31,6 +31,7 @@ from typing import Union
from babi.list_spy import ListSpy
from babi.list_spy import MutableSequenceNoSlice
from babi.margin import Margin
VERSION_STR = 'babi v0'
TCallable = TypeVar('TCallable', bound=Callable[..., Any])
@@ -101,31 +102,6 @@ class Key(NamedTuple):
keyname: bytes
class Margin(NamedTuple):
header: bool
footer: bool
@property
def body_lines(self) -> int:
return curses.LINES - self.header - self.footer
@property
def page_size(self) -> int:
if self.body_lines <= 2:
return 1
else:
return self.body_lines - 2
@classmethod
def from_current_screen(cls) -> 'Margin':
if curses.LINES == 1:
return cls(header=False, footer=False)
elif curses.LINES == 2:
return cls(header=False, footer=True)
else:
return cls(header=True, footer=True)
class Status:
def __init__(self) -> None:
self._status = ''

27
babi/margin.py Normal file
View File

@@ -0,0 +1,27 @@
import curses
from typing import NamedTuple
class Margin(NamedTuple):
header: bool
footer: bool
@property
def body_lines(self) -> int:
return curses.LINES - self.header - self.footer
@property
def page_size(self) -> int:
if self.body_lines <= 2:
return 1
else:
return self.body_lines - 2
@classmethod
def from_current_screen(cls) -> 'Margin':
if curses.LINES == 1:
return cls(header=False, footer=False)
elif curses.LINES == 2:
return cls(header=False, footer=True)
else:
return cls(header=True, footer=True)