この問題はほとんど美的であることを私は知っていますが、このようなものは私を悩ませます。私は自分の質問に答えるのは嫌いですが、実際には、他の人からのいくつかの入力に基づいて、これに対するかなりまともな解決策を思いつきました。誰かが将来同様のことをしたい場合に備えて、コードサンプルを添付します。これを行うにはおそらくもっと良い方法があることを私は知っていますが、これが私がしたことです。
基本的に、各スレッドからconsole.writelineを使用する代わりに、背後にいくつかのロジックを持つ新しいサブルーチン(TextOut)を作成しました。また、console.readline()を使用する代わりに、各文字を共有文字列に読み込むように入力スレッドを更新しました。コードは次のとおりです。
Private command As String = ""
Private Sub ConsoleInput()
Dim cki As ConsoleKeyInfo
cki = Console.ReadKey()
If cki.Key = ConsoleKey.Escape Then
command = "" 'Clear command
ElseIf cki.Key = ConsoleKey.Backspace Then
If Len(command) > 0 Then 'Make sure you don't go out of bounds
For i As Integer = 0 To Len(command)
Console.Write(" ") 'Clear output since new string will be shorter
Next
command = Left(command, Len(command) - 1) 'Shorten command by 1 char
End If
Console.CursorLeft = 0 'Set the cursor to the beginning of the line
Console.Write(command) 'Write the command to the screen
ElseIf cki.Key = ConsoleKey.Enter Then 'Command has been submitted, start checking
Console.CursorLeft = 0 'Set the cursor to the beginning of the line
For i As Integer = 0 To Len(command)
Console.Write(" ") 'Clear output from command (hides the executed command)
Next
Dim tempCMD As String = command
command = ""
'If/then statements for validating command goes here
command = "" 'Clear command to allow new input
Else
command += cki.KeyChar 'Add char to command string
Console.CursorLeft = 0 'Set the cursor to the beginning of the line
Console.Write(command) 'Write the command to the screen
End If
ConsoleInput() 'Loop for more input
End Sub
Sub TextOut(ByVal message As String)
If command <> "" Then
For i As Integer = 0 To Len(command)
Console.Write(" ") 'Clears output in case output is shorter than current command
Next
Console.CursorLeft = 0 'Sets cursor to beginning of row
End If
Console.WriteLine(message) 'Writes the current message to the screen
If message <> command Then
Console.Write(command) 'Writes the command back to the screen
End If
End Sub