diff --git a/src/main/kotlin/app/termora/terminal/ControlSequenceIntroducerProcessor.kt b/src/main/kotlin/app/termora/terminal/ControlSequenceIntroducerProcessor.kt index 855c649..3acdfdf 100644 --- a/src/main/kotlin/app/termora/terminal/ControlSequenceIntroducerProcessor.kt +++ b/src/main/kotlin/app/termora/terminal/ControlSequenceIntroducerProcessor.kt @@ -691,6 +691,13 @@ class ControlSequenceIntroducerProcessor(terminal: Terminal, reader: TerminalRea // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer 1049 -> { + // Save cursor + if (enable) { + CursorStoreStores.store(terminal) + } else { + CursorStoreStores.restore(terminal) + } + // 如果是关闭 清屏 if (!enable) { terminal.getDocument().eraseInDisplay(2) @@ -924,7 +931,7 @@ class ControlSequenceIntroducerProcessor(terminal: Terminal, reader: TerminalRea else -> { if (log.isWarnEnabled) { - log.warn("xterm-256 foreground color, code: $code") + log.warn("xterm-256 background color, code: $code") } } } diff --git a/src/main/kotlin/app/termora/terminal/CursorStoreStores.kt b/src/main/kotlin/app/termora/terminal/CursorStoreStores.kt new file mode 100644 index 0000000..36c98cb --- /dev/null +++ b/src/main/kotlin/app/termora/terminal/CursorStoreStores.kt @@ -0,0 +1,66 @@ +package app.termora.terminal + +import org.slf4j.LoggerFactory + + +object CursorStoreStores { + private val log = LoggerFactory.getLogger(CursorStoreStores::class.java) + + fun restore(terminal: Terminal) { + val terminalModel = terminal.getTerminalModel() + val cursorStore = if (terminalModel.hasData(DataKey.SaveCursor)) { + terminalModel.getData(DataKey.SaveCursor) + } else { + CursorStore( + position = Position(1, 1), + textStyle = TextStyle.Default, + autoWarpMode = false, + originMode = false, + graphicCharacterSet = GraphicCharacterSet() + ) + } + + terminalModel.setData(DataKey.OriginMode, cursorStore.originMode) + terminalModel.setData(DataKey.TextStyle, cursorStore.textStyle) + terminalModel.setData(DataKey.AutoWrapMode, cursorStore.autoWarpMode) + terminalModel.setData(DataKey.GraphicCharacterSet, cursorStore.graphicCharacterSet) + + val region = if (terminalModel.isOriginMode()) terminalModel.getScrollingRegion() + else ScrollingRegion(top = 1, bottom = terminalModel.getRows()) + var y = cursorStore.position.y + if (y < region.top) { + y = 1 + } else if (y > region.bottom) { + y = region.bottom + } + + terminal.getCursorModel().move(row = y, col = cursorStore.position.x) + + if (log.isDebugEnabled) { + log.debug("Restore Cursor (DECRC). $cursorStore") + } + } + + fun store(terminal: Terminal) { + val terminalModel = terminal.getTerminalModel() + + val graphicCharacterSet = terminalModel.getData(DataKey.GraphicCharacterSet) + // 避免引用 + val characterSets = mutableMapOf() + characterSets.putAll(graphicCharacterSet.characterSets) + + val cursorStore = CursorStore( + position = terminal.getCursorModel().getPosition(), + textStyle = terminalModel.getData(DataKey.TextStyle), + autoWarpMode = terminalModel.getData(DataKey.AutoWrapMode, false), + originMode = terminalModel.isOriginMode(), + graphicCharacterSet = graphicCharacterSet.copy(characterSets = characterSets), + ) + + terminalModel.setData(DataKey.SaveCursor, cursorStore) + + if (log.isDebugEnabled) { + log.debug("Save Cursor (DECSC). $cursorStore") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/termora/terminal/EscapeSequenceProcessor.kt b/src/main/kotlin/app/termora/terminal/EscapeSequenceProcessor.kt index ae35823..93bc284 100644 --- a/src/main/kotlin/app/termora/terminal/EscapeSequenceProcessor.kt +++ b/src/main/kotlin/app/termora/terminal/EscapeSequenceProcessor.kt @@ -333,59 +333,12 @@ class EscapeSequenceProcessor(terminal: Terminal, reader: TerminalReader) : Abst // ESC 7 Save Cursor (DECSC), VT100. '7' -> { - val graphicCharacterSet = terminalModel.getData(DataKey.GraphicCharacterSet) - // 避免引用 - val characterSets = mutableMapOf() - characterSets.putAll(graphicCharacterSet.characterSets) - - val cursorStore = CursorStore( - position = terminal.getCursorModel().getPosition(), - textStyle = terminalModel.getData(DataKey.TextStyle), - autoWarpMode = terminalModel.getData(DataKey.AutoWrapMode, false), - originMode = terminalModel.isOriginMode(), - graphicCharacterSet = graphicCharacterSet.copy(characterSets = characterSets), - ) - - terminalModel.setData(DataKey.SaveCursor, cursorStore) - - if (log.isDebugEnabled) { - log.debug("Save Cursor (DECSC). $cursorStore") - } + CursorStoreStores.store(terminal) } // Restore Cursor (DECRC), VT100. '8' -> { - val cursorStore = if (terminalModel.hasData(DataKey.SaveCursor)) { - terminalModel.getData(DataKey.SaveCursor) - } else { - CursorStore( - position = Position(1, 1), - textStyle = TextStyle.Default, - autoWarpMode = false, - originMode = false, - graphicCharacterSet = GraphicCharacterSet() - ) - } - - terminalModel.setData(DataKey.OriginMode, cursorStore.originMode) - terminalModel.setData(DataKey.TextStyle, cursorStore.textStyle) - terminalModel.setData(DataKey.AutoWrapMode, cursorStore.autoWarpMode) - terminalModel.setData(DataKey.GraphicCharacterSet, cursorStore.graphicCharacterSet) - - val region = if (terminalModel.isOriginMode()) terminalModel.getScrollingRegion() - else ScrollingRegion(top = 1, bottom = terminalModel.getRows()) - var y = cursorStore.position.y - if (y < region.top) { - y = 1 - } else if (y > region.bottom) { - y = region.bottom - } - - terminal.getCursorModel().move(row = y, col = cursorStore.position.x) - - if (log.isDebugEnabled) { - log.debug("Restore Cursor (DECRC). $cursorStore") - } + CursorStoreStores.restore(terminal) }