简体   繁体   English

C/C++ NCURSES,获取WINDOW中输入的所有字符

[英]C/C++ NCURSES, get all characters typed in a WINDOW

What I'm trying to achieve (more than “to reproduce”):我想要实现的目标(不仅仅是“重现”):

In other projects (not TUI contexts) I've used several GUI toolkit ( wxWidgets , wxPython ), etc. (just to name a few)), and most of the time they have handy methods on widgets receiving user input (like “text control” (single and/or multi lines)), methods which are used to get the content of the widgets into any container/object (eg string ( 1 )).在其他项目(不是 TUI 上下文)中,我使用了几个 GUI 工具包( wxWidgetswxPython )等(仅举几例),并且大多数时候它们在接收用户输入的小部件上有方便的方法(比如“文本” control”(单行和/或多行)),用于将小部件的内容放入任何容器/对象(例如string1 ))的方法。

Is there any similar functionality in ncurses ? ncurses中是否有任何类似的功能?

Lets say I have the following code:可以说我有以下代码:

WINDOW *textarea = newwin(height, width, starty, startx);

/**
 * There, code for letting the user type text in the textarea 
**/

switch (ch)
{
    case KEY_F(4): // Save
        /**
         * What do I do from here
         * to get all the content of the textarea WINDOW
         * that the user typed in
        **/
        break;
}

Does ncurses provides such a feature? ncurses 是否提供这样的功能?

I'm working on a lightweight terminal text editor (not a source code editor, simply a text editor), and it would greatly simplify my job if I could do such a thing with ncurses.我正在开发一个轻量级的终端文本编辑器(不是源代码编辑器,只是一个文本编辑器),如果我能用 ncurses 做这样的事情,它会大大简化我的工作。


Notes (for the curious)笔记(好奇的)

(1): For example the wxTextCtrl::GetValue which returns a wxString (1): 例如返回 wxString 的wxString wxTextCtrl::GetValue

curses doesn't have a notion of "containers". curses 没有“容器”的概念。 It uses windows (whose semantics are defined by the calling application), and can get input characters associated with a window, eg, using wgetch or wget_wch .它使用 windows(其语义由调用应用程序定义),并且可以获得与 window 关联的输入字符,例如,使用wgetchwget_wch The string-input functions call one of those.字符串输入函数调用其中之一。

However, the input streams for the wgetch/wget_wch functions are probably (unless you set up separate screens ) the same input device.但是,wgetch/wget_wch 函数的输入流可能(除非您设置单独的屏幕)是相同的输入设备。 It's up to the application to decide how to distinguish input from one or multiple windows.由应用程序决定如何区分来自一个或多个 windows 的输入。

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

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