Skip to content

Implement CLI TTY/terminal width/coloring #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 8, 2025
Merged

Implement CLI TTY/terminal width/coloring #1538

merged 11 commits into from
Aug 8, 2025

Conversation

jakebailey
Copy link
Member

TTY detection means we'll stop printing out pretty results by default without a TTY.

With that in place, we can implement createColors and do the colorization code for the rest of the CLI. I've implemented that, though it's likely not optimal. Not really a big deal given what I implemented is mainly code for --help or similar.

Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

one of: none, commonjs, amd, system, umd, es6/es2015, es2020, es2022, esnext, node16, node18, nodenext, preserve
default: undefined
 --lib Specify a set of bundled library declaration files that describe the target runtime environment .
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, es next, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.itera ble, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2 015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellkn own, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017. sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asy nciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es20 19.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint , es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2 020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.i ntl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es20 23.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/ esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/ esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, decorators, decorators.legacy
Copy link
Member Author

Choose a reason for hiding this comment

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

This line looks weird, but it turns out that this is actually exactly what Strada does if you fix bugs in the test suite that prevent this code from being tested. I think we've never noticed that this was broken because most people's terminals would wrap the line.

Copy link
Member Author

Choose a reason for hiding this comment

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

I now "fix" the bug here by adding the newline that was missing.

Copy link
Member Author

@jakebailey jakebailey Aug 7, 2025

Choose a reason for hiding this comment

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

I'm happy to leave it "broken", though, since it technically matches the old behavior. It would be nice if this code did word wrapping but that's another issue for another day.

@jakebailey jakebailey requested a review from Copilot August 7, 2025 23:25
Copy link
Contributor

@Copilot 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 implements TTY/terminal width detection and coloring for the CLI help output. The key change is adding proper TTY detection to stop printing colorized output when not outputting to a TTY, along with implementing proper color support for help text formatting.

Key changes:

  • Added TTY detection and terminal width querying capabilities to the system interface
  • Implemented a createColors function with proper color code generation for different terminal environments
  • Updated help output formatting to use colors and terminal width-aware layout

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/execute/system.go Added new system interface methods for TTY detection, terminal width, and environment variables
internal/execute/outputs.go Implemented color system and updated help formatting to use colors and terminal width
internal/core/tristate.go Added IsUnknown() method for tristate values
cmd/tsgo/sys.go Implemented TTY detection and terminal width querying for the OS system
internal/execute/testsys_test.go Added test system support for TTY/terminal width simulation
internal/execute/tsc_test.go Updated test cases to use environment variables for terminal width testing
internal/execute/tsctestrunner_test.go Added environment variable support to test runner
go.mod Added golang.org/x/term dependency
testdata/baselines/reference/*.js Updated test baselines showing colorized help output

@jakebailey jakebailey added this pull request to the merge queue Aug 8, 2025
Merged via the queue into main with commit 47e7268 Aug 8, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/tty branch August 8, 2025 06:58
@alexsch01
Copy link

alexsch01 commented Aug 9, 2025

Is there a way to bypass this - print pretty results in an environment that's detected as a TTY? @jakebailey

@jakebailey
Copy link
Member Author

Yes, --pretty or in tsconfig.

If you're seeing this behave differently to tsc, please file an issue.

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