在用C控制台底部的输入栏 [英] Input bar at console bottom in C

查看:132
本文介绍了在用C控制台底部的输入栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像vim,狗,资质一些应用程序包含

Some applications like vim, mutt, aptitude contain


  • 用于输出的顶部窗口部分和

  • 对于用户的底部,以输入或状态显示。

(假设有一个子过程,以输出和另一个取用户的输入。其目的是允许同时更新的输出作为正在键入的输入或观看的状态。)

(Suppose there is one child process to output and another one to take user input. The purpose is to allow for updated output at the same time as you are typing the input or viewing the status.)

Actions  Undo  Package  Resolver  Search  Options  Views  Help
C-T: Menu  ?: Help  q: Quit  u: Update  g: Download/Install/Remove Pkgs



                                                                            |
                                                                            |
                                                                            |
                                                                            |
                                                                            |
                            ┌─────────────┐                                 |
                            │Loading cache│                                 |
                            └─────────────┘                                 |
                                                                            |
                                                                            |
                                                                            |
                                                                            |
                                                                            |
                                                                            |    
                                                                            |
--------------------------------------------------------------------------- |
Initialising package states                                            100% |


+-------------------------------------------------------+
| some output here                                      |
|                                                       |
|                                                       |
|                                                       |
|                                                       |
|                                                       |
|-------------------------------------------------------+
|:input here                                            |
+-------------------------------------------------------+

Ncurses的教程没有提到这是明显可行的。

Ncurses tutorial does not mention this to be obviously possible.

在查询的ç打印到{窗口,屏幕,终端,控制台底部} 的在计算器或者在网络搜索引擎是没有帮助的。

A query on "c print to {window,screen,terminal,console} bottom" at StackOverflow or at a web search engine isn't helpful.

可以在C做编程?

虽然下面的一些解决方案的可以移动的字符到一个给定的位置,存在它可能需要丢弃的用户输入,而不是留在屏幕上的问题。像 VIM 的情况下,输入:W 和pressing输入不留:宽在屏幕上

While some of the solutions below can move character to a given position, there is the problem that it may be needed to discard user input rather than leaving it on screen. Like in vim's case, typing ":w" and pressing Enter does not leave a ":w" on the screen.

更新。这是在这里找到:如何删除getstr(后文)C ++的ncurses

Update. This is found here: How to delete text after getstr() c++ ncurses

在键入在窗口底部,输入顶部修改的文本,我们看到移动焦点回到底部的问题。这是解决方案,12月29日缺席。

While you are typing the input at window bottom and the text at the top changes, we see the problem of moving the focus back to the bottom. This is absent in the solutions as of December 29.

更新1.只是试图


  • 记得previous光标位置,然后

  • 显示输出,然后

  • 恢复位置

是<强>不是一件容易的溶液:因为这些是不同的过程,尝试检索光标位置不影响其它过程执行期间所发生的变化。

is not an easy solution: as these are different processes, attempts to retrieve cursor position don't affect the changes that happened during the other process execution.

例如,如果父母需要投入那么孩子不知道光标的位置如何变化,并在控制台的另一部分进行线路输出后不能恢复光标的位置。

Eg if parent takes input then the child doesn't know how the cursor position changed and can't restore the cursor position after performing a line of output at another part of the console.

实现,这将涉及到一些进程间通信,如果有其他的解决方案,他们可能是preferable。

Implementing this would involve some inter process communication and if there are other solutions they could be preferable.

  • Get Input from keyboard without waiting for input Related, but not specific enough.
  • How to make a chat like UI using Python Urwid? Urwid for Python which does the job (per J.F. Sebastian in the comment below). Unfortunately not in C.

推荐答案

使用标准库,有没有办法做到这一点;使用ncurses的,因为你已经暗示,它很容易成为可能;我觉得本教程解释了它相当不错。

Using the standard libraries, there's no way to do that; using ncurses, as you already suggest, it is easily possible; I think this tutorial explains it quite nicely.

这篇关于在用C控制台底部的输入栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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