我如何编写自己的控制台 [英] How can I write my own console

查看:91
本文介绍了我如何编写自己的控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想使用c ++编写自己的控制台窗口并使它跨平台

但是我不知道我应该从哪里开始以及如何写


我应该使用C ++和OpenGL还是其他语言编写它,同时我想使其成为一个跨平台项目,但是我不知道我可以这样做还是应该使用每个平台的API来实现.实现这一目标并为每个平台编写一个项目

我应该使用win32 API来为Windows编写它,还是使用Linux API来为Linux编写

注意:我要编写它是因为我要创建一个支持阿拉伯语的控制台窗口,因为现有的控制台仅支持英语,所以我想编写自己的控制台以向其绘制阿拉伯字符并使每个人都可以使用它平台,因此开发人员可以编写支持阿拉伯语的控制台应用程序


预先感谢

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

推荐答案

控制台是...控制台(用于向系统发出命令的东西).它应该支持维持与系统对话所需的较少语言,否则它将成为控制台,但更应该是用于管理文本的图形应用程序".

而且多平台控制台"可能是一种错觉,因为它必须用于将命令发送到底层操作系统(因此,您还需要多平台命令解释器,甚至可能是多语言的-但是这种方式将不再有脚本可移植性...)

无论如何,应该根据自洽的交互模型来定义多平台应用程序,向用户/其他程序公开与之交互所需的功能,然后将它们映射"到系统的基础交互模型上.实现于.
第一部分本质上是平台无关的",第二部分是平台相关的",并且应以与基础平台和变体相同的版本存在.

从理论上讲所有这一切.在实践中,这可能会导致大量的直通"代码,因此-就大多数平台应用而言-清晰的区分并不总是很明显"的,并且很多
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
#ifdef PLATFORM_WINDOWS
... do the windows way
#endif
#ifdef PLATFORM_LINUX
... do the linux way
#endif


将会存在,并内含代码.


will exist, inlined with the code.


如果您使用纯C并确保所有库调用均符合POSIX,则应该可以使其跨平台.控制台的基本功能是:
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
    }
}


可以使用POSIX兼容功能来实现.几乎所有平台都支持此功能,包括Linux,OSX,BSD和许多其他平台(不包括Windows).基本思想在Richard的答案中,但是当您执行外部命令时,您打开了一些管道,然后生成了一个子进程.
请参见将UNIX管道描述符映射到C中的stdin和stdout [ QuickWin [ QT [
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.


这篇关于我如何编写自己的控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆