Skip to content

Commit cfe4d9b

Browse files
committed
Properly fix prompt printing in C# example.
GitOrigin-RevId: 4a9306738d35a3ba0893ae65922a5bcef7c2f644
1 parent 42d5248 commit cfe4d9b

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

example/csharp/TdExample.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Example
2929

3030
private static readonly string _newLine = Environment.NewLine;
3131
private static readonly string _commandsLine = "Enter command (gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ";
32+
private static volatile string _currentPrompt = null;
3233

3334
private static Td.Client CreateTdClient()
3435
{
@@ -43,19 +44,24 @@ private static Td.Client CreateTdClient()
4344

4445
private static void Print(string str)
4546
{
46-
Console.WriteLine();
47+
if (_currentPrompt != null)
48+
{
49+
Console.WriteLine();
50+
}
4751
Console.WriteLine(str);
48-
if (_haveAuthorization)
52+
if (_currentPrompt != null)
4953
{
50-
Console.Write(_commandsLine);
54+
Console.Write(_currentPrompt);
5155
}
5256
}
5357

5458
private static string ReadLine(string str)
5559
{
56-
Console.WriteLine();
5760
Console.Write(str);
58-
return Console.ReadLine();
61+
_currentPrompt = str;
62+
var result = Console.ReadLine();
63+
_currentPrompt = null;
64+
return result;
5965
}
6066

6167
private static void OnAuthorizationStateUpdated(TdApi.AuthorizationState authorizationState)

example/java/org/drinkless/tdlib/example/Example.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public final class Example {
5959
}
6060

6161
private static void print(String str) {
62+
if (currentPrompt != null) {
63+
System.out.println("");
64+
}
6265
System.out.println(str);
6366
if (currentPrompt != null) {
6467
System.out.print(currentPrompt);

0 commit comments

Comments
 (0)