Last active
October 27, 2022 06:34
-
-
Save JamesIgoe/77f4d07efb5cb2edf3783ceae7b7e574 to your computer and use it in GitHub Desktop.
Simple spinner for console app on long operations, providing viaul feedback.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class ConsoleSpinner | |
Private counter As Integer | |
Public Sub New() | |
counter = 0 | |
End Sub | |
Public Sub Turn(userText As String) | |
counter += 1 | |
Dim cursor As String = "" | |
Select Case counter Mod 4 | |
Case 0 | |
cursor = "/" | |
Case 1 | |
cursor = "-" | |
Case 2 | |
cursor = "\" | |
Case 3 | |
cursor = "|" | |
End Select | |
''adding 20 characters to overwrite any name | |
Dim buffer As String = " " | |
Dim contentLength = cursor.Length + userText.Length + counter.ToString().Length + 22 | |
Console.Write(String.Format("{0} {1} {2}{3}", counter, cursor, userText, buffer)) | |
Console.SetCursorPosition(Console.CursorLeft - contentLength, Console.CursorTop) | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment