Skip to content

Add terminal client detection to the RUN section#124

Merged
steffen merged 2 commits intomainfrom
feature/terminal-client-detection
Mar 13, 2026
Merged

Add terminal client detection to the RUN section#124
steffen merged 2 commits intomainfrom
feature/terminal-client-detection

Conversation

@nicklegan
Copy link
Copy Markdown
Collaborator

Summary

Display the terminal client information in the RUN section of the report to help diagnose rendering issues when users share reports. Terminal emulators differ significantly in ANSI escape sequence support, unicode rendering, and color depth, so knowing the terminal makes it much easier to reproduce and fix display problems.

Changes

pkg/utils/utils.goGetTerminalInformation()

Detects the terminal client by checking the following environment variables in order:

  • TERM_PROGRAM + TERM_PROGRAM_VERSION — set by most terminal emulators (iTerm2, Apple Terminal, VSCode, WarpTerminal, Ghostty, Alacritty, etc.)
  • LC_TERMINAL + LC_TERMINAL_VERSION — fallback for SSH sessions (iTerm2 propagates these)
  • WT_SESSION — Windows Terminal detection

Supplementary details shown in parentheses:

  • TERM type (e.g. xterm-256color)
  • COLORTERM color support level (e.g. truecolor)
  • Shell name (basename of SHELL)
  • Terminal dimensions via golang.org/x/term (e.g. 120×30)

Falls back to "Unknown" when no terminal information is available.

Example output:

Terminal                   iTerm2 3.5.10 (xterm-256color, truecolor, zsh, 120×30)

pkg/display/sections/run_information.go

Added Terminal line between Machine and Git metrics version.

script/remove-non-deterministic-rows

Added ^Terminal to the integration test filter since the value varies across environments.

pkg/utils/utils_test.go

Added 3 tests:

  • TestGetTerminalInformationReturnsNonEmpty
  • TestGetTerminalInformationWithTermProgram
  • TestGetTerminalInformationFallsBackToUnknown

Display the terminal program, version, TERM type, color support,
shell, and terminal dimensions in the RUN section of the report.
This information helps diagnose rendering issues when users share
reports, since ANSI escape sequences and unicode character support
vary across terminal clients.

Detection checks TERM_PROGRAM, LC_TERMINAL (for SSH sessions),
and WT_SESSION (for Windows Terminal) environment variables, with
TERM type and terminal dimensions as supplementary details. Falls
back to "Unknown" when no terminal information is available.

The Terminal line is added to the integration test's
non-deterministic row filter since it varies across environments.
Copilot AI review requested due to automatic review settings March 13, 2026 16:14
@nicklegan nicklegan self-assigned this Mar 13, 2026
@nicklegan nicklegan requested a review from steffen March 13, 2026 16:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds terminal client detection to the RUN section of the git-metrics report. Knowing which terminal emulator is in use helps diagnose rendering issues when users share reports, since terminals differ in ANSI, unicode, and color support.

Changes:

  • Added GetTerminalInformation() to pkg/utils/utils.go that detects the terminal program via environment variables (TERM_PROGRAM, LC_TERMINAL, WT_SESSION) and collects supplementary details (TERM type, color support, shell, dimensions).
  • Integrated the new terminal line into the RUN section display and added it to the integration test non-deterministic row filter.
  • Added unit tests for the new function.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/utils/utils.go New GetTerminalInformation() function for detecting terminal client info
pkg/display/sections/run_information.go Added Terminal line to the RUN section output
script/remove-non-deterministic-rows Filter ^Terminal rows in integration tests
pkg/utils/utils_test.go Three unit tests for GetTerminalInformation plus two helper functions

Comment thread pkg/utils/utils_test.go Outdated
Comment thread pkg/utils/utils_test.go Outdated
Comment thread pkg/utils/utils_test.go Outdated
Replace the custom contains/stringContains helper functions with
strings.Contains from the standard library and add a strings
import.

Replace the manual save/defer/restore boilerplate in
TestGetTerminalInformationWithTermProgram and
TestGetTerminalInformationFallsBackToUnknown with t.Setenv, which
automatically restores the original value when the test ends.

Strengthen TestGetTerminalInformationFallsBackToUnknown to assert
result == "Unknown" rather than just non-empty, so the test
actually catches regressions in the fallback path.
@steffen steffen merged commit babfbea into main Mar 13, 2026
7 checks passed
@steffen steffen deleted the feature/terminal-client-detection branch March 13, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants