Filter ANSI output before Slack forwarding
This commit is contained in:
@@ -7,6 +7,7 @@ import threading
|
||||
import time
|
||||
|
||||
from lazy_enter.config import Config
|
||||
from lazy_enter.output_filter import clean_terminal_output
|
||||
from lazy_enter.pty_manager import PtyManager
|
||||
from lazy_enter.slack_handler import SlackHandler
|
||||
|
||||
@@ -23,6 +24,7 @@ class Bridge:
|
||||
self._output_thread: threading.Thread | None = None
|
||||
self._running = False
|
||||
self._channel: str = self.config.allowed_channel_id
|
||||
self._last_sent_output: str = ""
|
||||
|
||||
self.slack.on_message(self._handle_message)
|
||||
self.slack.on_command(self._handle_command)
|
||||
@@ -51,6 +53,7 @@ class Bridge:
|
||||
return
|
||||
|
||||
self._channel = channel
|
||||
self._last_sent_output = ""
|
||||
self.pty = PtyManager(self.config.default_shell)
|
||||
self.pty.start()
|
||||
self._running = True
|
||||
@@ -65,6 +68,7 @@ class Bridge:
|
||||
if self.pty:
|
||||
self.pty.stop()
|
||||
self.pty = None
|
||||
self._last_sent_output = ""
|
||||
self.slack.send_message(channel, ":stop_sign: 세션이 종료되었습니다.")
|
||||
|
||||
def _poll_output(self) -> None:
|
||||
@@ -73,14 +77,18 @@ class Bridge:
|
||||
while self._running and self.pty and self.pty.is_alive:
|
||||
output = self.pty.read_output(timeout=self.config.pty_read_timeout)
|
||||
if output:
|
||||
buffer += output
|
||||
cleaned = clean_terminal_output(output)
|
||||
if cleaned:
|
||||
buffer += f"{cleaned}\n"
|
||||
|
||||
if buffer:
|
||||
# 메시지 길이 제한 적용
|
||||
message = buffer[: self.config.max_message_length]
|
||||
message = buffer[: self.config.max_message_length].rstrip()
|
||||
if len(buffer) > self.config.max_message_length:
|
||||
message += "\n... (truncated)"
|
||||
self.slack.send_message(self._channel, f"```\n{message}\n```")
|
||||
if message and message != self._last_sent_output:
|
||||
self.slack.send_message(self._channel, f"```\n{message}\n```")
|
||||
self._last_sent_output = message
|
||||
buffer = ""
|
||||
|
||||
time.sleep(self.config.output_buffer_interval)
|
||||
|
||||
Reference in New Issue
Block a user