views:

19

answers:

1

How do I programmatically change the position of the cursor in a Mac terminal program? I'm teaching a couple of kids to program and we're learning by writing a little terminal game. I've done this with C# on Windows with SetCursorPosition(x, y) so I'm hoping for something like that.

+1  A: 

Normally you'll be using a library like ncurses that provides an abstraction to control the terminal. However, if you want to emit the raw ANSI escape code to do this directly, you'll want the CUP code, which looks like \e[n;mH where n and m are the row and column numbers (1-based, origin is top-left corner) and \e is the ESC control code (0x1b).

Kevin Ballard
I was afraid Curses was going to be the only option. I have a link error trying to get the move command to work, and was hoping for something different. I'll have to post a new question. Thanks.
Alyoshak
I believe there's a more modern alternative to curses, but I don't remember what it's called. It's worth searching for though.
Kevin Ballard