简体   繁体   English

如何创建控制台终端?

[英]How to create a console terminal?

From where I can start creating a console for my C++ programs ? 从哪里开始为我的C ++程序创建控制台?

I need a bare minimum console to launch and manage console applications, the reason why I need this it's because I need to pack everything into 1 executable and create and control my little environment. 我需要一个最低限度的控制台来启动和管理控制台应用程序,我之所以需要它是因为我需要将所有内容打包成1个可执行文件并创建和控制我的小环境。

With the term "console" I only mean a terminal to run my program, nothing more, nothing less, I don't want my console to be interfaced with the underlaying system , only care about my console applications. 使用术语“控制台”我只是指一个终端来运行我的程序,仅此而已,仅此而已, 我不希望我的控制台与底层系统接口 ,只关心我的控制台应用程序。

So my question is: given a C++ applications or a command line interpreter, what is the know-how required to create a terminal that is able to interface itself to this application and report and manage the usual input ( std::cout, special characters like bells, text input from the user, and so on ) ? 所以我的问题是:给定一个C ++应用程序或一个命令行解释器,创建一个能够将自己与自己的应用程序接口并报告和管理通常输入(std :: cout,特殊字符)的终端需要什么?像铃铛,用户输入的文字等等)?

I think this is a WAY too large question for "one answer". 我认为对于“一个答案”来说,这是一个太大的问题。

There are three components to the problem: 该问题有三个组成部分:

  1. Running another application from your code. 从代码运行另一个应用程序。
  2. Capturing the output of said application. 捕获所述应用程序的输出。
  3. Displaying the output in a console type window. 在控制台类型窗口中显示输出。

I believe at least 1 & 2 are decidedly different for each major type of platform, at the very least it is different on Windows vs. Symbian vs. Linux/Unix type platforms. 我相信每种主要类型的平台至少有1和2个明显不同,至少在Windows与Symbian与Linux / Unix类型平台上是不同的。 I believe, largely, an Android platform can achieve this by the same method as Linux. 我相信,在很大程度上,Android平台可以通过与Linux相同的方法实现这一目标。

The third part, aside from all the complexities of emulating a VT100 or ANSI terminal (which is non-trivial because there is a large number of different escape-codes to parse and interpret, but you can probably get away with just implementing half a dozen or so to begin with). 第三部分,除了模拟VT100或ANSI终端的所有复杂性之外(这是非常重要的,因为有大量不同的转义码可以解析和解释,但是你可能只需要实现六个就可以逃脱左右开始)。

I'd expect, aside from "platform specific code", this is a project that requires a few thousand lines of code, and if you know where to start (that is, you are familiar with fork(), execl() etc in Linux or their equivalents in another OS, and familiar with redirection if stdin , stderr and stdout using dup2() and similar functions, again with reservation for OS specific names, you could have something that roughly works in a few weeks. If you have no idea about these things, you will have to learn how to use these features first. 我希望,除了“平台特定代码”之外,这是一个需要几千行代码的项目,如果你知道从哪里开始(也就是说,你熟悉fork(), execl()等Linux或其他操作系统中的等价物,如果stdinstderrstdout使用dup2()和类似函数熟悉重定向,再次预留操作系统特定名称,你可以在几周内完成大致工作。如果你没有关于这些事情的想法,你将不得不首先学习如何使用这些功能。

Of course, doing terminal emulation, such as "draw a line of text here", "insert an empty line at line X", "clear screen from this position" or "clear remaining line", etc, etc will require a fair amount of work to cover ALL the different variants and options. 当然,进行终端仿真,例如“在这里画一行文字”,“在第X行插入空行”,“从这个位置清除屏幕”或“清除剩余行”等等都需要相当数量工作涵盖所有不同的变种和选项。 Especially if you wish to do this on a variable size display, rather than a "fixed 80 columns and 25 rows" as the original VT100 terminals supported. 特别是如果您希望在可变尺寸显示器上执行此操作,而不是支持原始VT100终端的“固定80列和25行”。 And I'm assuming you have already written code to draw basic text in OpenGL or OpenVG (does OpenVG support text natively, or do you have to do that as "draw bitmap" - I can't remember exactly how it works - I wasn't one of the people working on text in Symbian Graphics, so I was never really concerned with how it worked). 而且我假设您已经编写了代码来在OpenGL或OpenVG中绘制基本文本(OpenVG本身是否支持文本,或者您必须将其作为“绘制位图” - 我不记得它是如何工作的 - 我不知道在Symbian Graphics中处理文本的人之一,所以我从未真正关心它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM