@@ -8,6 +8,7 @@ import kotlinx.collections.immutable.persistentListOf
8
8
import kotlinx.collections.immutable.persistentMapOf
9
9
import kotlinx.collections.immutable.plus
10
10
import kotlinx.collections.immutable.toPersistentHashSet
11
+ import kotlinx.collections.immutable.toPersistentList
11
12
import kotlinx.coroutines.CoroutineScope
12
13
import kotlinx.coroutines.Dispatchers
13
14
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -73,15 +74,16 @@ import warlockfe.warlock3.stormfront.protocol.StormfrontModeEvent
73
74
import warlockfe.warlock3.stormfront.protocol.StormfrontNavEvent
74
75
import warlockfe.warlock3.stormfront.protocol.StormfrontOutputEvent
75
76
import warlockfe.warlock3.stormfront.protocol.StormfrontParseErrorEvent
77
+ import warlockfe.warlock3.stormfront.protocol.StormfrontPopStyleEvent
76
78
import warlockfe.warlock3.stormfront.protocol.StormfrontProgressBarEvent
77
79
import warlockfe.warlock3.stormfront.protocol.StormfrontPromptEvent
78
80
import warlockfe.warlock3.stormfront.protocol.StormfrontPropertyEvent
79
81
import warlockfe.warlock3.stormfront.protocol.StormfrontProtocolHandler
82
+ import warlockfe.warlock3.stormfront.protocol.StormfrontPushStyleEvent
80
83
import warlockfe.warlock3.stormfront.protocol.StormfrontRoundTimeEvent
81
84
import warlockfe.warlock3.stormfront.protocol.StormfrontSettingsInfoEvent
82
85
import warlockfe.warlock3.stormfront.protocol.StormfrontStreamEvent
83
86
import warlockfe.warlock3.stormfront.protocol.StormfrontStreamWindowEvent
84
- import warlockfe.warlock3.stormfront.protocol.StormfrontStyleEvent
85
87
import warlockfe.warlock3.stormfront.protocol.StormfrontTimeEvent
86
88
import warlockfe.warlock3.stormfront.protocol.StormfrontUnhandledTagEvent
87
89
import warlockfe.warlock3.stormfront.stream.StormfrontWindow
@@ -94,6 +96,7 @@ import java.net.Socket
94
96
import java.net.SocketException
95
97
import java.net.SocketTimeoutException
96
98
import java.nio.charset.Charset
99
+ import java.util.*
97
100
import java.util.concurrent.ConcurrentHashMap
98
101
import kotlin.math.max
99
102
@@ -240,7 +243,7 @@ class StormfrontClient(
240
243
private var parseText = true
241
244
242
245
private var currentStream: TextStream = mainStream
243
- private var currentStyle : WarlockStyle ? = null
246
+ private val styleStack = Stack < WarlockStyle >()
244
247
245
248
// Output style is for echo style! Not received text
246
249
private var outputStyle: WarlockStyle ? = null
@@ -337,12 +340,15 @@ class StormfrontClient(
337
340
is StormfrontOutputEvent ->
338
341
outputStyle = event.style
339
342
340
- is StormfrontStyleEvent ->
341
- currentStyle = event.style
343
+ is StormfrontPushStyleEvent ->
344
+ styleStack.push(event.style)
345
+
346
+ StormfrontPopStyleEvent ->
347
+ styleStack.pop()
342
348
343
349
is StormfrontPromptEvent -> {
344
350
currentTypeAhead.update { max(0 , it - 1 ) }
345
- currentStyle = null
351
+ styleStack.clear()
346
352
currentStream = mainStream
347
353
if (! isPrompting) {
348
354
mainStream.appendPartial(
@@ -418,7 +424,7 @@ class StormfrontClient(
418
424
419
425
is StormfrontComponentDefinitionEvent -> {
420
426
// Should not happen on main stream, so don't clear prompt
421
- val styles = currentStyle?. let { persistentListOf(it) } ? : persistentListOf ()
427
+ val styles = styleStack.toPersistentList ()
422
428
bufferText(
423
429
text = StyledString (
424
430
persistentListOf(
@@ -535,7 +541,7 @@ class StormfrontClient(
535
541
536
542
private fun bufferText (text : StyledString ) {
537
543
var styledText = text
538
- currentStyle?. let { styledText = styledText.applyStyle(it) }
544
+ styleStack.asReversed().forEach { styledText = styledText.applyStyle(it) }
539
545
outputStyle?.let { styledText = styledText.applyStyle(it) }
540
546
buffer = buffer?.plus(styledText) ? : styledText
541
547
}
0 commit comments