#!/usr/bin/python3
#
# SPDX-License-Identifier: GPL-2.0-only
# (c) 2026 Gerd Hoffmann
#
""" misc utility functions """
import re
import datetime

zapterm1 = re.compile(r'\x1b\[[0-9;:=?!]*[HJhlmnpt]')
zapterm2 = re.compile(r'\x1b\][0-9]*')
zapterm3 = re.compile(r'[\x07\r]')

def zap_term(line):
    """ remove terminal control sequences """
    line = zapterm1.sub('', line)
    line = zapterm2.sub('', line)
    line = zapterm3.sub('', line)
    return line

def iso_now():
    """ return current time in iso format """
    tz = datetime.timezone.utc
    ts = datetime.datetime.now(tz)
    return ts.isoformat()
