|
5 | 5 | import asyncio |
6 | 6 | import os, sys |
7 | 7 | import time, datetime |
8 | | -import getopt, json, shlex |
| 8 | +import getopt, json, shlex, re |
9 | 9 | import logging |
10 | 10 | from pathlib import Path |
11 | 11 | from prompt_toolkit.shortcuts import PromptSession |
|
39 | 39 | ANSI_LIGHT_BLUE = "\033[1;34m" |
40 | 40 | ANSI_LIGHT_GREEN = "\033[1;32m" |
41 | 41 |
|
| 42 | +def escape_ansi(line): |
| 43 | + ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]') |
| 44 | + return ansi_escape.sub('', line) |
| 45 | + |
42 | 46 | def print_above(str): |
43 | 47 | """ prints a string above current line """ |
44 | 48 | width = os.get_terminal_size().columns |
45 | | - lines = divmod(len(str), width)[0] + 1 |
| 49 | + stringlen = len(escape_ansi(str))-1 |
| 50 | + lines = divmod(stringlen, width)[0] + 1 |
46 | 51 | print("\u001B[s", end="") # Save current cursor position |
47 | 52 | print("\u001B[A", end="") # Move cursor up one line |
48 | 53 | print("\u001B[999D", end="") # Move cursor to beginning of line |
@@ -173,6 +178,8 @@ async def interactive_loop(mc, to=None) : |
173 | 178 | \"quit\", \"q\", CTRL+D will end interactive mode""") |
174 | 179 |
|
175 | 180 | await mc.ensure_contacts() |
| 181 | + handle_message.json_output = False |
| 182 | + handle_message.above = True |
176 | 183 | await subscribe_to_msgs(mc) |
177 | 184 | if to is None: |
178 | 185 | contact = next(iter(mc.contacts.items()))[1] |
|
0 commit comments