Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there

I want to write my own console window using c++ and make it cross-platform

But I don't know from where should I start and how to write it


Should I write it using C++ and OpenGL or what, and in the same time I want to make it a cross-platform project but I don't know can I do this or I should use every platform''s APIs to achieve that and write a project for every platform

Should I use win32 APIs to write it for windows and Linux APIs to write it for Linux

Note: I'm going to write it because I want to make a console window that supports Arabic, because the existing consoles just supports English, so I want to write my own console to draw Arabic characters to it and make it available for every platform so developers can write console applications that supports Arabic


Thanks in advance
Posted

A console is a ... console (something that is used to give commands to a system). It should support the less languages required to sustain a dialog towards the system, otherwise is anymore a console, but right more a "graphical application to manage text".

And a "multi-platform console" risk to be an illusion, since it has to be used to send command to the underlying operating system (so you also need a multi-platform command interpreter, may be even multi-language - but this way there will be no more scripting portability...)

Anyway, a multi-platform application should be defined in term of a self-consistent interaction model,exposing the the user/other programs the functions required to interact with it, and them "map" that model onto the underlying interaction model of the system is implemented on.
The first part is essentially "platform independent", the second part is "platform dependent" and should exist in as many versions as the underlying platforms and variants are.

All this in theory. In practice this may result in tons of "passthrough" code, so -as the most of platform application are- that clear distinction is not always "well evident", and lot of
C++
#ifdef PLATFORM_WINDOWS
... do the windows way
#endif
#ifdef PLATFORM_LINUX
... do the linux way
#endif

will exist, inlined with the code.
 
Share this answer
 
Comments
Amir Mahfoozi 6-Nov-11 7:02am    
+5
If you use pure C and make sure all your library calls are POSIX compliant you should be able to make it cross-platform. The basic functionality of a console is :
Do Forever
{
    Read next string
    Split string into words
    Switch on first word
    {
        If internal command
            run subroutine 
        If external command
            execute command process
        If unknown
            display error message
    }
}
 
Share this answer
 
This can be acheived with POSIX compliant functions. This is supported by almost all platforms including Linux, OSX, BSD, and many others (Windows not included). The basic idea is in Richard's answer, but when you execute an external command you open up some pipes and then spawn a child process.
See Mapping UNIX pipe descriptors to stdin and stdout in C[^] for an example on how to do this in a UNIX based environment (including linux and OSX) or QuickWin[^] for Windows. Create a common function for doing things, and use Emilio's solution to select the correct code based on the platform.

As for the GUI side of things, I'd suggest something like QT[^] which is cross platform. Just saves you having to do that bit cross platform too.

Whatever you end up doing, make sure that you are using some form of extended character set, like Unicode. You will probably need to convert the output from many of the programs, as they typically only print or take input in ASCII.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900