From a13b80a2b4450161adb817165fd5f7a95be72811 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 5 May 2019 17:05:20 +0300 Subject: [PATCH] preserve indents to help minimise whitespace changes --- tools/gen-styles | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/tools/gen-styles b/tools/gen-styles index 19c420a4..0e894e9f 100644 --- a/tools/gen-styles +++ b/tools/gen-styles @@ -163,15 +163,18 @@ my $baseTheme = "AppTheme.NoActionBar"; # HSL sub outputThemes { my $out = shift; - $out->print(hslStyleForHue($baseColorHue)); + my $baseIndent = shift; + $out->print(hslStyleForHue($baseColorHue, undef, $baseIndent)); for( my $hue = 0; $hue < 360; $hue += 15 ) { - $out->print(hslStyleForHue($hue, $baseTheme)); + $out->print("\n"); + $out->print(hslStyleForHue($hue, $baseTheme, $baseIndent)); } } sub hslStyleForHue { my $hue = shift; my $base = shift; + my $baseIndent = shift // ''; my $blueL = 0.665; my $yellowL = 0.350; @@ -190,31 +193,32 @@ sub hslStyleForHue { my $l4 = 0.980; my $result = ""; + my $indent = "$baseIndent "; if ($base) { - $result .= sprintf "\n"; + $result .= "$baseIndent\n"; return $result; } @@ -226,16 +230,18 @@ if ($xml) { my $end_marker = ''; my ($fh, $filename) = tempfile(basename($0).'.XXXXXXXX', DIR => dirname($xml)); open(my $in, '<', $xml); + my $base_indent = ''; my $state = 'waiting-for-start-marker'; while (<$in>) { if ( $state eq 'waiting-for-start-marker' ) { print $fh $_; - $state = 'skipping-styles' if /^\s*\Q$start_marker\E/; + $state = 'skipping-styles', $base_indent = $1 + if /^(\s*)\Q$start_marker\E/; next; } if ( $state eq 'skipping-styles' ) { next unless /^\s*\Q$end_marker\E/; - outputThemes($fh); + outputThemes($fh, $base_indent); print $fh $_; $state = 'copying-the-rest'; next; -- 2.39.2