mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
correct line size for color printing
This commit is contained in:
parent
15f237675f
commit
d56038133c
1 changed files with 9 additions and 2 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import os, sys
|
import os, sys
|
||||||
import time, datetime
|
import time, datetime
|
||||||
import getopt, json, shlex
|
import getopt, json, shlex, re
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from prompt_toolkit.shortcuts import PromptSession
|
from prompt_toolkit.shortcuts import PromptSession
|
||||||
|
|
@ -39,10 +39,15 @@ ANSI_RED = "\033[0;31m"
|
||||||
ANSI_LIGHT_BLUE = "\033[1;34m"
|
ANSI_LIGHT_BLUE = "\033[1;34m"
|
||||||
ANSI_LIGHT_GREEN = "\033[1;32m"
|
ANSI_LIGHT_GREEN = "\033[1;32m"
|
||||||
|
|
||||||
|
def escape_ansi(line):
|
||||||
|
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
|
||||||
|
return ansi_escape.sub('', line)
|
||||||
|
|
||||||
def print_above(str):
|
def print_above(str):
|
||||||
""" prints a string above current line """
|
""" prints a string above current line """
|
||||||
width = os.get_terminal_size().columns
|
width = os.get_terminal_size().columns
|
||||||
lines = divmod(len(str), width)[0] + 1
|
stringlen = len(escape_ansi(str))-1
|
||||||
|
lines = divmod(stringlen, width)[0] + 1
|
||||||
print("\u001B[s", end="") # Save current cursor position
|
print("\u001B[s", end="") # Save current cursor position
|
||||||
print("\u001B[A", end="") # Move cursor up one line
|
print("\u001B[A", end="") # Move cursor up one line
|
||||||
print("\u001B[999D", end="") # Move cursor to beginning of line
|
print("\u001B[999D", end="") # Move cursor to beginning of line
|
||||||
|
|
@ -173,6 +178,8 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
|
||||||
\"quit\", \"q\", CTRL+D will end interactive mode""")
|
\"quit\", \"q\", CTRL+D will end interactive mode""")
|
||||||
|
|
||||||
await mc.ensure_contacts()
|
await mc.ensure_contacts()
|
||||||
|
handle_message.json_output = False
|
||||||
|
handle_message.above = True
|
||||||
await subscribe_to_msgs(mc)
|
await subscribe_to_msgs(mc)
|
||||||
if to is None:
|
if to is None:
|
||||||
contact = next(iter(mc.contacts.items()))[1]
|
contact = next(iter(mc.contacts.items()))[1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue