Prechádzať zdrojové kódy

feat: solid-colour bar (fg+bg same, no gaps), partial block with dim background, spaces for empty cells, no ░ character

clanker 1 týždeň pred
rodič
commit
b2973941fa
2 zmenil súbory, kde vykonal 51 pridanie a 49 odobranie
  1. 1 20
      installer/install-usm.sh
  2. 50 29
      src/cli/ProgressBar.vala

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 20
installer/install-usm.sh


+ 50 - 29
src/cli/ProgressBar.vala

@@ -128,9 +128,9 @@ namespace Usm.Cli {
             unowned string charset;
             unicode = get_charset(out charset);
             bar_filled_char = unicode ? "█" : "#";
-            bar_empty_char = unicode ? "░" : " ";
+            bar_empty_char = " ";
             if(unicode) {
-                partial_blocks = { "", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
+                partial_blocks = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
             }
             else {
                 partial_blocks = { " ", ".", ":", "-", "=", "+", "*", "#", "#" };
@@ -349,7 +349,7 @@ namespace Usm.Cli {
         }
 
         private void draw_line() {
-            stderr.printf("\r\033[K%s%s%s", colour_for_task(current_task), line_text(), COLOUR_RESET);
+            stderr.printf("\r\033[K%s", line_text());
             line_live = true;
         }
 
@@ -367,11 +367,14 @@ namespace Usm.Cli {
         private string line_text() {
             var width = detect_terminal_width();
             var text_zone = int.max(14, width / 3);
+            var colour = colour_for_task(current_task);
 
             var cells = new StringBuilder();
+            cells.append(colour);
             cells.append(zone_text(text_zone));
             pad_to_zone(cells, text_zone);
-            cells.append(bar_text(width - text_zone, overall));
+            cells.append(COLOUR_RESET);
+            cells.append(bar_text(width - text_zone, overall, colour));
             return cells.str;
         }
 
@@ -387,7 +390,7 @@ namespace Usm.Cli {
             var cells = new StringBuilder();
             cells.append(ellipsise(phase_label ?? "", text_zone));
             pad_to_zone(cells, text_zone);
-            cells.append(bar_text(width - text_zone, phase_progress));
+            cells.append(bar_text(width - text_zone, phase_progress, null));
             return cells.str;
         }
 
@@ -400,14 +403,17 @@ namespace Usm.Cli {
         }
 
         /**
-         * The bar zone proper — gap, `█`/`░` cells (`[####    ]` in the
-         * ASCII fallback), gap and the fraction's percentage
-         * right-aligned in a `100%`-wide field. The fixed percentage
-         * field keeps the cell count constant from 0% to 100%, and the
-         * fill uses + 0.5 rounding in plain arithmetic because the CLI
-         * target does not link libm.
+         * 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.
          */
-        private string bar_text(int bar_zone, float fraction) {
+        private string bar_text(int bar_zone, float fraction, string? colour = null) {
             var percent = (int)(fraction * 100);
             var capacity = bar_zone - 6 - (unicode ? 0 : 2);
 
@@ -423,15 +429,7 @@ namespace Usm.Cli {
             if(eighths > 8) {
                 eighths = 8;
             }
-            if(eighths > 0 && full < capacity) {
-                // The partial cell absorbs the fraction — full cells plus
-                // one partial, eighths 8 collapses into a full cell
-                if(eighths == 8) {
-                    full++;
-                    eighths = 0;
-                }
-            }
-            else if(eighths == 8) {
+            if(eighths == 8) {
                 full++;
                 eighths = 0;
             }
@@ -441,16 +439,39 @@ namespace Usm.Cli {
             if(!unicode) {
                 cells.append("[");
             }
-            for(var i = 0; i < full; i++) {
-                cells.append(bar_filled_char);
-            }
-            if(full < capacity && eighths > 0) {
-                cells.append(partial_blocks[eighths]);
-                full++;
+
+            if(colour != null && unicode) {
+                var bg = colour.replace("[3", "[4");
+                cells.append(colour);
+                cells.append(bg);
+                for(var i = 0; i < full; i++) {
+                    cells.append(" ");
+                }
+                if(full < capacity && eighths > 0) {
+                    cells.append("\033[49m");
+                    cells.append(colour);
+                    cells.append("\033[100m");
+                    cells.append(partial_blocks[eighths]);
+                    full++;
+                }
+                cells.append("\033[0m");
+                for(var i = full; i < capacity; i++) {
+                    cells.append(" ");
+                }
             }
-            for(var i = full; i < capacity; i++) {
-                cells.append(bar_empty_char);
+            else {
+                for(var i = 0; i < full; i++) {
+                    cells.append(bar_filled_char);
+                }
+                if(full < capacity && eighths > 0) {
+                    cells.append(partial_blocks[eighths]);
+                    full++;
+                }
+                for(var i = full; i < capacity; i++) {
+                    cells.append(" ");
+                }
             }
+
             if(!unicode) {
                 cells.append("]");
             }

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov