I'm using GNU Pascal.
For my homework (due to next Friday) I have to learn how to set up the cursor position, and how to change text and background colour.
And how can I learn more about such commands?
I'm using GNU Pascal.
For my homework (due to next Friday) I have to learn how to set up the cursor position, and how to change text and background colour.
And how can I learn more about such commands?
For : the standard, simplest way in GNU Pascal is to use the CRT unit. Add uses crt; to the program header. CRT exposes routines you’ll use for screen work: ClrScr, GotoXY(X,Y), TextColor(color), TextBackground(color), WhereX, WhereY, ClrEol, Window(x1,y1,x2,y2), KeyPressed and ReadKey. Coordinates are 1-based (top-left is 1,1). Color names are the usual constants (Black, Blue, Green, Cyan, Red, Magenta, Brown, LightGray, DarkGray, LightBlue, LightGreen, LightCyan, LightRed, LightMagenta, Yellow, White). Note that TextColor/TextBackground affect only subsequent output — to change already-printed text it must be rewritten.
A short example that sets position and colors:
program ScreenDemo;
uses crt;
begin
ClrScr;
TextColor(LightGreen);
TextBackground(Blue);
GotoXY(10,5);
Write('Hello GNU Pascal!');
GotoXY(1,24);
TextColor(White);
TextBackground(Black);
end. Troubleshooting and portability tips: if the compiler complains about Crt not being found, verify the GNU Pascal installation and unit search paths. If colors or cursor moves don’t show when run from an IDE or redirected output, run the compiled program in a real terminal/console instead — many IDE consoles don’t emulate full terminal capabilities. For broader terminal compatibility, ANSI escape sequences can be used as a fallback (example: Write(#27 + '[31m' + 'Red text' + #27 + '[0m'); — #27 is ESC). For robust cursor/input control on Unix, consider ncurses bindings; on Windows, console behavior is different and may require platform-specific handling. See ’s pointer to the GNU Pascal CRT documentation for exact signatures and additional helpers.
Thanks, that is a nice site!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.