Repository: Qiskit/qiskit

Issue:
more control over job_monitor output
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
Allow the user to control the new line characters that are emitted by job_monitor output.
I found myself needing to change this to allow me to use qiskit-terra's tools on my non jupyter notebook environment.
I'm already working on a PR for this, which will appear linked here very soon.


more control over job_monitor output
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
Allow the user to control the new line characters that are emitted by job_monitor output.
I found myself needing to change this to allow me to use qiskit-terra's tools on my non jupyter notebook environment.
I'm already working on a PR for this, which will appear linked here very soon.




Discussion:

Resolving patch:
diff --git a/qiskit/tools/monitor/job_monitor.py b/qiskit/tools/monitor/job_monitor.py
--- a/qiskit/tools/monitor/job_monitor.py
+++ b/qiskit/tools/monitor/job_monitor.py
@@ -17,7 +17,9 @@
 import time
 
 
-def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.stdout):
+def _text_checker(
+    job, interval, _interval_set=False, quiet=False, output=sys.stdout, line_discipline="\r"
+):
     """A text-based job status checker
 
     Args:
@@ -27,6 +29,8 @@ def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.st
         quiet (bool): If True, do not print status messages.
         output (file): The file like object to write status messages to.
         By default this is sys.stdout.
+        line_discipline (string): character emitted at start of a line of job monitor output,
+        This defaults to \\r.
 
     """
     status = job.status()
@@ -35,7 +39,7 @@ def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.st
     msg_len = len(msg)
 
     if not quiet:
-        print("\r%s: %s" % ("Job Status", msg), end="", file=output)
+        print("%s%s: %s" % (line_discipline, "Job Status", msg), end="", file=output)
     while status.name not in ["DONE", "CANCELLED", "ERROR"]:
         time.sleep(interval)
         status = job.status()
@@ -58,13 +62,13 @@ def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.st
             msg_len = len(msg)
 
         if msg != prev_msg and not quiet:
-            print("\r%s: %s" % ("Job Status", msg), end="", file=output)
+            print("%s%s: %s" % (line_discipline, "Job Status", msg), end="", file=output)
             prev_msg = msg
     if not quiet:
         print("", file=output)
 
 
-def job_monitor(job, interval=None, quiet=False, output=sys.stdout):
+def job_monitor(job, interval=None, quiet=False, output=sys.stdout, line_discipline="\r"):
     """Monitor the status of a IBMQJob instance.
 
     Args:
@@ -73,6 +77,8 @@ def job_monitor(job, interval=None, quiet=False, output=sys.stdout):
         quiet (bool): If True, do not print status messages.
         output (file): The file like object to write status messages to.
         By default this is sys.stdout.
+        line_discipline (string): character emitted at start of a line of job monitor output,
+        This defaults to \\r.
     """
     if interval is None:
         _interval_set = False
@@ -80,4 +86,6 @@ def job_monitor(job, interval=None, quiet=False, output=sys.stdout):
     else:
         _interval_set = True
 
-    _text_checker(job, interval, _interval_set, quiet=quiet, output=output)
+    _text_checker(
+        job, interval, _interval_set, quiet=quiet, output=output, line_discipline=line_discipline
+    )


Test patch: