Skip to content

Commit 9de62e3

Browse files
tDwtpBenedikt Roland
andauthored
Expanded tab settings to accommodate different styles. (linux-test-project#455)
* Expanded tab settings to accommodate different styles. '--num-spaces' now allows any numerical value. alter apperance via negative values. replace with spaces via positive values (backwards compatible). do not alter tabs or their apperance via 0. help and man pages updated to reflect the changes. default (8) is unchanged. minor tweak to man pages: num replaced with spaces for consistency. NOTE: uses CSS3 'tab-size' (for altering tab apperance). Widely available since 2021. Webkit since around 2013. * fix typo --------- Co-authored-by: Benedikt Roland <Benedikt.Roland@heidelberg-instruments.com>
1 parent 751a063 commit 9de62e3

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

bin/genhtml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7254,12 +7254,6 @@ if ($css_filename) {
72547254
}
72557255
}
72567256

7257-
# Make sure tab_size is within valid range
7258-
if ($tab_size < 1) {
7259-
print(STDERR "ERROR: invalid number of spaces specified: $tab_size!\n");
7260-
exit(1);
7261-
}
7262-
72637257
# Get HTML prolog and epilog
72647258
$html_prolog = get_html_prolog($html_prolog_file);
72657259
$html_epilog = get_html_epilog($html_epilog_file);
@@ -7474,7 +7468,10 @@ HTML OUTPUT
74747468
--header-title BANNER Banner at top of each HTML page
74757469
--footer FOOTER Footer at bottom of each HTML page
74767470
--no-sourceview Do not create source code view
7477-
--num-spaces NUM Replace tabs with NUM spaces in source view
7471+
--num-spaces NUM change appearance of tabs in source view
7472+
NUM == 0 will not touch tabs
7473+
NUM > 0 will replace them with NUM spaces
7474+
NUM < 0 will only change their appearance
74787475
--legend Include color legend in HTML output
74797476
--html-prolog FILE Use FILE as HTML prolog for generated pages
74807477
--html-epilog FILE Use FILE as HTML epilog for generated pages
@@ -8477,9 +8474,11 @@ sub escape_html($)
84778474
$string =~ s/>/&gt;/g; # > -> &gt;
84788475
$string =~ s/\"/&quot;/g; # " -> &quot;
84798476

8480-
while ($string =~ /^([^\t]*)(\t)/) {
8481-
my $replacement = " " x ($tab_size - (length($1) % $tab_size));
8482-
$string =~ s/^([^\t]*)(\t)/$1$replacement/;
8477+
if ($tab_size > 0) {
8478+
while ($string =~ /^([^\t]*)(\t)/) {
8479+
my $replacement = " " x ($tab_size - (length($1) % $tab_size));
8480+
$string =~ s/^([^\t]*)(\t)/$1$replacement/;
8481+
}
84838482
}
84848483

84858484
$string =~ s/\n/<br>/g; # \n -> <br>
@@ -9358,6 +9357,7 @@ sub write_css_file()
93589357
font-family: monospace;
93599358
white-space: pre;
93609359
margin-top: 2px;
9360+
tab-size: #TAB_SIZE;
93619361
}
93629362
93639363
/* elided/removed code */
@@ -9559,6 +9559,13 @@ END_OF_DATE_SPAN
95599559
$css_data =~ s/$key/$color/gm;
95609560
}
95619561

9562+
if ($tab_size < 0) {
9563+
my $abs_tab_size = abs($tab_size);
9564+
$css_data =~ s/#TAB_SIZE/$abs_tab_size/gm;
9565+
} else {
9566+
$css_data =~ s/^.*#TAB_SIZE.*\n//gm;
9567+
}
9568+
95629569
print(CSS_HANDLE $css_data);
95639570

95649571
close(CSS_HANDLE) or die("unable to close CSS handle: $!\n");

man/genhtml.1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,8 +2686,17 @@ the coverage criteria check or the serialized coverage DB,
26862686
.RE
26872687
.BI "\-\-num\-spaces " spaces
26882688
.RS
2689-
Replace tabs in source view with
2690-
.I num
2689+
Change appearance of tabs in source view according to
2690+
.IR spaces .
2691+
2692+
When set to 0, tabs and their behaviour will be the browser's default.
2693+
.br
2694+
Negative values will set the rendered width in the source view to
2695+
.I spaces
2696+
spaces.
2697+
.br
2698+
Positive values will replace tabs with
2699+
.I spaces
26912700
spaces.
26922701

26932702
Default value is 8.

0 commit comments

Comments
 (0)