简体   繁体   English

如何接受Tab作为STDIN的输入以自动填充文本

[英]How do I accept Tab as input from STDIN to autofill text

How do I do autofill a text when Tab key is pressed after a period from STDIN using C? 使用C在距STDIN一段时间后按下Tab键时,如何自动填充文本?

Input would look like, 输入看起来像

C:\>autofil.exe Hello
C:\>autofil.exe Hello.  ( When I enter a period, it should autofil Hello after the period)
C:\>autofil.exe Hello.World  *World is autofilled when period was entered.

Second requirement is if I am at 第二个条件是我是否在

C:\>autofil.exe Hello.World  (And when i press Tab key, `World` should print with other suggestions, as `Friend`, and if I press Tab again, print `Matt`, and scroll so on when tab is pressed... )

Well, that is my requirement. 好吧,这是我的要求。 Tab complete to autofill text. 制表符完成以自动填充文本。 Also, want to know how to read the Tab key from STDIN. 另外,想知道如何从STDIN中读取Tab键。

Thanks! 谢谢!

You could use Readline GNU library For Windows , is pretty easy to use, the other way around is to use PDcurses / Ncurses (are almost the same) and do it by hand (handling console behavior and such). 您可以使用Readline GNU库对于Windows ,它非常易于使用,另一种方法是使用PDcurses / Ncurses (几乎相同)并手动完成(处理控制台行为等)。

In case you use readline, to acomplish autocomplete is as simple as doing: 如果您使用readline,完成自动完成就很简单:

rl_bind_key('\t', rl_complete);
char *input = readline("C:\>");

In case you use Ncurses/PDcurses, you will have to do a little more work :) 如果您使用Ncurses / PDcurses,则需要做更多的工作:)

  • First you save actual console parameters. 首先,您保存实际的控制台参数。
  • Then you set echo of the input off with noecho(). 然后使用noecho()将输入的回显设置为关闭。
  • You will have to handle input and parse the arguments to call programs. 您将必须处理输入并解析参数以调用程序。
  • Also you will have to search in dirs (current and the ones on PATH variable) for things matching your current input. 另外,您还必须在目录(当前目录和PATH变量中的目录)中搜索与您的当前输入相匹配的内容。

Before ending your program set again the saved console parameters. 在结束程序之前,请再次设置保存的控制台参数。

Ncurses How-To Is an easy right to the point guide. Ncurses操作方法是指向指南的简单方法。

Posix curses definition Contains functions and key definitions. Posix curses定义包含功能和键定义。

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

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