Skip to content

Commit 5884844

Browse files
committed
Strip ANSI escape codes from command output
Add regex pattern to remove ANSI escape sequences from dcover output lines. This ensures clean, readable output in MCP clients that don't properly handle terminal control codes. Changes: - Import re module - Define ANSI_ESCAPE pattern for matching escape sequences - Strip escape codes before yielding output lines
1 parent 29ee418 commit 5884844

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

covermcp/executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
import contextlib
17+
import re
1718
import time
1819
from collections.abc import Iterator
1920
from pathlib import Path
@@ -22,6 +23,8 @@
2223

2324
CLEANUP_TIMEOUT: Final[int] = 5
2425

26+
ANSI_ESCAPE: Final[re] = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
27+
2528

2629
def execute(command: list[str], working_dir: Path, timeout: int | None) -> Iterator[str]:
2730
"""Execute the given command in the working directory with real-time output streaming.
@@ -66,7 +69,7 @@ def execute(command: list[str], working_dir: Path, timeout: int | None) -> Itera
6669
cleanup_process(process)
6770
raise TimeoutExpired(command, timeout)
6871

69-
yield line.rstrip("\n\r")
72+
yield ANSI_ESCAPE.sub("", line.rstrip("\n\r"))
7073

7174
if timeout is not None:
7275
elapsed = time.time() - start_time

0 commit comments

Comments
 (0)