Recent

Author Topic: linuxcrt - a crt unit for linux that uses ansi escape sequences.  (Read 1202 times)

el3ctrolyte

  • Guest
What is wrong with the normal CRT unit? In linux the crt unit sets the terminal in raw mode and then does some special thing the get colored text on the screen and also to give other functionality to the programmer. I didn't like this very much, because i am used to C(and other languages) that uses ansi escape sequences to get colored text. That is why i wrote this little library. It does not implement all the ansi escape sequences, but the basics are there.

These are the all the functions of the library:

procedure mcFgColor(color:mcColor);
procedure mcBgColor(color:mcColor);
procedure mcAttr(attr:mcColor);
procedure mcClsLn();
procedure mcClsDisp();
procedure mcGotoXYH(x,y:mcValue);
procedure mcGotoXYf(x,y:mcValue);

They are all pretty self explanatory.

These are all the available colors:

mcCBlack
mcCRed
mcCGreen
mcCYellow
mcCBlue
mcCMagenta;
mcCCyan
mcCWhite

These are all the attributes that you can apply to the text:

mcAAttrOff
mcABold
mcAUnderscore
mcABlink
mcAReverse
mcAConcealed

You can get the library here:
https://github.com/el3ctr0lyte/LinuxCrt

I hope people find this useful. Don't hesitate to contribute!

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: linuxcrt - a crt unit for linux that uses ansi escape sequences.
« Reply #1 on: March 27, 2021, 04:13:24 am »
[...] does some special thing the get colored text on the screen and also to give other functionality to the programmer. I didn't like this very much, because i am used to C(and other languages) that uses ansi escape sequences [...]

While it's true that setting raw mode might not have been the best decision (though it was done, IIRC, to overcome some limitations of cooked mode), the crt unit in *nixen systems also uses escape sequences whenever it can (which is most of the time). All the "special" things you see in the source are mostly meant to keep state, build the sequences, etc. so as to mimic the "standard" crt interface as much as posible.

But, yes, for simple things just sending VT100 escapes to the console is usually more than enough, so congrats! ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018