kete/prompt: re-write the last line
If a log message comes in the background, it will clear the current command. Rewrite the current line buffer from readline so we get more user friendly.pull/36/head
parent
a833ff2b4c
commit
72d19ffdad
|
@ -19,6 +19,7 @@ import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import readline
|
||||||
import select
|
import select
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
@ -498,17 +499,24 @@ class TuhiKeteShellLogHandler(logging.StreamHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(TuhiKeteShellLogHandler, self).__init__(sys.stdout)
|
super(TuhiKeteShellLogHandler, self).__init__(sys.stdout)
|
||||||
self.setFormatter(logging.Formatter(log_format))
|
self.setFormatter(logging.Formatter(log_format))
|
||||||
|
self._prompt = ''
|
||||||
|
|
||||||
|
def emit(self, record):
|
||||||
|
self.terminator = f'\n{self._prompt}{readline.get_line_buffer()}'
|
||||||
|
super(TuhiKeteShellLogHandler, self).emit(record)
|
||||||
|
|
||||||
def set_normal_mode(self):
|
def set_normal_mode(self):
|
||||||
self.acquire()
|
self.acquire()
|
||||||
self.setFormatter(logging.Formatter(log_format))
|
self.setFormatter(logging.Formatter(log_format))
|
||||||
self.terminator = '\n'
|
self.terminator = '\n'
|
||||||
|
self._prompt = ''
|
||||||
self.release()
|
self.release()
|
||||||
|
|
||||||
def set_prompt_mode(self, prompt):
|
def set_prompt_mode(self, prompt):
|
||||||
self.acquire()
|
self.acquire()
|
||||||
self.setFormatter(logging.Formatter('\r{}'.format(log_format)))
|
# '\x1b[2K\r' clears the current line and start again from the beginning
|
||||||
self.terminator = '\n{}'.format(prompt)
|
self.setFormatter(logging.Formatter(f'\x1b[2K\r{log_format}'))
|
||||||
|
self._prompt = prompt
|
||||||
self.release()
|
self.release()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue