git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] chainlint: sidestep impoverished macOS "terminfo"

From
Eric Sunshine via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 9, 2022, 16:58 UTC
Message-ID
<b85b28e5a6beea97c149f0b9de6ba8d0a4a7c1f9.1668013114.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1413.git.1668013114.gitgitgadget@gmail.com>
From: Eric Sunshine <sunshine@sunshineco.com>

Although the macOS Terminal.app is "xterm"-compatible, its corresponding "terminfo" entry neglects to mention capabilities which Terminal.app actually supports (such as "dim text"). This oversight on Apple's part ends up penalizing users of "good citizen" console programs which consult "terminfo" to tailor their output based upon reported terminal capabilities (as opposed to programs which assume that the terminal supports ANSI codes).

Sidestep this Apple problem by imbuing get_colors() with specific knowledge of "xterm" capabilities rather than trusting "terminfo" to report them correctly. Although hard-coding such knowledge is ugly, "xterm" support is nearly ubiquitous these days, and Git itself sets precedence by assuming support for ANSI color codes. For non-"xterm", fall back to querying "terminfo" via `tput` as usual.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/chainlint.pl | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/t/chainlint.pl b/t/chainlint.pl
index 7972c5bbe6f..fcf4d459249 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -653,21 +653,32 @@ my @NOCOLORS = (bold => '', rev => '', reset => '', blue => '', green => '', red
 my %COLORS = ();
 sub get_colors {
 	return \%COLORS if %COLORS;
-	if (exists($ENV{NO_COLOR}) ||
-	    system("tput sgr0 >/dev/null 2>&1") != 0 ||
-	    system("tput bold >/dev/null 2>&1") != 0 ||
-	    system("tput rev  >/dev/null 2>&1") != 0 ||
-	    system("tput setaf 1 >/dev/null 2>&1") != 0) {
+	if (exists($ENV{NO_COLOR})) {
 		%COLORS = @NOCOLORS;
 		return \%COLORS;
 	}
-	%COLORS = (bold  => `tput bold`,
-		   rev   => `tput rev`,
-		   reset => `tput sgr0`,
-		   blue  => `tput setaf 4`,
-		   green => `tput setaf 2`,
-		   red   => `tput setaf 1`);
-	chomp(%COLORS);
+	if ($ENV{TERM} =~ /\bxterm\b/) {
+		%COLORS = (bold  => "\e[1m",
+			   rev   => "\e[7m",
+			   reset => "\e[0m",
+			   blue  => "\e[34m",
+			   green => "\e[32m",
+			   red   => "\e[31m");
+		return \%COLORS;
+	}
+	if (system("tput sgr0 >/dev/null 2>&1") == 0 &&
+	    system("tput bold >/dev/null 2>&1") == 0 &&
+	    system("tput rev  >/dev/null 2>&1") == 0 &&
+	    system("tput setaf 1 >/dev/null 2>&1") == 0) {
+		%COLORS = (bold  => `tput bold`,
+			   rev   => `tput rev`,
+			   reset => `tput sgr0`,
+			   blue  => `tput setaf 4`,
+			   green => `tput setaf 2`,
+			   red   => `tput setaf 1`);
+		return \%COLORS;
+	}
+	%COLORS = @NOCOLORS;
 	return \%COLORS;
 }
 
-- 
gitgitgadget
Previous: Eric Sunshine via GitGitGadgetNext: Taylor Blau
Message 2 of 20 in “chainlint: emit line numbers alongside test definitions”
  1. 0/3 chainlint: emit line numbers alongside test definitionsEric Sunshine via GitGitGadget, Nov 9, 2022
  2. 1/3 chainlint: sidestep impoverished macOS "terminfo"Eric Sunshine via GitGitGadget, Nov 9, 2022
  3. Taylor BlauNov 9, 2022
  4. brian m. carlsonNov 10, 2022
  5. Eric SunshineNov 10, 2022
  6. brian m. carlsonNov 10, 2022
  7. Eric SunshineNov 10, 2022
  8. brian m. carlsonNov 10, 2022
  9. 2/3 chainlint: latch line numbers at which each token starts and endsEric Sunshine via GitGitGadget, Nov 9, 2022
  10. 3/3 chainlint: prefix annotated test definition with line numbersEric Sunshine via GitGitGadget, Nov 9, 2022
  11. Taylor BlauNov 9, 2022
  12. 0/3 chainlint: emit line numbers alongside test definitionsEric Sunshine via GitGitGadget, Nov 11, 2022
  13. 1/3 chainlint: sidestep impoverished macOS "terminfo"Eric Sunshine via GitGitGadget, Nov 11, 2022
  14. Ævar Arnfjörð BjarmasonNov 11, 2022
  15. Eric SunshineNov 11, 2022
  16. Eric SunshineNov 11, 2022
  17. Taylor BlauNov 11, 2022
  18. 2/3 chainlint: latch line numbers at which each token starts and endsEric Sunshine via GitGitGadget, Nov 11, 2022
  19. 3/3 chainlint: prefix annotated test definition with line numbersEric Sunshine via GitGitGadget, Nov 11, 2022
  20. Ævar Arnfjörð BjarmasonNov 11, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.