Skip to content

Commit d560381

Browse files
committed
correct line size for color printing
1 parent 15f2376 commit d560381

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/meshcore_cli/meshcore_cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import asyncio
66
import os, sys
77
import time, datetime
8-
import getopt, json, shlex
8+
import getopt, json, shlex, re
99
import logging
1010
from pathlib import Path
1111
from prompt_toolkit.shortcuts import PromptSession
@@ -39,10 +39,15 @@
3939
ANSI_LIGHT_BLUE = "\033[1;34m"
4040
ANSI_LIGHT_GREEN = "\033[1;32m"
4141

42+
def escape_ansi(line):
43+
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
44+
return ansi_escape.sub('', line)
45+
4246
def print_above(str):
4347
""" prints a string above current line """
4448
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
4651
print("\u001B[s", end="") # Save current cursor position
4752
print("\u001B[A", end="") # Move cursor up one line
4853
print("\u001B[999D", end="") # Move cursor to beginning of line
@@ -173,6 +178,8 @@ async def interactive_loop(mc, to=None) :
173178
\"quit\", \"q\", CTRL+D will end interactive mode""")
174179

175180
await mc.ensure_contacts()
181+
handle_message.json_output = False
182+
handle_message.above = True
176183
await subscribe_to_msgs(mc)
177184
if to is None:
178185
contact = next(iter(mc.contacts.items()))[1]

0 commit comments

Comments
 (0)