Skip to content

Commit

Permalink
fix: Catch stopping the reader thread
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicfTail committed Oct 26, 2023
1 parent 0016aac commit 5f555b4
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions ConsoleIOUI/Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,24 @@ public void Start()
EntranceHandler();

Console.OutputEncoding = Encoding.UTF8;
readerThread = new(ReadWorker)
{
IsBackground = true
};
readerThread = new(ReadWorker);

GotoAlternateBuffer();
DrawInterface();

readerThread.Start();

readerThread.Join();

GotoMainBuffer();

ExitHandler();
}

public void Stop()
{
GotoMainBuffer();
exit = true;
readerThread?.Interrupt();
ExitHandler();
exit = true;
}

private void ReadWorker()
Expand All @@ -97,8 +96,10 @@ private void ReadWorker()
Thread.Sleep(2);
}
}
finally
{ }
catch (ThreadInterruptedException)
{
exit = true;
}
}
}

Expand Down Expand Up @@ -354,17 +355,23 @@ private void ResetInput()
windowOffset = 0;
}

private static void GotoMainBuffer()
private void GotoMainBuffer()
{
Console.Clear();
Console.Write(InterfaceHelpers.DefaultCursorString);
Console.Write(InterfaceHelpers.MainBufferString);
lock (drawLock)
{
Console.Clear();
Console.Write(InterfaceHelpers.DefaultCursorString);
Console.Write(InterfaceHelpers.MainBufferString);
}
}

private static void GotoAlternateBuffer()
private void GotoAlternateBuffer()
{
Console.Write(InterfaceHelpers.AltBufferString);
Console.Clear();
Console.Write(InterfaceHelpers.SteadyBarString);
lock (drawLock)
{
Console.Write(InterfaceHelpers.AltBufferString);
Console.Clear();
Console.Write(InterfaceHelpers.SteadyBarString);
}
}
}

0 comments on commit 5f555b4

Please sign in to comment.