开发者

ASCII user interface in C++ w/ Unix PuTTY terminal using escape sequences

开发者 https://www.devze.com 2023-03-01 03:51 出处:网络
I\'m trying to make a simple ASCII user interface for a simple internet chat program.I\'m planning it to look like this:

I'm trying to make a simple ASCII user interface for a simple internet chat program. I'm planning it to look like this:

(name): message

(name): message

---------------------------------------------

(you): message |(cursor)

I was going to use ASCII (ANSI?) control characters to accomplish this.

Whenever the chat client receives a message from the server, it should update so that the message appears as the first message above the dash-line, then return the开发者_运维问答 cursor to its previous position so the user can continue typing where they left off.

My initial plan was:

1. save the current cursor position (\e7)

2. move the cursor up 1 line (to the dash-line) and to the beginning of that line (\e[1F])

3. move the dash line down (\n)

4. move the cursor up one line again (to the now empty line) (\e[1A)

5. print the message from the server

6. restore previous cursor position (\e8)

all together: "\e7\e[1F\n\e[1A" << message << "\e8";

Where I'm having trouble is that the newline character seems only to move the cursor to the next line, and not actually insert a blank line. How can I accomplish this behavior?

This is for a homework assignment, but this is just an extra bit of flair i wanted to add on for myself. The actual assignment is already completed.

note: algorithm for handling user's input on their own screen is handled correctly already.


Look into something like pdcurses. It's cross platform. That will make all of those manipulations a lot easier. You can also check into curses on *nix and the ancient conio library on Windows if you don't mind your code not being portable.


If you are using bash, you can do it with special commands using characters escapes. See http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html


Seriously consider using a curses library (see Wikipedia for more information).

0

精彩评论

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