mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 10:22:58 +08:00
fix: color mismatch issue
This commit is contained in:
@@ -691,6 +691,13 @@ class ControlSequenceIntroducerProcessor(terminal: Terminal, reader: TerminalRea
|
|||||||
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
|
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
|
||||||
1049 -> {
|
1049 -> {
|
||||||
|
|
||||||
|
// Save cursor
|
||||||
|
if (enable) {
|
||||||
|
CursorStoreStores.store(terminal)
|
||||||
|
} else {
|
||||||
|
CursorStoreStores.restore(terminal)
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是关闭 清屏
|
// 如果是关闭 清屏
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
terminal.getDocument().eraseInDisplay(2)
|
terminal.getDocument().eraseInDisplay(2)
|
||||||
@@ -924,7 +931,7 @@ class ControlSequenceIntroducerProcessor(terminal: Terminal, reader: TerminalRea
|
|||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
if (log.isWarnEnabled) {
|
if (log.isWarnEnabled) {
|
||||||
log.warn("xterm-256 foreground color, code: $code")
|
log.warn("xterm-256 background color, code: $code")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
66
src/main/kotlin/app/termora/terminal/CursorStoreStores.kt
Normal file
66
src/main/kotlin/app/termora/terminal/CursorStoreStores.kt
Normal file
@@ -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<Graphic, CharacterSet>()
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -333,59 +333,12 @@ class EscapeSequenceProcessor(terminal: Terminal, reader: TerminalReader) : Abst
|
|||||||
|
|
||||||
// ESC 7 Save Cursor (DECSC), VT100.
|
// ESC 7 Save Cursor (DECSC), VT100.
|
||||||
'7' -> {
|
'7' -> {
|
||||||
val graphicCharacterSet = terminalModel.getData(DataKey.GraphicCharacterSet)
|
CursorStoreStores.store(terminal)
|
||||||
// 避免引用
|
|
||||||
val characterSets = mutableMapOf<Graphic, CharacterSet>()
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore Cursor (DECRC), VT100.
|
// Restore Cursor (DECRC), VT100.
|
||||||
'8' -> {
|
'8' -> {
|
||||||
val cursorStore = if (terminalModel.hasData(DataKey.SaveCursor)) {
|
CursorStoreStores.restore(terminal)
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user