Skip to content

Instantly share code, notes, and snippets.

@JamesIgoe
Last active October 27, 2022 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesIgoe/77f4d07efb5cb2edf3783ceae7b7e574 to your computer and use it in GitHub Desktop.
Save JamesIgoe/77f4d07efb5cb2edf3783ceae7b7e574 to your computer and use it in GitHub Desktop.
Simple spinner for console app on long operations, providing viaul feedback.
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