Terminal control/Cursor positioning: Difference between revisions
Content deleted Content added
→{{header|Python}}: +winapi |
|||
Line 289: | Line 289: | ||
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x:<lang Python>print("\033[6;3HHello")</lang> |
Using ANSI escape sequence, where ESC[y;xH moves curser to row y, col x:<lang Python>print("\033[6;3HHello")</lang> |
||
On Windows it needs to import and init the [http://code.google.com/p/colorama/ colorama] module first. |
On Windows it needs to import and init the [http://code.google.com/p/colorama/ colorama] module first. |
||
ANSI sequences are not recognized in Windows console, here is a program using Windows API: |
|||
<lang python>from ctypes import * |
|||
STD_OUTPUT_HANDLE = -11 |
|||
class COORD(Structure): |
|||
pass |
|||
COORD._fields_ = [("X", c_short), ("Y", c_short)] |
|||
def print_at(r, c, s): |
|||
h = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) |
|||
windll.kernel32.SetConsoleCursorPosition(h, COORD(c, r)) |
|||
c = s.encode("windows-1252") |
|||
windll.kernel32.WriteConsoleA(h, c_char_p(c), len(c), None, None) |
|||
print_at(6, 3, "Hello")</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |