-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
748c72e
refactor(ansi): change mode.go to use types for modes
aymanbagabas 7817556
refactor(ansi): change order of arguments in MoveCursor
aymanbagabas e040579
feat(ansi): add method type for cell width calculation
aymanbagabas e9757d9
fix: ansi: use method receiver for StringWidth
aymanbagabas 2c97f3a
feat(ansi): add more tests for wcwidth and grapheme width methods
aymanbagabas 54c5365
chore(ansi): update wcwidth
aymanbagabas 04cef54
feat(ansi): add Strip method
aymanbagabas 87d8e7f
docs(ansi): godoc Cmd type reference
aymanbagabas bfe4e9f
chore: revert using width methods
aymanbagabas a3ac3b8
fix(ansi): rename MoveCursor to SetCursorPosition
aymanbagabas 6fbefb1
chore(ansi): go mod tidy
aymanbagabas eb4d51c
refactor(ansi): rename EraseDisplay constants to EraseScreen and add …
aymanbagabas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
github.com/charmbracelet/x/wcwidth v0.0.0-20241022174419-46d9bb99a691 h1:XxrWKvvGJaroJNEgoGGBfCGn/s/67TvhJVTF265WwfA= | ||
github.com/charmbracelet/x/wcwidth v0.0.0-20241022174419-46d9bb99a691/go.mod h1:Ey8PFmYwH+/td9bpiEx07Fdx9ZVkxfIjWXxBluxF4Nw= | ||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= | ||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= | ||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ansi | ||
|
||
// Method is a type that represents the how to calculate the cell widths in the | ||
// terminal. The default is to use [WcWidth]. Some terminals use grapheme | ||
// clustering by default. Some support mode 2027 to tell the terminal to use | ||
// mode 2027 instead of wcwidth. | ||
type Method uint8 | ||
|
||
// Display width modes. | ||
const ( | ||
WcWidth Method = iota | ||
GraphemeWidth | ||
) | ||
|
||
// String returns the string representation of the Method. | ||
func (m Method) String() string { | ||
switch m { | ||
case WcWidth: | ||
return "WcWidth" | ||
case GraphemeWidth: | ||
return "GraphemeWidth" | ||
default: | ||
return "Unknown" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orcol, 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!