From: Frank Brehm Date: Thu, 1 Feb 2024 17:13:15 +0000 (+0100) Subject: Adding method print_dot() to class BaseDPXApplication X-Git-Tag: 1.0.0~1^2~14 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=505f2422f027064f337c72a870f65e7cdffbe4dd;p=pixelpark%2Fpp-admin-tools.git Adding method print_dot() to class BaseDPXApplication --- diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index fedbe69..002192a 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -36,7 +36,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.9.1' +__version__ = '0.9.2' # ============================================================================= @@ -52,6 +52,14 @@ class CursorPosition(namedtuple('CursorPosition', ['x', 'y'])): msg += ' x = {x:3d}, y = {y:3d}'.format(x=self.x, y=self.y) return msg + # ------------------------------------------------------------------------- + @property + def unknown(self): + """Return, whether the cursor position is not evaluated.""" + if self.x == -1 and self.y == -1: + return True + return False + # ============================================================================= class BaseDPXApplication(FbConfigApplication): """Base class for all DPX application classes.""" @@ -61,8 +69,6 @@ class BaseDPXApplication(FbConfigApplication): # show_force_option = False show_simulate_option = True - max_term_line_length = 150 - # ------------------------------------------------------------------------- def __init__( self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None, @@ -70,6 +76,8 @@ class BaseDPXApplication(FbConfigApplication): argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None, config_dir=DEFAULT_CONFIG_DIR): """Initialize the BaseDPXApplication object.""" + self.cur_dots = 0 + super(BaseDPXApplication, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, description=description, cfg_class=cfg_class, initialized=False, @@ -183,6 +191,24 @@ class BaseDPXApplication(FbConfigApplication): return CursorPosition(-1, -1) + # ------------------------------------------------------------------------- + def print_dot(self): + """Print out a dot without a newline.""" + max_x = self.max_term_line_length + term_size = shutil.get_terminal_size((DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT)) + max_x = term_size.columns + + cur_pos = self.cursor_position() + if cur_pos.unknown: + cur_pos = self.cur_dots + 1 + + if cur_pos >= max_x: + print() + self.cur_dots = 0 + + print('.', end='', flush=True) + self.cur_dots += 1 + # =============================================================================