From cfe4d9bdcee9305632eb228a46a95407d05b5c7a Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Mar 2018 18:54:50 +0300 Subject: [PATCH] Properly fix prompt printing in C# example. GitOrigin-RevId: 4a9306738d35a3ba0893ae65922a5bcef7c2f644 --- example/csharp/TdExample.cs | 18 ++++++++++++------ .../org/drinkless/tdlib/example/Example.java | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/example/csharp/TdExample.cs b/example/csharp/TdExample.cs index c7823bef..be98e1a7 100644 --- a/example/csharp/TdExample.cs +++ b/example/csharp/TdExample.cs @@ -29,6 +29,7 @@ namespace TdExample private static readonly string _newLine = Environment.NewLine; private static readonly string _commandsLine = "Enter command (gc - GetChat, me - GetMe, sm - SendMessage, lo - LogOut, q - Quit): "; + private static volatile string _currentPrompt = null; private static Td.Client CreateTdClient() { @@ -43,19 +44,24 @@ namespace TdExample private static void Print(string str) { - Console.WriteLine(); - Console.WriteLine(str); - if (_haveAuthorization) + if (_currentPrompt != null) { - Console.Write(_commandsLine); + Console.WriteLine(); + } + Console.WriteLine(str); + if (_currentPrompt != null) + { + Console.Write(_currentPrompt); } } private static string ReadLine(string str) { - Console.WriteLine(); Console.Write(str); - return Console.ReadLine(); + _currentPrompt = str; + var result = Console.ReadLine(); + _currentPrompt = null; + return result; } private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authorizationState) diff --git a/example/java/org/drinkless/tdlib/example/Example.java b/example/java/org/drinkless/tdlib/example/Example.java index c1aad644..831de88f 100644 --- a/example/java/org/drinkless/tdlib/example/Example.java +++ b/example/java/org/drinkless/tdlib/example/Example.java @@ -59,6 +59,9 @@ public final class Example { } private static void print(String str) { + if (currentPrompt != null) { + System.out.println(""); + } System.out.println(str); if (currentPrompt != null) { System.out.print(currentPrompt);