]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding method print_dot() to class BaseDPXApplication
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 1 Feb 2024 17:13:15 +0000 (18:13 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 1 Feb 2024 17:13:15 +0000 (18:13 +0100)
lib/pp_admintools/app/__init__.py

index fedbe69da8615a1c0853beee96726689db7cc689..002192a72d2bfde5d798abe5a261d4021b40b5b6 100644 (file)
@@ -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
+
 
 # =============================================================================