-
-
Notifications
You must be signed in to change notification settings - Fork 48
Add ansi escape codes #199
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
Open
csos95
wants to merge
9
commits into
ponylang:main
Choose a base branch
from
csos95:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
63c2e0f
add rfc for adding ansi escape codes
csos95 673734d
add item for show/hide cursor
csos95 d6ca849
add items for more text styles and cursor stuff
csos95 80926b3
Update text/0000-add-ansi-escape-codes.md
csos95 3fd41f9
update rfc to only include additions
csos95 15f6665
fix spelling
csos95 3a95040
Update text/0000-add-ansi-escape-codes.md
csos95 6eb358b
Update text/0000-add-ansi-escape-codes.md
csos95 575812b
Update text/0000-add-ansi-escape-codes.md
csos95 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 hidden or 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,88 @@ | ||||||||||||
- Feature Name: add_ansi_escape_codes | ||||||||||||
- Start Date: 2022-02-14 | ||||||||||||
- RFC PR: (leave this empty) | ||||||||||||
- Pony Issue: (leave this empty) | ||||||||||||
|
||||||||||||
# Summary | ||||||||||||
|
||||||||||||
This RFC proposes the addition of more escape code functions to the ANSI | ||||||||||||
primitive of the term package. | ||||||||||||
|
||||||||||||
# Motivation | ||||||||||||
|
||||||||||||
The purpose of these additional methods is to cover more of the standard ANSI | ||||||||||||
escape codes within the stdlib. | ||||||||||||
|
||||||||||||
# Detailed design | ||||||||||||
|
||||||||||||
## Added Escape Codes | ||||||||||||
|
||||||||||||
- 8-bit foreground `\x1B[38;5;nm` and background `\x1B[48;5;nm` colors | ||||||||||||
- 24-bit foreground `\x1B[38;2;r;g;bm` and background `\x1B[48;2;r;g;bm` colors | ||||||||||||
- enter alternate screen buffer `\x1B[?1049h` and leave alternate screen buffer `\x1B[?1049l` | ||||||||||||
- bell alert `\x7` | ||||||||||||
- scroll up `\x1B[nS` and scroll down `\x1B[nT` | ||||||||||||
- next line `\x1B[nE` and previous line `\x1B[nF` | ||||||||||||
- cursor horizontal absolute `\x1B[nG` | ||||||||||||
- hide cursor `\x1B[?25l` and show cursor `\x1B[?25h` | ||||||||||||
- save cursor position `\x1B[s` and restore cursor position `\x1B[u` | ||||||||||||
- device status report `\x1B[6n` (sends cursor position to stdin) | ||||||||||||
- faint `\x1B[2m`, italic `\x1B[3m`, conceal `\x1B[8m`, and strike `\x1B[9m` text | ||||||||||||
- erase in display `\x1B[nJ` | ||||||||||||
- erase in line `\x1B[nK` | ||||||||||||
|
||||||||||||
|
||||||||||||
## Erase In Display/Line | ||||||||||||
|
||||||||||||
There are currently two similar functions, but they have a couple of issues: | ||||||||||||
|
||||||||||||
- Neither of them expose the parameter that the escape codes take. | ||||||||||||
- The `clear` function moves the cursor to the top left and then clears the screen. | ||||||||||||
This may have been done to create the same result that this escape code gave on DOS. | ||||||||||||
|
||||||||||||
Unlike the other added escape codes, these two only have a few valid values | ||||||||||||
for the parameters. | ||||||||||||
To enforce the safety of these functions using the type system, four primitives | ||||||||||||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
and two type unions would be defined to be used as the parameters for these | ||||||||||||
two functions. | ||||||||||||
|
||||||||||||
```pony | ||||||||||||
primitive EraseAfter | ||||||||||||
primitive EraseBefore | ||||||||||||
primitive EraseAll | ||||||||||||
primitive EraseBuffer | ||||||||||||
|
||||||||||||
type EraseDisplay is (EraseAfter | EraseBefore | EraseAll | EraseBuffer) | ||||||||||||
type EraseLine is (EraseAfter | EraseBefore | EraseAll) | ||||||||||||
``` | ||||||||||||
# How We Teach This | ||||||||||||
|
||||||||||||
The added functions would be documented as the existing functions on the `ANSI` | ||||||||||||
primitive are and an example of usage would be added to `ANSI`. | ||||||||||||
|
||||||||||||
# How We Test This | ||||||||||||
|
||||||||||||
The functions that have parameters would have tests added to ensure that they | ||||||||||||
return the correct escape code for the given parameters. | ||||||||||||
|
||||||||||||
The functions that would have parameters and would be tested are: | ||||||||||||
|
||||||||||||
- 8-bit and 24-bit colors for the foreground and background | ||||||||||||
- scroll up and scroll down | ||||||||||||
- next line and previous line | ||||||||||||
- cursor horizontal absolute | ||||||||||||
- erase_display | ||||||||||||
- erase_line | ||||||||||||
|
||||||||||||
# Drawbacks | ||||||||||||
|
||||||||||||
Some escape codes may not work on all terminals. | ||||||||||||
|
||||||||||||
# Alternatives | ||||||||||||
|
||||||||||||
Don't add these escape code functions and have users look up and print the | ||||||||||||
escape codes they want. | ||||||||||||
|
||||||||||||
# Unresolved questions | ||||||||||||
|
||||||||||||
None |
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.
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.
If that extra newline is added, the next line would be split out into a separate paragraph instead of being attached to the bullet point about the functionality of the current clear function.