Ver código fonte

feat: unified dim-track bar rendering — solid fill (fg+bg same) for full blocks, dim background for track (all interactive modes incl. phase bars), partial blocks in bar colour on track

clanker 1 semana atrás
pai
commit
5f8d69c33b
1 arquivos alterados com 46 adições e 19 exclusões
  1. 46 19
      src/cli/ProgressBar.vala

+ 46 - 19
src/cli/ProgressBar.vala

@@ -406,12 +406,13 @@ namespace Usm.Cli {
          * The bar zone proper — gap, fill cells, gap and the fraction's
          * percentage right-aligned in a `100%`-wide field.
          *
-         * When {@link colour} is provided (transaction bar), filled cells
-         * render with identical foreground+background — a seamless solid
-         * bar with no inter-character gaps — and the partial cell carries
-         * a dim background so the bar's edge stays defined against the
-         * empty cells (plain spaces). Phase bars pass null and render
-         * partial-block characters on spaces.
+         * All interactive modes render the bar as a coloured track:
+         * full cells use identical foreground+background (a seamless
+         * solid bar with no inter-character gaps), the partial cell
+         * carries the bar colour on the dim track background, and empty
+         * cells are the dim track itself. The track is always visually
+         * defined. {@link colour} selects the fill (task colour, or
+         * bright white when null for phase bars).
          */
         private string bar_text(int bar_zone, float fraction, string? colour = null) {
             var percent = (int)(fraction * 100);
@@ -436,30 +437,56 @@ namespace Usm.Cli {
 
             var cells = new StringBuilder();
             cells.append(" ");
-            if(!unicode) {
-                cells.append("[");
-            }
 
-            if(colour != null && unicode) {
-                var bg = colour.replace("[3", "[4");
-                cells.append(colour);
+            if(interactive && unicode) {
+                var fg = colour ?? "\x1b[97m";
+                var bg = fg.contains("[9") ? fg.replace("[9", "[10") : fg.replace("[3", "[4");
+                const string DIM_BG = "\x1b[100m";
+                const string RESET = "\x1b[0m";
+
+                cells.append(fg);
                 cells.append(bg);
                 for(var i = 0; i < full; i++) {
                     cells.append(" ");
                 }
+                cells.append(RESET);
+                cells.append(DIM_BG);
                 if(full < capacity && eighths > 0) {
-                    cells.append("\033[49m");
-                    cells.append(colour);
-                    cells.append("\033[100m");
+                    cells.append(fg);
                     cells.append(partial_blocks[eighths]);
+                    cells.append(RESET);
+                    cells.append(DIM_BG);
                     full++;
                 }
-                cells.append("\033[0m");
                 for(var i = full; i < capacity; i++) {
                     cells.append(" ");
                 }
+                cells.append(RESET);
+            }
+            else if(interactive && !unicode) {
+                var fg = colour ?? "\x1b[97m";
+                var bg = fg.contains("[9") ? fg.replace("[9", "[10") : fg.replace("[3", "[4");
+                const string DIM_BG = "\x1b[100m";
+                const string RESET = "\x1b[0m";
+
+                cells.append("[");
+                cells.append(fg);
+                cells.append(bg);
+                for(var i = 0; i < full; i++) {
+                    cells.append("#");
+                }
+                cells.append(RESET);
+                cells.append(DIM_BG);
+                for(var i = full; i < capacity; i++) {
+                    cells.append(" ");
+                }
+                cells.append(RESET);
+                cells.append("]");
             }
             else {
+                if(!unicode) {
+                    cells.append("[");
+                }
                 for(var i = 0; i < full; i++) {
                     cells.append(bar_filled_char);
                 }
@@ -470,11 +497,11 @@ namespace Usm.Cli {
                 for(var i = full; i < capacity; i++) {
                     cells.append(" ");
                 }
+                if(!unicode) {
+                    cells.append("]");
+                }
             }
 
-            if(!unicode) {
-                cells.append("]");
-            }
             cells.append(" ");
             cells.append("%3d%%".printf(percent));
             return cells.str;