package wang.yaojia.webterm.terminalview

import com.termux.terminal.TerminalEmulator
import com.termux.terminal.TerminalSession
import com.termux.terminal.TerminalSessionClient

/**
 * A no-op [TerminalSessionClient] handed to the [TerminalEmulator] constructor.
 *
 * Termux's `TerminalEmulator` calls `mClient` on a handful of rare escape-sequence paths (DECRQM,
 * termcap/terminfo queries, some SGR/OSC diagnostics) WITHOUT a null-check, so the emulator must be
 * built with a non-null client or those sequences would crash the parser. We therefore supply a client
 * that swallows every callback: this class is NOT a subprocess bridge (there is no [TerminalSession] —
 * the callback parameters are always ignored) and it logs NOTHING (terminal bytes are attacker-
 * influenced; the parser's diagnostic strings must never reach logcat).
 *
 * Title changes do NOT arrive here — the emulator routes OSC 0/2 titles through
 * `TerminalOutput.titleChanged`, which [RemoteTerminalSession] handles. This client's [onTitleChanged]
 * is intentionally inert.
 */
internal class NoOpTerminalSessionClient : TerminalSessionClient {

    override fun onTextChanged(changedSession: TerminalSession?) = Unit
    override fun onTitleChanged(changedSession: TerminalSession?) = Unit
    override fun onSessionFinished(finishedSession: TerminalSession?) = Unit
    override fun onCopyTextToClipboard(session: TerminalSession?, text: String?) = Unit
    override fun onPasteTextFromClipboard(session: TerminalSession?) = Unit
    override fun onBell(session: TerminalSession?) = Unit
    override fun onColorsChanged(session: TerminalSession?) = Unit
    override fun onTerminalCursorStateChange(state: Boolean) = Unit

    /** Default block cursor; the on-screen view owns real cursor styling. */
    override fun getTerminalCursorStyle(): Int = TerminalEmulator.TERMINAL_CURSOR_STYLE_BLOCK

    override fun logError(tag: String?, message: String?) = Unit
    override fun logWarn(tag: String?, message: String?) = Unit
    override fun logInfo(tag: String?, message: String?) = Unit
    override fun logDebug(tag: String?, message: String?) = Unit
    override fun logVerbose(tag: String?, message: String?) = Unit
    override fun logStackTraceWithMessage(tag: String?, message: String?, e: Exception?) = Unit
    override fun logStackTrace(tag: String?, e: Exception?) = Unit
}
