fckstckvrflw fckstckvrflw - 9 days ago 5
Pascal Question

Colors in windows console

I want to display colors in "simple program" turbo pascal application. I do not want to import anything, please do not put answers like "you must use this library or that library etc..". I know that when you print

\x1b[33m
to windows console, everything which comes after it will be yellow. For example, in node.js
console.log('\x1b[33mText');
will display yellow text in the console no matter what console default font setting was.

Pascal is using windows console for stdio, so it should be possible to achieve the same result printing the magic code. I wrote a function to do that:

function _(a: integer): boolean;
begin
write(chr(27), '[', a, 'm');
_ := true;
end;


and I call it like this:

_(33);
write('wth this doesnt work')


Unfortunatelly, it prints this. Why? How to do it properly?

Answer

node.js is providing you with behavior that windows console does not. It's interpreting the \xb1[33m as being a color change command. Pascal does not do this.

http://newsblogs21.blogspot.com/2014/03/cara-membuat-background-dan-tulisan.html