[llvm] [LLVM] [Support] Query the terminal width using the termios API (PR #143514)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 15 00:40:21 PDT 2025
================
@@ -304,31 +307,41 @@ bool Process::FileDescriptorIsDisplayed(int fd) {
#endif
}
-static unsigned getColumns() {
+static unsigned getColumns([[maybe_unused]] int FileID) {
// If COLUMNS is defined in the environment, wrap to that many columns.
if (const char *ColumnsStr = std::getenv("COLUMNS")) {
int Columns = std::atoi(ColumnsStr);
if (Columns > 0)
return Columns;
}
- // We used to call ioctl TIOCGWINSZ to determine the width. It is considered
- // unuseful.
- return 0;
+ // Unfortunately, COLUMNS is a shell variable, not a proper environment
----------------
MaskRay wrote:
Just delete the first sentence.
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html specifies COLUMNS - This variable shall represent a decimal integer >0 used to indicate the user's preferred width in column positions for the terminal screen or window.
It's not correct to say that it is not an environment variable, it's just that shells don't set it. The words "Unfortunately" and "proper" are also unnecessary.
We should just state that we query the column positions.
https://github.com/llvm/llvm-project/pull/143514
More information about the llvm-commits
mailing list