Merge branch 'master' into doc
This commit is contained in:
@ -25,9 +25,16 @@ class Display:
|
||||
self.pack = pack or TexturePack.get_pack("ascii")
|
||||
|
||||
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
||||
"""
|
||||
Overwrites the native curses function of the same name.
|
||||
"""
|
||||
return curses.newpad(height, width) if self.screen else FakePad()
|
||||
|
||||
def truncate(self, msg: str, height: int, width: int) -> str:
|
||||
"""
|
||||
Truncates a string into a string adapted to the width and height of
|
||||
the screen.
|
||||
"""
|
||||
height = max(0, height)
|
||||
width = max(0, width)
|
||||
lines = msg.split("\n")
|
||||
@ -37,8 +44,8 @@ class Display:
|
||||
|
||||
def translate_color(self, color: Union[int, Tuple[int, int, int]]) -> int:
|
||||
"""
|
||||
Translate a tuple (R, G, B) into a curses color index.
|
||||
If we have already a color index, then nothing is processed.
|
||||
Translates a tuple (R, G, B) into a curses color index.
|
||||
If we already have a color index, then nothing is processed.
|
||||
If this is a tuple, we construct a new color index if non-existing
|
||||
and we return this index.
|
||||
The values of R, G and B must be between 0 and 1000, and not
|
||||
@ -67,9 +74,9 @@ class Display:
|
||||
low: bool = False, right: bool = False, top: bool = False,
|
||||
vertical: bool = False, chartext: bool = False) -> None:
|
||||
"""
|
||||
Display a message onto the pad.
|
||||
Displays a message onto the pad.
|
||||
If the message is too large, it is truncated vertically and horizontally
|
||||
The text can be bold, italic, blinking, ... if the good parameters are
|
||||
The text can be bold, italic, blinking, ... if the right parameters are
|
||||
given. These parameters are translated into curses attributes.
|
||||
The foreground and background colors can be given as curses constants
|
||||
(curses.COLOR_*), or by giving a tuple (R, G, B) that corresponds to
|
||||
@ -129,6 +136,9 @@ class Display:
|
||||
|
||||
def resize(self, y: int, x: int, height: int, width: int,
|
||||
resize_pad: bool = True) -> None:
|
||||
"""
|
||||
Resizes a pad.
|
||||
"""
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
@ -139,6 +149,9 @@ class Display:
|
||||
self.pad.resize(self.height + 1, self.width + 1)
|
||||
|
||||
def refresh(self, *args, resize_pad: bool = True) -> None:
|
||||
"""
|
||||
Refreshes a pad
|
||||
"""
|
||||
if len(args) == 4:
|
||||
self.resize(*args, resize_pad)
|
||||
self.display()
|
||||
@ -147,10 +160,10 @@ class Display:
|
||||
window_y: int, window_x: int,
|
||||
last_y: int, last_x: int) -> None:
|
||||
"""
|
||||
Refresh a pad on a part of the window.
|
||||
Refreshes a pad on a part of the window.
|
||||
The refresh starts at coordinates (top_y, top_x) from the pad,
|
||||
and is drawn from (window_y, window_x) to (last_y, last_x).
|
||||
If coordinates are invalid (negative indexes/length..., then nothing
|
||||
If coordinates are invalid (negative indexes/length...), then nothing
|
||||
is drawn and no error is raised.
|
||||
"""
|
||||
top_y, top_x = max(0, top_y), max(0, top_x)
|
||||
@ -180,7 +193,7 @@ class Display:
|
||||
def handle_click(self, y: int, x: int, game: Game) -> None:
|
||||
"""
|
||||
A mouse click was performed on the coordinates (y, x) of the pad.
|
||||
Maybe it can do something.
|
||||
Maybe it should do something.
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -194,7 +207,9 @@ class Display:
|
||||
|
||||
|
||||
class VerticalSplit(Display):
|
||||
|
||||
"""
|
||||
A class to split the screen in two vertically with a pretty line.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.pad = self.newpad(self.rows, 1)
|
||||
@ -215,7 +230,9 @@ class VerticalSplit(Display):
|
||||
|
||||
|
||||
class HorizontalSplit(Display):
|
||||
|
||||
"""
|
||||
A class to split the screen in two horizontally with a pretty line.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.pad = self.newpad(1, self.cols)
|
||||
@ -236,6 +253,9 @@ class HorizontalSplit(Display):
|
||||
|
||||
|
||||
class Box(Display):
|
||||
"""
|
||||
A class for pretty boxes to print menus and other content.
|
||||
"""
|
||||
title: str = ""
|
||||
|
||||
def update_title(self, title: str) -> None:
|
||||
|
Reference in New Issue
Block a user