RobTillaart / ANSI

Arduino library with basic ANSI display codes for simple terminal apps
MIT License
17 stars 6 forks source link

Use enum deviceTypes instead of int #22

Closed chlordk closed 11 months ago

chlordk commented 12 months ago

Auto Format is done with Arduino IDE 2.2.1

RobTillaart commented 12 months ago

I don't know what the effect will be if the terminal returns a value that is not in the enum. This might differ per compiler (needs investigation) so I prefer to keep using the integer values.

Same as with the ansi colors, defined enums for readability but just using ints to keep it straightforward for the average user.

hanschou commented 12 months ago

Fine with me. Just reject. The "enum" is often a long discussion I seldomly want to participate in :-) When I wrote:

type = deviceTypes(buffer[2]);

it was actually the wrong way to do it as only '1','2', and '3' was valid and any other UNKNOWN.

RobTillaart commented 12 months ago

@chlordk For now I leave the PR open as I want to investigate if the idea of using the enum deviceType (which is good) can be made understandable for the beginning Arduino user somehow. I would really like to test it with an original VT100 I used eons ago.

If you have more ideas to improve the library, just let me know!

chlordk commented 12 months ago

Oh, you got a original VT100? A physical one? That's cool.

I have two ideas:

  1. Extended RGB colors
  2. Logfile/printing

RGB colors Some modern terminal emulators can take 24bit RGB color code. If you see this on read background it is working: echo -en "\e[48;2;255;0;0m-\e[m". Fade test: for ((r=0; r<256; r+=3)) ; do echo -en "\e[48;2;${r};0;0m-\e[m" ; done ; echo It does not work on a VT100 but if you know what a VT100 would write on the screen when it doesn't work then this could be used for a "full feature test demo". Like "if you see this garbage on the screen it doesn't work".

Logfile This is not really an application feature more a way of doing things. In TTY mode all new data is added to the bottom of the screen. If one want to log all data the terminal emulator can be put in log mode so all data would be written to a file. This will not work in full screen ANSI mode. In ANSI mode one can setup the terminal emulator to switch between Transparent or pass-through printing (slave printing) and screen printing with the "\e[5i" to switch on and "[4i" to switch off.

Run this script when running PuTTY:

#! /bin/bash
cat <<EOF
In PuTTY click upper left corner
-> Change Settings...
-> Terminal (in left  side)
-> Remote-controlled-printing
and select "Microsoft XPS Document Writer".
Click [Apply]

In Windows find the file in the user "Documents" directory
(C:\> dir %USERPROFILE%\Documents).
The filename is:
"PuTTY remote printer output.oxps"

This is ANSI mode.^[[5iLine 1 in printing mode.
Line 2 in printing mode.^[[4i Back to ANSI screen mode.
EOF

The above will create one new file each time.

History The physical VT100 terminal was connected with a RS232 cable to the server. If one wanted to have a printer next to the terminal either a cable had to be drawn from the server and using an extra serial port or the printer could be attached to the back of the VT100. Then the user could send the \e[5i command to the terminal and all data would now be passed through to the printer. During the printing the terminal could not be used and with a slow printer this could be a bit annoying.

RobTillaart commented 12 months ago

Oh, you got a original VT100? A physical one? That's cool.

No the opposite, I wished I had. Worked with them in the past and they were very nice, silent good keyboard and yes a burnt in display. Seen some for sale on the internet for too high prices several years ago. Maybe I should take a look again.

Will look into the ideas later, some other projects have prio

RobTillaart commented 12 months ago

@chlordk The ANSI.h file has some commented lines for printing, these are minimal tested.

Should be renamed to (what is best)

chlordk commented 12 months ago

How about

ansi.setPrintingMode(true);

Then it is just:

ANSI::setprintingMode(bool on) {
  print( on ? "\e[5i" : "\e[4i");
RobTillaart commented 12 months ago

Created a develop branch with all experimental code enabled, including setprintingMode() and an initial version of supportMatrix.md

Back to my other projects...

RobTillaart commented 12 months ago

RGB colors Some modern terminal emulators can take 24bit RGB color code. If you see this on read background it is working: echo -en "\e[48;2;255;0;0m-\e[m". Fade test: for ((r=0; r<256; r+=3)) ; do echo -en "\e[48;2;${r};0;0m-\e[m" ; done ; echo It does not work on a VT100 but if you know what a VT100 would write on the screen when it doesn't work then this could be used for a "full feature test demo". Like "if you see this garbage on the screen it doesn't work".

This could be interesting to add a function for under experimental.

RobTillaart commented 11 months ago

@chlordk

Sorry for the inconvenience, I have other priorities to attend so some things including this PR is delayed.

wrt the RGB functions, I added these two in the latest release, and as I do not want to get into "enum trouble" I close this PR. Keep proposing your ideas as I hope to find time again soon.