move Margin to its own module
This commit is contained in:
26
babi/main.py
26
babi/main.py
@@ -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
27
babi/margin.py
Normal 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)
|
||||
Reference in New Issue
Block a user