开发者

How do I programmatically change the position of the cursor in a Mac terminal program?

开发者 https://www.devze.com 2023-01-22 21:41 出处:网络
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 l开发者_如何学Goearning by writing a little terminal game.I\'

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 l开发者_如何学Goearning 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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消