-
Notifications
You must be signed in to change notification settings - Fork 20
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
BREAKING: refactor modes and cursor #217
Conversation
53050cf
to
84d03df
Compare
This adds a new type `Method` to the `ansi` package that represents how to calculate the cell widths in the terminal. The default is to use `GraphemeWidth` which keeps the current behavior. In order to use `WcWidth`, you can call the member functions on the `Method` type. ```go ansi.StringWidth("👩👩👧👧") // 2 ansi.GraphemeWidth.StringWidth("👩👩👧👧") // 2 ansi.WcWidth.StringWidth("👩👩👧👧") // 6 ```
84d03df
to
2c97f3a
Compare
ansi/cursor.go
Outdated
@@ -153,7 +153,7 @@ func CursorPreviousLine(n int) string { | |||
// CSI n ; m H | |||
// | |||
// See: https://vt100.net/docs/vt510-rm/CUP.html | |||
func MoveCursor(row, col int) string { | |||
func MoveCursor(col, row int) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change the order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a common pattern to use the x, y int
or col, row int
than the opposite, it was confusing and led me to swap the values sometimes. It was implemented this way because the ANSI sequence (CUP) takes a row then a column in that order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok that totally makes sense. Thanks for explaining!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok that totally makes sense. Thanks for explaining!
This complicates the API and makes it harder to understand. In practice, it only matters during rendering.
MoveCursor indicates that the cursor is moved from one position to another relative to where it is currently. But the actual behavior of the function is to set the cursor to a specific position in the screen.
6d9f350
to
a859bf9
Compare
a859bf9
to
eb4d51c
Compare
ansi.MoveCursor
ansi.MoveCursor
toansi.SetCursorPosition
Implementansi.Method
to respect the cell widths on variousansi
operationsansi.EraseDisplay
constantsTODO: