Properly fix prompt printing in C# example.

GitOrigin-RevId: 4a9306738d35a3ba0893ae65922a5bcef7c2f644
This commit is contained in:
levlam 2018-03-20 18:54:50 +03:00
parent 42d5248446
commit cfe4d9bdce
2 changed files with 15 additions and 6 deletions

View File

@ -29,6 +29,7 @@ namespace TdExample
private static readonly string _newLine = Environment.NewLine; private static readonly string _newLine = Environment.NewLine;
private static readonly string _commandsLine = "Enter command (gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): "; private static readonly string _commandsLine = "Enter command (gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ";
private static volatile string _currentPrompt = null;
private static Td.Client CreateTdClient() private static Td.Client CreateTdClient()
{ {
@ -43,19 +44,24 @@ namespace TdExample
private static void Print(string str) private static void Print(string str)
{ {
Console.WriteLine(); if (_currentPrompt != null)
Console.WriteLine(str);
if (_haveAuthorization)
{ {
Console.Write(_commandsLine); Console.WriteLine();
}
Console.WriteLine(str);
if (_currentPrompt != null)
{
Console.Write(_currentPrompt);
} }
} }
private static string ReadLine(string str) private static string ReadLine(string str)
{ {
Console.WriteLine();
Console.Write(str); Console.Write(str);
return Console.ReadLine(); _currentPrompt = str;
var result = Console.ReadLine();
_currentPrompt = null;
return result;
} }
private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authorizationState) private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authorizationState)

View File

@ -59,6 +59,9 @@ public final class Example {
} }
private static void print(String str) { private static void print(String str) {
if (currentPrompt != null) {
System.out.println("");
}
System.out.println(str); System.out.println(str);
if (currentPrompt != null) { if (currentPrompt != null) {
System.out.print(currentPrompt); System.out.print(currentPrompt);