At first I thought clearing a specific console line was not feasible, but a quick search showed me that nothing is impossible.
So I created a new console application and started thinking of how I'd get something like that to work. Below is the "first working draft" - I'm about to [heavily] refactor it on my own and then put the resulting code up on Code Review, but this should be good enough to get you started.
The program makes the Tab key autocomplete the current input using an array of strings as data, matching the first item it finds; you'll have to tweak it a bit if you want something smarter (like having the current folder's child paths as data, and/or iterating through matches at each consecutive press of the Tab key):
class Program
{
static void Main(string[] args)
{
var data = new[]
{
"Bar",
"Barbec",
"Barbecue",
"Batman",
};
var builder = new StringBuilder();
var input = Console.ReadKey(intercept:true);
while (input.Key != ConsoleKey.Enter)
{
var currentInput = builder.ToString();
if (input.Key == ConsoleKey.Tab)
{
var match = data.FirstOrDefault(item => item != currentInput && item.StartsWith(currentInput, true, CultureInfo.InvariantCulture));
if (string.IsNullOrEmpty(match))
{
input = Console.ReadKey(intercept: true);
continue;
}
ClearCurrentLine();
builder.Clear();
Console.Write(match);
builder.Append(match);
}
else
{
if (input.Key == ConsoleKey.Backspace && currentInput.Length > 0)
{
builder.Remove(builder.Length - 1, 1);
ClearCurrentLine();
currentInput = currentInput.Remove(currentInput.Length - 1);
Console.Write(currentInput);
}
else
{
var key = input.KeyChar;
builder.Append(key);
Console.Write(key);
}
}
input = Console.ReadKey(intercept:true);
}
Console.Write(input.KeyChar);
}
/// <remarks>
/// https://stackoverflow.com/a/8946847/1188513
/// </remarks>>
private static void ClearCurrentLine()
{
var currentLine = Console.CursorTop;
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth));
Console.SetCursorPosition(0, currentLine);
}
}
Thanks for this question, that was fun!