bormuth
asked on
gotoxy for cout ?
Is there any way to use gotoxy or clearscreen as I did in pascal for c++ std::cout ?
I want to code a console programm with a user interface for unix and windows.
I'm looking for a way that is platform independent and has no need of additional libraries etc. like nc-curses or so....
ASKER
I use borland c++ and g++.
I even want to use colors.
I thought POSIX was a standart to creatin threads ... ?
The POSIX standards include other functions besides thread functions.
Standard File, Terminal I/O, Files/Directories, and Process functions.
Check out tcgetattr() and tcsetattr()
The should be under <termios.h> header.
Standard File, Terminal I/O, Files/Directories, and Process functions.
Check out tcgetattr() and tcsetattr()
The should be under <termios.h> header.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> platform independent and has no need of additional libraries
That's the problem here. There _IS_NO_ platform independent way of doing platform DEPENDENT things. That is the whole point behind things like CURSES. They encapsulate the dependent things in such a way so as to remove the dependencies on the application program.
That's the problem here. There _IS_NO_ platform independent way of doing platform DEPENDENT things. That is the whole point behind things like CURSES. They encapsulate the dependent things in such a way so as to remove the dependencies on the application program.
By the way, POSIX does NOT address this in any way.
>>I even want to use colors.
Another option is to use XLib or GNOME/GTK.
Both work on Unix and Linux, but as far as I know, they don't work on windows.
You might try looking to see if any one made libraries or classes to use GNOME/GTK code on windows.
Another option is to use XLib or GNOME/GTK.
Both work on Unix and Linux, but as far as I know, they don't work on windows.
You might try looking to see if any one made libraries or classes to use GNOME/GTK code on windows.
>> they don't work on windows
Maybe, but TCL/Tk will, if you're planning on going into scripting.
You might get lucky with those other tool(kits), ever since Cygnus pulled their Cygwin dll trick Win32 has been flooded with ports of various Unix/Linux tools.
Haven't seen curses or ncurses on Win32 yet, but if someone has a link... For console IO that would surely be the most portable way.
Maybe, but TCL/Tk will, if you're planning on going into scripting.
You might get lucky with those other tool(kits), ever since Cygnus pulled their Cygwin dll trick Win32 has been flooded with ports of various Unix/Linux tools.
Haven't seen curses or ncurses on Win32 yet, but if someone has a link... For console IO that would surely be the most portable way.
Your best way will be to use ANSI codes on an ANSI compliant terminal output window.
A GotoXY would be:
sprintf(Buffer, "\x1B[%d;%df", XLoc, YLoc);
or
cout << "\x1B[";
cout << XLoc;
cout << ";";
cout << YLoc;
cout << "f";
Then just print your text:
Hello World!
Read about the ansi codes and see if this will do what you want it to do. It is the best "platform independent" solution that I have found.
Ansi Codes:
#define Normal "\x1B[0m"
#define Black "\x1B[30;47m"
#define Red "\x1B[31;40m"
#define Green "\x1B[32;40m"
#define Yellow "\x1B[33;40m"
#define Blue "\x1B[34;40m"
#define Magenta "\x1B[35;40m"
#define Cyan "\x1B[36;40m"
#define White "\x1B[37;40m"
#define Cursor_Home "\x1B[1;1f"
#define Clear_Screen "\x1B[2J"
30 - black characters
31 - red characters
32 - green characters
33 - yellow characters
34 - blue characters
35 - magenta characters
36 - cyan characters
37 - white characters
40 - black background
41 - red background
42 - green background
43 - yellow background
44 - blue background
45 - magenta background
46 - cyan background
47 - white background
A GotoXY would be:
sprintf(Buffer, "\x1B[%d;%df", XLoc, YLoc);
or
cout << "\x1B[";
cout << XLoc;
cout << ";";
cout << YLoc;
cout << "f";
Then just print your text:
Hello World!
Read about the ansi codes and see if this will do what you want it to do. It is the best "platform independent" solution that I have found.
Ansi Codes:
#define Normal "\x1B[0m"
#define Black "\x1B[30;47m"
#define Red "\x1B[31;40m"
#define Green "\x1B[32;40m"
#define Yellow "\x1B[33;40m"
#define Blue "\x1B[34;40m"
#define Magenta "\x1B[35;40m"
#define Cyan "\x1B[36;40m"
#define White "\x1B[37;40m"
#define Cursor_Home "\x1B[1;1f"
#define Clear_Screen "\x1B[2J"
30 - black characters
31 - red characters
32 - green characters
33 - yellow characters
34 - blue characters
35 - magenta characters
36 - cyan characters
37 - white characters
40 - black background
41 - red background
42 - green background
43 - yellow background
44 - blue background
45 - magenta background
46 - cyan background
47 - white background
>>ANSI codes on an ANSI compliant terminal output window.
Yeah, right! The question asks for a "platform independent and has no need of additional libraries" method. Please explain how requiring an ANSI compliant output window meets this specification!
Or are you just trying to grab points here with your inappropriate "answer" that is locking this question!
Please read and understand:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
(Of course this is the C++ topic area where anything goes...)
Yeah, right! The question asks for a "platform independent and has no need of additional libraries" method. Please explain how requiring an ANSI compliant output window meets this specification!
Or are you just trying to grab points here with your inappropriate "answer" that is locking this question!
Please read and understand:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
(Of course this is the C++ topic area where anything goes...)
No libraries are required for ANSI output.
Just an ANSI compliant shell, which Win9x, NT, 2000, Me all fit. Also this will work on Unix if the emulation is VT100 or ANSI compatable.
Thus it is platform independent and requires no additional libraries.
jhance: No I am not trying to just grab points here with my "inappropriate answer". Are you?
Just an ANSI compliant shell, which Win9x, NT, 2000, Me all fit. Also this will work on Unix if the emulation is VT100 or ANSI compatable.
Thus it is platform independent and requires no additional libraries.
jhance: No I am not trying to just grab points here with my "inappropriate answer". Are you?
_YOU_ locked the question, not me.
If, if, if...... that's NOT platform independent in my book!
If, if, if...... that's NOT platform independent in my book!
Hi c567591,
All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.
When posting an answer, it's considered improper etiquette to post an answer, after other experts have already posted possible answers, or have already made contributions to the question.
If you feel you have an answer, you can post it as a comment, and the questioner can convert your comment to an answer, if he/she thinks it?s correct or deserving of the awarded points.
There are some experts who never post answers as answer. Instead, they post their answers as comments. If you read the following link, you?ll see why this is the preferred method for many of our experts, including myself.
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
At the bottom of the above link, see the following section:
"Advice for Experts on Providing Solutions Through Comments or Answers"
All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.
When posting an answer, it's considered improper etiquette to post an answer, after other experts have already posted possible answers, or have already made contributions to the question.
If you feel you have an answer, you can post it as a comment, and the questioner can convert your comment to an answer, if he/she thinks it?s correct or deserving of the awarded points.
There are some experts who never post answers as answer. Instead, they post their answers as comments. If you read the following link, you?ll see why this is the preferred method for many of our experts, including myself.
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
At the bottom of the above link, see the following section:
"Advice for Experts on Providing Solutions Through Comments or Answers"
Hey, ANSI... it hadn't occurred to me to use ANSI coding and it might be an option. Indeed many, many terminals support ANSI, though I think WinDos will require that driver to be loaded.
Some links on curses for Win32
http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
http://virtunix.itribe.net/files/gsar/pdcurses-2.3b-win32.tar.gz
http://infoservice.lg.ua/~paul/devel/pdcurses_mingw32.html
Unix on Win32 links page
http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
Some links on curses for Win32
http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
http://virtunix.itribe.net/files/gsar/pdcurses-2.3b-win32.tar.gz
http://infoservice.lg.ua/~paul/devel/pdcurses_mingw32.html
Unix on Win32 links page
http://dmoz.org/Computers/Software/Operating_Systems/Unix/Win32/
ASKER
Sorry for rejecting the answer ...
I think I have to respect that there is no strait forward answer to my question.
**************************
Is it possible to split points to several persons ?
**************************
By the way I decied to use Curses on Unix and access the Win32 console directly.
I have problems with Win32 console. Have a look at
https://www.experts-exchange.com/jsp/qYourQuestion.jsp?jsessionid=127575992510748836
>> split points
You can ask in the Customer Support TA for help. They can do things like refunding your points so that you can post questions specifically for those you think were helpfull.
BTW, that link can not work, you need to post one with a qid=<whatever-number> in it.
You can ask in the Customer Support TA for help. They can do things like refunding your points so that you can post questions specifically for those you think were helpfull.
BTW, that link can not work, you need to post one with a qid=<whatever-number> in it.
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity, I will suggest to accept "Axter,jhance,Kangaroo,jas onclarke" comment(s) as an answer since you tried to award several experts.
If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please do not accept this comment as an answer!
======
Werner
If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
Please do not accept this comment as an answer!
======
Werner
ASKER
Sorry about forgetting this questions
- Ingo
The best you can do is try using POSIX, but oddly enough, VC++ does not support most of the POSIX functions.