0

I'm trying to print out the last line of code on a separate line, as it always prints on the same line as the spinner?

I've already tried removing the sleep function.

from halo import Halo
import time
from colorama import Fore

name = input("TARGET:\n")

spinner = Halo(text='\nCalling: ' + name, spinner='dots')

spinner.start('\rCalling: ' + name)

time.sleep(5)

print(Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')

I expect the output of the last line to be on a separate line when printed.

SimonN
  • 1,989
  • 2
  • 10
  • 18
JipBit
  • 31
  • 5
  • 2
    Does stopping the spinner first work? Or possibly adding \n at the start of your print. – SimonN Nov 03 '19 at 14:03
  • I just had to stop the spinner, thank you! Also, I know this is a separate question, but how would can I clear an output in the terminal after it's been printed? – JipBit Nov 03 '19 at 20:34
  • So that I can clear the target input and output above, and only have the final message in the console after the spinner stops. – JipBit Nov 03 '19 at 20:39

1 Answers1

0

Two options for you. On my system (Mac) your code doesn't seem to do what it's supposed to, it just prints loads of lines rather than a spinner. In any case here are options that I would expect to work:

Stop the spinner

name = input("TARGET:\n")

spinner = Halo(text='\nCalling: ' + name, spinner='dots')

spinner.start('\rCalling: ' + name)

time.sleep(5)

spinner.stop()

print(Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')

Add a newline

name = input("TARGET:\n")

spinner = Halo(text='\nCalling: ' + name, spinner='dots')

spinner.start('\rCalling: ' + name)

time.sleep(5)

print("\n" + Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')
SimonN
  • 1,989
  • 2
  • 10
  • 18
  • Both options solved my problem, thank you! Can you answer my other comment about clearing the terminal after an output? – JipBit Nov 03 '19 at 20:46
  • Answer here hopefully https://stackoverflow.com/questions/3249524/print-in-one-line-dynamically – SimonN Nov 03 '19 at 20:49
  • Would there be a way to simply clear the terminal after the spinner ends and print the last line, having it alone as the first line in the terminal? – JipBit Nov 03 '19 at 20:54
  • Check this answer https://stackoverflow.com/q/517970/11432434 – SimonN Nov 03 '19 at 20:57
  • Thank you so much! Sorry about the easy fixes, I'm new to coding with python. Very helpful! :) – JipBit Nov 03 '19 at 21:02
  • No worries, please mark the answer accepted if it helped you out. Enjoy Python, it's a great language – SimonN Nov 03 '19 at 21:26