From 0e3775f619d26dad80232006309bf38804ecb383 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 11 Sep 2025 11:04:15 +0100 Subject: [PATCH] fix(siren/dump): add function to strip ANSI escape sequences from output The `cursor` CLI tool started printing some info about outdated version before clearing the screen with ANSI escape sequences. Hence we need to filter that out when dumping the list of extensions to a lock file. --- siren | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/siren b/siren index b0d83fb..4314ec7 100755 --- a/siren +++ b/siren @@ -283,6 +283,12 @@ resolve_symlink() { fi } +# Strip ANSI escape sequences from stdin and write clean text to stdout. +# This removes CSI sequences like ESC[...A/K that UIs use for status lines. +strip_ansi_sequences() { + awk '{ gsub(/\033\[[0-9;?]*[ -\/]*[@-~]/, ""); print }' +} + # Backup and symlink. backup_and_link() { local source="$1" @@ -1101,7 +1107,9 @@ do_dump_extensions() { echo "# ${SETUP_EDITOR} Extensions" echo "# Generated on ${current_date}" echo - "${editor_cmd}" --list-extensions --show-versions 2> /dev/null + "${editor_cmd}" --list-extensions --show-versions 2> /dev/null | + strip_ansi_sequences | + grep -E '^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+@[A-Za-z0-9._-]+$' } > "${extensions_lock}" info "Extensions list dumped to ${extensions_lock}"