c++ - 控制台程序如何实现tab键自动补全?
PHPz
PHPz 2017-04-17 13:15:55
0
2
841

我在实现一个类似cmd的程序,程序内置一些命令,通过tab键自动补全命令.
但是控制台没有自己的窗口过程函数,无法处理按键消息,setwindowshook也对控制台程序无效.
虽然普通的getchar可以判断是否是tab,但是命令是以行为单位的,还有backspace退格等问题,所以请教大家有没有好的方法

PHPz
PHPz

学习是最好的投资!

reply all(2)
小葫芦

GNU Readline Library - Programming with GNU Readline

迷茫

I have thought about this problem before:
You can use getchar. ch=getchar(), the value of ch is judged every time it is input.
If the backspace escape character 'b' can be overwritten by direct output.
If it is the completion of TAB key, store what you want to complete in the array, and then match it. The specific form is
1. Output a matchable character on the next line of the current cursor. If you want to match, enter the Enter key or the like. Otherwise, ignore it. Here you need to get and save the current cursor position, and then jump to The next line should also be deleted after the prompt string is displayed. blabla. .
2. Press the TAB key to directly output the matching string. To save the original point, if the user presses 'esc', the original string will be returned, record the number of matches, and just output 'b'. If you continue to press TAB, the current one will be output, and the matching next one will be output.

There are several functions for reference:
getch() // conio.h
The characters entered will not be displayed on the screen, similar to password input in Linux.
ssprintf()
Modify characters
to get the console cursor position, etc. . . .

My previous collection of articles, "How to enter the password using cmd first to display the * number"
http://www.cnblogs.com/jiangkun86/archive/2011/09/19/2181910.html

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template