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 an additional escape sequence \e. #963

Merged
merged 2 commits into from
Apr 8, 2021
Merged

Conversation

PureFox48
Copy link
Contributor

This is an idea I had when discussing #945 to avoid the need to support octal escape sequences.

Probably, the only common use for these nowadays is to encode the ESC character (0o33) itself in ANSI escape codes and adding an escape sequence for this will make life a little easier.

It's not a new idea as gcc, clang and tcc already support it as a non-standard extension to their C compilers.

I haven't added a test as the other escape sequences which represent control characters don't seem to have any.

This is an idea I had when discussing wren-lang#945 to avoid the need to support octal escape sequences.

The only common use for these nowadays is to encode the ESC character (0o33) itself in ANSI escape codes and adding an escape sequence for this will make it a little easier.

It's not a new idea as gcc, clang and tcc already support it as a non-standard extension to their C compilers.
@ruby0x1
Copy link
Member

ruby0x1 commented Apr 8, 2021

@PureFox48 is it \033 or \33, I suspect you're missing a preceding 0 if using octal.

One alternative is adding \x instead, then ESC become \x1b and it's more general purpose than just \e.

@mhermier
Copy link
Contributor

mhermier commented Apr 8, 2021

@ruby0x1 the front 0 is optional, the escapes where always octal in all known conventions/implementations.

@PureFox48
Copy link
Contributor Author

PureFox48 commented Apr 8, 2021

Yes, @mhermier is correct that the leading 0 is optional since octal escapes can be either 1, 2 or 3 characters following the \.

Wikipedia has a good summary here.

Although \x1b works fine, the reason I wanted to add \e is because you don't then have to remember the code for ESC when writing an ANSI escape code and (apart from \0 which we already have) it's the only common use for octal escapes these days. We wouldn't therefore need to support them as well as octal literals.

@mhermier
Copy link
Contributor

mhermier commented Apr 8, 2021

Adding \x will need to be done at some point to allow to ease creation of byte arrays, but it is not critical yet (till someone request for it).

@PureFox48
Copy link
Contributor Author

We already have \x. See escaping in the docs towards the end of the secton.

@ruby0x1
Copy link
Member

ruby0x1 commented Apr 8, 2021

Ah ok, I've somehow only ever noticed with a leading 0 but looked it up.

Also I forgot \x was there below. I'll make that table a bit clearer.

Noting that the Wren page also has this line, which hints that escapes aren't too precious or strictly minimal.

"\a" // Alarm beep. (Who uses this?)

@mhermier
Copy link
Contributor

mhermier commented Apr 8, 2021

People who do console applications, probably wren-cli use it... was not able to run it since a while because of local changes...

@PureFox48
Copy link
Contributor Author

Yes, I sometimes use \a myself as it's currently the only way to get a tweet out of Wren without using a game engine :)

@ruby0x1 ruby0x1 merged commit 5244a9d into wren-lang:main Apr 8, 2021
@ruby0x1
Copy link
Member

ruby0x1 commented Apr 8, 2021

Minor note: the new escape wasn't documented in this PR but I added it.

Thanks for the PR, I think I've used escape stuff enough in wren for unit tests, command line tools and logging that it's not unreasonable to make it cleaner considering the low impact of the change.

@PureFox48
Copy link
Contributor Author

Excellent, thanks :)

@PureFox48 PureFox48 deleted the patch-12 branch November 13, 2022 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants