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

FEAT: basic support for ANSI escaping sequences in Windows CLI console #2522

Merged
merged 3 commits into from Apr 2, 2017

Conversation

Projects
None yet
4 participants
@Oldes
Contributor

Oldes commented Mar 31, 2017

This modification enables ANSI escape sequences to be processed in the Windows CLI console. It would be probably fine to add at least cursor support into gui-console while stripping the escape sequences there when not applied (gui console cannot have colors).

@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Mar 31, 2017

Contributor

With above modification one can get color output like here:
https://github.com/Oldes/media/raw/master/screens/ansi-color-test.PNG

using this code:

	print "^[[2J" ;reset screen
	foreach [int des] [
		"00" "none"
		"39" "foreground"
		"49" "background"
		"01" "all"
	] [
		print ["INTENSITY:" des]
		repeat b 8 [
			repeat c 8 [
				pen: 29 + c
				bac: 39 + b
				code: to-string reduce ["[" int ";" pen ";" bac "m"]
				prin to-string reduce [#"^[" code "^^[" code "^[[0m  "	]
			]
			print ""
		]
		print ""
	]
Contributor

Oldes commented Mar 31, 2017

With above modification one can get color output like here:
https://github.com/Oldes/media/raw/master/screens/ansi-color-test.PNG

using this code:

	print "^[[2J" ;reset screen
	foreach [int des] [
		"00" "none"
		"39" "foreground"
		"49" "background"
		"01" "all"
	] [
		print ["INTENSITY:" des]
		repeat b 8 [
			repeat c 8 [
				pen: 29 + c
				bac: 39 + b
				code: to-string reduce ["[" int ";" pen ";" bac "m"]
				prin to-string reduce [#"^[" code "^^[" code "^[[0m  "	]
			]
			print ""
		]
		print ""
	]
Oldes
@dockimbel

This comment has been minimized.

Show comment
Hide comment
@dockimbel

dockimbel Apr 2, 2017

Member

You need to provide same feature on Linux and macOS platform in order to be accepted. Moreover, be aware that such code will be dropped or at least, heavily changed once we pass 0.7.0 and implement the console:// port.

Member

dockimbel commented Apr 2, 2017

You need to provide same feature on Linux and macOS platform in order to be accepted. Moreover, be aware that such code will be dropped or at least, heavily changed once we pass 0.7.0 and implement the console:// port.

@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Apr 2, 2017

Contributor

*nix terminals support ansi sequences by default. Just with some differences in colors.

Contributor

Oldes commented Apr 2, 2017

*nix terminals support ansi sequences by default. Just with some differences in colors.

@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Apr 2, 2017

Contributor

Old Rebol2 console suported at least the cursor movement and erasing.

Contributor

Oldes commented Apr 2, 2017

Old Rebol2 console suported at least the cursor movement and erasing.

@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Apr 2, 2017

Contributor

All console versions should support it at least in a minimal form as it is standard used many years.

Contributor

Oldes commented Apr 2, 2017

All console versions should support it at least in a minimal form as it is standard used many years.

@dockimbel

This comment has been minimized.

Show comment
Hide comment
@dockimbel

dockimbel Apr 2, 2017

Member

I know ANSI escape codes and how Unix terminals work, though, I was not aware that the current Red CLI console on Unix let them pass unchanged (was not the case before).

Member

dockimbel commented Apr 2, 2017

I know ANSI escape codes and how Unix terminals work, though, I was not aware that the current Red CLI console on Unix let them pass unchanged (was not the case before).

@dockimbel dockimbel merged commit 7f0f958 into red:master Apr 2, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@StephaneVeneri

This comment has been minimized.

Show comment
Hide comment
@StephaneVeneri

StephaneVeneri Apr 2, 2017

Contributor

With the last Automated builds on Windows, works fine with gui-console but problem with cli-console :

C:\red>red-02apr17-7f0f958.exe  --cli
Compiling Red console...
*** Loading Error: file access error: %win32-ansi.reds
*** in file: %/C/red/win32-cli.reds
*** at line: 18
Contributor

StephaneVeneri commented Apr 2, 2017

With the last Automated builds on Windows, works fine with gui-console but problem with cli-console :

C:\red>red-02apr17-7f0f958.exe  --cli
Compiling Red console...
*** Loading Error: file access error: %win32-ansi.reds
*** in file: %/C/red/win32-cli.reds
*** at line: 18
@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Apr 2, 2017

Contributor
Contributor

Oldes commented Apr 2, 2017

@Oldes

This comment has been minimized.

Show comment
Hide comment
@Oldes

Oldes Apr 2, 2017

Contributor

Here is a fix: #2534

Contributor

Oldes commented Apr 2, 2017

Here is a fix: #2534

@qtxie

Use string/get-char to get the right codepoint for a string.

bytes: 2
]
UCS-2 [
if str/3 <> #"[" [return 0]

This comment has been minimized.

@qtxie

qtxie May 10, 2017

Contributor

FIX-1: It's not safe to test a single byte here. If the char is #"ś" (which codepoint is #"^(015B)"), then it's wrong.

@qtxie

qtxie May 10, 2017

Contributor

FIX-1: It's not safe to test a single byte here. If the char is #"ś" (which codepoint is #"^(015B)"), then it's wrong.

bytes: 4
]
UCS-4 [
if str/5 <> #"[" [return 0]

This comment has been minimized.

@qtxie

qtxie May 10, 2017

Contributor

Same as FIX-1.

@qtxie

qtxie May 10, 2017

Contributor

Same as FIX-1.

value2: 0
attribute: -1
until [
cp: str/1

This comment has been minimized.

@qtxie

qtxie May 10, 2017

Contributor

Same as FIX-1, should use string/get-char to get the codepoint.

@qtxie

qtxie May 10, 2017

Contributor

Same as FIX-1, should use string/get-char to get the codepoint.

This comment has been minimized.

@Oldes

Oldes May 10, 2017

Contributor

@qtxie thanks, sounds reasonable... the fix is in this commit: 9e80702

@Oldes

Oldes May 10, 2017

Contributor

@qtxie thanks, sounds reasonable... the fix is in this commit: 9e80702

This comment has been minimized.

@qtxie

qtxie May 11, 2017

Contributor

@Oldes Thanks for the fix. 👍

@qtxie

qtxie May 11, 2017

Contributor

@Oldes Thanks for the fix. 👍

col [integer!]
row [integer!]
][
switch unit [

This comment has been minimized.

@qtxie

qtxie May 10, 2017

Contributor

Should use string/get-char here instead of the switch code. See here.

@qtxie

qtxie May 10, 2017

Contributor

Should use string/get-char here instead of the switch code. See here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment