Hack Forums
[C] How could I work on an auto-complete feature? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] How could I work on an auto-complete feature? (/showthread.php?tid=3732453)



How could I work on an auto-complete feature? - Terry A. Davis - Sep 3, 2013

So I was thinking of it today, my program requires user input from a list and I got a thought from Linux how you press tab it auto completes to whatever command it is closest too.


My thought was something like this

Code
#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;

int main()
{
string sInput;
cout << "Enter the input";
cin >> sInput;
/*If it is an exact input as in it fits the following if statements it goes and does that.*/

/*However, if it doesn't it loads PDCurses or a similar library that allows "console" manipulation so it lists them then I can press up or down to choose the closest one judging by what the first few characters are. */
}

Yeah shit syntax and such, but idgaf. I am just stuck how I would set up like a Linux auto-completion feature. Without criticizing me to much how would I do this or can you point me somewhere?


* - g4143 - Sep 3, 2013

If your trying to implement this on a Linux console then you'll have to look at the ncurses library so that you can grab keystrokes and display output.


* - Terry A. Davis - Sep 3, 2013

Nah sadly I am using crappy pdcurses for Windows for the time being.


* - g4143 - Sep 3, 2013

(Sep 3, 2013 03:23 AM)Perfect Cell Wrote:  Nah sadly I am using crappy pdcurses for Windows for the time being.

Did you try looking at Window's conio functionality?


* - Shihanus - Sep 3, 2013

The other problem is that as far as I'm aware cin is a blocking functions. You'll have to use non blocking input or multiple threads.