Inverted colors in console with CRT in Linux lazarus / 32-Linux ---------------------------------------------------------------------- glorfin · 2018-05-06 18:46 I am writing a console application and would like to highlight some output with inverted colors. In Windows I could do it retrieving current colors with GetConsoleScreenBufferInfo and then exchanging them. But it does not seem that standard way to find current console colors exists in Linux. In general, on Linux one can use escape sequences to invert colors. However, escape sequences seem to be disabled if one uses CRT unit. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Invert;begin  writeln(#27'[7mInverted'#27'[m');end. produces output in inverted colors, but Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Invert;uses CRT;begin  GoToXY(2,2);  writeln(#27'[7mInverted'#27'[m');end.writes with normal attributes. So, is there any way to use CRT unit and write with inverted colors on linux console? Thank you in advance! ---------------------------------------------------------------------- BobS · 2019-06-10 07:52 This works for me: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;uses crt, Unix;var  Rever, Reset: String;  RtnCode: Longint;begin  Rever:='tput rev';  (*reverse foreground/background*)  Reset:='tput sgr0';  writeln ('hello world');  RtnCode:=fpSystem(Rever);  writeln ('reverse the world');  RtnCode:=fpSystem(Reset);  writeln ('back to normal')end. ---------------------------------------------------------------------- Handoko · 2019-06-10 09:21 @glorfin Maybe you will be interested to try how to make it colorful and blinking: https://forum.lazarus.freepascal.org/index.php/topic,42759.msg298690.h tml#msg298690 ---------------------------------------------------------------------- marcov · 2019-06-10 09:42 Crt puts the console in raw mode, so escapes won't work. The current colors are in "textattr" in lo hi format, so var b : byte; b:=textattr; textattr:=b shr 4 + (b and 15) shl 4; should go a long way. Maybe you need to set them with textcolor/background though, on unix. ---------------------------------------------------------------------- BobS · 2019-06-10 09:59 Some more fun playing around with the tput (which works well in bash too): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program consoleclrs;uses crt, Unix;var  Rever, Reset, Blink, UnderOn, UnderOff, Bold: String;  (*In the color strings 'F' means foreground, 'B' means background*)  BlackF, BlackB, BlueF, BlueB, CyanF, CyanB, GreenF, GreenB: String;  strx: String;  RtnCode: Longint;  x: integer;begin  (*colors can very depending on your terminal settings*)  Rever:='tput rev';  (*reverse foreground/background, use Reset to stop*)  Reset:='tput sgr0'; (*sets foreground/background to default colors*)  Blink:='tput blink'; (*causes text to blink, use Reset to stop*)  UnderOn :='tput smul'; (*start underline*)  UnderOff:='tput rmul'; (*stop underline*)  Bold:='tput bold'; (*bolds text, use Reset to stop*)   BlackF:='tput setaf 0';  BlackB:='tput setab 0';  BlueF :='tput setaf 4';  BlueB :='tput setab 4';  CyanF :='tput setaf 6';  CyanB :='tput setab 6';  GreenF:='tput setaf 2';  GreenB:='tput setab 2';   RtnCode:=fpSystem(BlueF);  writeln ('I''m blue on black');   RtnCode:=fpSystem(Rever);  writeln ('I''m black on blue');   RtnCode:=fpSystem(GreenF); (*since reverse is on green is the background*)  writeln ('I''m black on green');   RtnCode:=fpSystem(Reset);  RtnCode:=fpSystem(GreenF);  RtnCode:=fpSystem(CyanB);  writeln ('I''m green on cyan');   RtnCode:=fpSystem(Reset);  writeln ('I''m your default colors!');  writeln ('This is a test.');    (*note if the screen hasn't been cleared recently an odd color bar may appear to fill up the rest of this line      in the last bacground color; setting background to black does not fix this.  Subsequent lines do not have      this bug.*)   Rtncode:=fpSystem(GreenF);  write ('I''m a ');  Rtncode:=fpSystem(Blink);  write ('surprise');  Rtncode:=fpSystem(Reset);  Rtncode:=fpSystem(GreenF);  writeln ('!');   Rtncode:=fpSystem(CyanF);  write ('I''m ');  Rtncode:=fpSystem(UnderOn);  write ('underlined');  Rtncode:=fpSystem(UnderOff);  writeln ('!  But this is not.');   RtnCode:=fpSystem(GreenF);  RtnCode:=fpSystem(Bold);  writeln ('I''m very bold!');   (*display some of the colors available in your console. *)  for x:=1 to 100   (*number of colors available depends on your enviornment try up to 255 or even 65K*)     do begin        str(x,strx);        strx:='tput setaf '+strx;        RtnCode:=fpSystem(strx);        write (' Color ',x);     end;   writeln (''); end.   Edit: Further testing shows that the tput bold command (and the dim command not show in this code) are not reliable.  Sometimes they work, sometimes nothing changes, and sometimes a different color is used...at least in 256 color mode. However italics works on my console (terminal): so try Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  ItalicsOn = 'tput sitm';  italicsOff = 'tput ritm';...RtnCode:=fpSystem(ItalicsOn);Writeln('I''m in Italics.');