Skip to content
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

Add ansi escape codes #199

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
63 changes: 63 additions & 0 deletions text/0000-add-ansi-escape-codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- 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 and the consolidation of the thirty-two existing color functions into four functions.
csos95 marked this conversation as resolved.
Show resolved Hide resolved

# Motivation

The purpose of these additional methods is to cover more of the standard ANSI escape codes within the stdlib.

# Detailed design

- Add escape codes for 3-bit, 4-bit, 8-bit, and 24-bit colors for the foreground and background.
The naming scheme of the color functions would be `{fg,bg}_{3,4,8,24}bit`.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
The 3-bit, 4-bit, and 8-bit versions would take a U8 specifying the color.
The 24-bit versions would take three U8s specifying the r, g, and b values.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
- Remove the thirty-two named color functions in favor of the 3-bit and 4-bit functions.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
- Add escape codes for enter and leave alternate screen buffer.
- Add escape code for the bell alert.
- Change `clear` and `erase` functions to take a U8 specifying what part of the screen/line to clear.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
The default for the escape codes if a value isn't given is zero.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
The action these functions currently take is three for `clear` and one for `erase`.
I would like to have the default value in these functions be zero.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
- Add escape codes for scroll up/down.
- Add escape codes for next/previous line.
- Add escape code for cursor horizontal position (moves the cursor to column n in the current line).
- Add escape codes for hide/show cursor.
- Add escape codes for save/restore cursor position.
- Add escape code for get cursor position (it is sent to stdin).
- Add escape codes for various text styles: italic, strike, conceal, faint.
csos95 marked this conversation as resolved.
Show resolved Hide resolved

If a value passed to any of the functions is invalid, such as 200 being passed to `fg_3bit`, an empty string would be returned.
csos95 marked this conversation as resolved.
Show resolved Hide resolved

# 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

I could not find existing testing for the `ANSI` primitive.
If there are existing tests for these functions, additional tests in the same format would be added to ensure that the new functions return the correct escape codes.
Most of these functions are just directly returning a string of the escape code without any parameters so they're pretty straightforward.
csos95 marked this conversation as resolved.
Show resolved Hide resolved

# Drawbacks

The removal of the existing color functions and the change to the `clear` and `erase` functions (if the default of zero is used) are breaking changes.
csos95 marked this conversation as resolved.
Show resolved Hide resolved

# Alternatives

## Alternative to the rfc as a whole
These escape codes can simply be printed independently of whatever is supported by functions on `ANSI`.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
Having them available on `ANSI` simply makes it so that users do not need to look the codes up themselves.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what you mean by this.

Copy link
Member

Choose a reason for hiding this comment

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

I do not understand this under the "Alternatives" section.


## Alternative to the breaking changes
The existing color functions could remain and the 3-bit and 4-bit color functions could exist alongside them or not be implemented.
csos95 marked this conversation as resolved.
Show resolved Hide resolved
csos95 marked this conversation as resolved.
Show resolved Hide resolved
The `clear` and `erase` functions could have default values that match their existing behavior.

# Unresolved questions

Should the breaking changes be made to simplify the interface?
csos95 marked this conversation as resolved.
Show resolved Hide resolved