From 80cf133bbf5fcac675c5e38c83fbf91a5eceaed3 Mon Sep 17 00:00:00 2001 From: KikooDX <30863886+KikooDX@users.noreply.github.com> Date: Sat, 16 Nov 2019 16:12:56 +0100 Subject: [PATCH] Fancy margin. Speed and size optimization. --- locate2.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/locate2.py b/locate2.py index 4c2abe8..1521984 100644 --- a/locate2.py +++ b/locate2.py @@ -28,7 +28,7 @@ class Screen: def fill(self, patern=" "): self._mat = [[patern[0] for i in range(self._width)] for i in range(self._height)] - def refresh(self, ask_for_input=True, endl="\n", fancy=False): + def refresh(self, ask_for_input=True, endl="\n", fancy=False, fmargin=4): to_print = str() for line in self._mat[:-1] if fancy else self._mat: for cell in line: @@ -38,9 +38,11 @@ class Screen: print(to_print) if ask_for_input or fancy: line = "" - for cell in self._mat[-1][:-5]: + if fancy: + for cell in self._mat[-1][:-1-fmargin]: line += cell - return input(line if fancy else "> ") + return input(line) + return input("> ") else: print("", end=endl) return None @@ -70,7 +72,7 @@ class Screen: class Pad(Screen): def refresh(self, x=1, y=1, width=21, height=7, ask_for_input=True,\ - endl="\n", fancy=True): + endl="\n", fancy=True, fmargin=4): ogwidth = width if width > self._width: width = self._width @@ -95,7 +97,7 @@ class Pad(Screen): to_print = to_print[:-1] print(to_print[:-width], end="") if ask_for_input or fancy: - return input(to_print[-width:-1]+ " " * (ogwidth - width - 4) if fancy else "> ") + return input(to_print[-width:-1]+ " " * (ogwidth - width - fmargin) if fancy else "> ") else: print(to_print[-width:], end=endl) return None