Prototype of web streaming
This commit is contained in:
@@ -15,6 +15,8 @@ class Display:
|
||||
height: int
|
||||
pad: Any
|
||||
|
||||
screen_lines: list = []
|
||||
|
||||
def __init__(self, screen: Any, pack: Optional[TexturePack] = None):
|
||||
self.screen = screen
|
||||
self.pack = pack or TexturePack.get_pack("ascii")
|
||||
@@ -83,6 +85,14 @@ class Display:
|
||||
# Refresh the pad only if coordinates are valid
|
||||
pad.refresh(top_y, top_x, window_y, window_x, last_y, last_x)
|
||||
|
||||
height, width = self.pad.getmaxyx()
|
||||
height = min(height, last_y - window_y + 1)
|
||||
width = min(width, last_x - window_x + 1)
|
||||
pad_str = "\n".join(pad.instr(y, top_x).decode("utf-8")[:-1]
|
||||
for y in range(top_y, top_y + height))
|
||||
pad_str = self.truncate(pad_str, height, width)
|
||||
Display.insert_message_in_screen(pad_str, window_y, window_x)
|
||||
|
||||
def display(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -94,6 +104,42 @@ class Display:
|
||||
def cols(self) -> int:
|
||||
return curses.COLS if self.screen else 42
|
||||
|
||||
@classmethod
|
||||
def resize_screen_lines(cls, height: int, width: int) -> None:
|
||||
cls.screen_lines = cls.screen_lines[:height]
|
||||
cls.screen_lines += [width * " "
|
||||
for _ in range(height - len(cls.screen_lines))]
|
||||
for i in range(len(cls.screen_lines)):
|
||||
cls.screen_lines[i] = cls.screen_lines[i][:width]
|
||||
|
||||
@classmethod
|
||||
def insert_message_in_screen(cls, message: str, y: int, x: int) -> None:
|
||||
for i, line in enumerate(message.split("\n")):
|
||||
if i + y <= len(cls.screen_lines):
|
||||
line = line[:len(cls.screen_lines[i + y]) - x]
|
||||
width = len(line)
|
||||
tmp_width = 0
|
||||
true_line = ""
|
||||
for c in line:
|
||||
tmp_width += 1
|
||||
true_line += c
|
||||
if c in TexturePack.SQUIRREL_PACK and c != " " and c != "█":
|
||||
tmp_width += 1
|
||||
if tmp_width >= width:
|
||||
break
|
||||
line = true_line
|
||||
cls.screen_lines[i + y] = cls.screen_lines[i + y][:x] + line + \
|
||||
cls.screen_lines[i + y][x + len(line):]
|
||||
|
||||
@classmethod
|
||||
def erase_screen_lines(cls) -> None:
|
||||
cls.screen_lines = [" " * len(cls.screen_lines[i])
|
||||
for i in range(len(cls.screen_lines))]
|
||||
|
||||
@classmethod
|
||||
def print_screen(cls) -> str:
|
||||
return "\n".join(cls.screen_lines)
|
||||
|
||||
|
||||
class VerticalSplit(Display):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user