user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] view: avoid excessive indentation in thread summary
@ 2015-12-30 22:32  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2015-12-30 22:32 UTC (permalink / raw)
  To: meta

We already use "` " (backtick + space) to denote one indentation
level, so do not excessively indent and always pad with one
level less of spaces.

The 'x' operator in Perl handles negative values, so subtracting
one from level=0 will result in an empty string without spaces.
---
 lib/PublicInbox/View.pm | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index bcd2ebc..ad03cfe 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -684,6 +684,11 @@ sub __thread_entry {
 	1;
 }
 
+sub indent_for {
+	my ($level) = @_;
+	INDENT x ($level - 1);
+}
+
 sub __ghost_prepare {
 	my ($state, $node, $level) = @_;
 	my $ghost = $state->{ghost} ||= [];
@@ -753,7 +758,7 @@ sub _inline_header {
 	my $d = _msg_date($mime);
 	$f = PublicInbox::Hval->new($f)->as_html;
 	$d = PublicInbox::Hval->new($d)->as_html;
-	my $pfx = ' ' . $d . ' ' . (INDENT x $level);
+	my $pfx = ' ' . $d . ' ' . indent_for($level);
 	my $attr = $f;
 	$state->{first_level} ||= $level;
 
@@ -809,7 +814,7 @@ sub inline_dump {
 	} else {
 		my $dot = $level == 0 ? '' : '` ';
 		my $pfx = (' ' x length(' 1970-01-01 13:37 ')).
-			(INDENT x $level) . $dot;
+			indent_for($level) . $dot;
 		$$dst .= $pfx;
 		$$dst .= ghost_parent("$upfx../", $node->messageid) . "\n";
 	}
@@ -887,7 +892,7 @@ sub dump_topics {
 		my ($mid, $ts) = @{delete $latest->{$topic}};
 		$mid = PublicInbox::Hval->new($mid)->as_href;
 		$subj = PublicInbox::Hval->new($subj)->as_html;
-		$pfx = INDENT x ($level - 1);
+		$pfx = indent_for($level);
 		my $nl = $level == $prev ? "\n" : '';
 		my $dot = $level == 0 ? '' : '` ';
 		$dst .= "$nl$pfx$dot<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-12-30 22:32  7% [PATCH] view: avoid excessive indentation in thread summary Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).