Skip to content

Conversation

DavidSpickett
Copy link
Collaborator

@DavidSpickett DavidSpickett commented Jun 9, 2025

I can't find a proper source for this but many materials say that ANSI rows and columns start at 1 not 0.

https://www2.math.upenn.edu/~kazdan/210/computer/ansi.html is as good as I can get:

<row> is a number from 1 through 25 that specifies the row to which the cursor is to be moved.
<col> is a number from 1 through 80 that specifies the column to which the cursor is to be moved.

0 does work in Windows terminal and Linux terminals, but we might as well be correct and it's one less thing to reason about when auditing this code.

From what I read, some terminals correct 0 back to 1 and some treat 0 as a missing argument, which also defaults to 1.

I can't find a proper source for this but many materials
say that ANSI rows and columns start at 1 not 0.

https://www2.math.upenn.edu/~kazdan/210/computer/ansi.html
is as good as I can get:
<row> is a number from 1 through 25 that specifies the row to which the cursor is to be moved.
<col> is a number from 1 through 80 that specifies the column to which the cursor is to be moved.

0 does work in Windows terminal and Linux terminals,
but we might as well be correct.

From what I read, some terminals correct 0 back to 1
and some treat 0 as a missing argument, which also
defaults to 1.
@llvmbot
Copy link
Member

llvmbot commented Jun 9, 2025

@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)

Changes

I can't find a proper source for this but many materials say that ANSI rows and columns start at 1 not 0.

https://www2.math.upenn.edu/~kazdan/210/computer/ansi.html is as good as I can get:
<row> is a number from 1 through 25 that specifies the row to which the cursor is to be moved. <col> is a number from 1 through 80 that specifies the column to which the cursor is to be moved.

0 does work in Windows terminal and Linux terminals, but we might as well be correct and it's one less thing to reason about when auditing this code.

From what I read, some terminals correct 0 back to 1 and some treat 0 as a missing argument, which also defaults to 1.


Full diff: https://github.com/llvm/llvm-project/pull/143385.diff

1 Files Affected:

  • (modified) lldb/source/Core/Statusline.cpp (+2-2)
diff --git a/lldb/source/Core/Statusline.cpp b/lldb/source/Core/Statusline.cpp
index 52f6134123b76..8a8640805cac0 100644
--- a/lldb/source/Core/Statusline.cpp
+++ b/lldb/source/Core/Statusline.cpp
@@ -24,8 +24,8 @@
 #define ANSI_SAVE_CURSOR ESCAPE "7"
 #define ANSI_RESTORE_CURSOR ESCAPE "8"
 #define ANSI_CLEAR_BELOW ESCAPE "[J"
-#define ANSI_SET_SCROLL_ROWS ESCAPE "[0;%ur"
-#define ANSI_TO_START_OF_ROW ESCAPE "[%u;0f"
+#define ANSI_SET_SCROLL_ROWS ESCAPE "[1;%ur"
+#define ANSI_TO_START_OF_ROW ESCAPE "[%u;1f"
 #define ANSI_REVERSE_VIDEO ESCAPE "[7m"
 #define ANSI_UP_ROWS ESCAPE "[%dA"
 

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

Thanks!

@DavidSpickett DavidSpickett merged commit 6ec48b4 into llvm:main Jun 10, 2025
7 checks passed
@DavidSpickett DavidSpickett deleted the lldb-ansi branch June 10, 2025 08:59
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
I can't find a proper source for this but many materials say that ANSI
rows and columns start at 1 not 0.

https://www2.math.upenn.edu/~kazdan/210/computer/ansi.html is as good as
I can get:
```
<row> is a number from 1 through 25 that specifies the row to which the cursor is to be moved.
<col> is a number from 1 through 80 that specifies the column to which the cursor is to be moved.
```

0 does work in Windows terminal and Linux terminals, but we might as
well be correct and it's one less thing to reason about when auditing
this code.

From what I read, some terminals correct 0 back to 1 and some treat 0 as
a missing argument, which also defaults to 1.
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Jul 3, 2025
I can't find a proper source for this but many materials say that ANSI
rows and columns start at 1 not 0.

https://www2.math.upenn.edu/~kazdan/210/computer/ansi.html is as good as
I can get:
```
<row> is a number from 1 through 25 that specifies the row to which the cursor is to be moved.
<col> is a number from 1 through 80 that specifies the column to which the cursor is to be moved.
```

0 does work in Windows terminal and Linux terminals, but we might as
well be correct and it's one less thing to reason about when auditing
this code.

From what I read, some terminals correct 0 back to 1 and some treat 0 as
a missing argument, which also defaults to 1.

(cherry picked from commit 6ec48b4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants