[console] Fix another concurrently logic

This commit is contained in:
Karlatemp 2022-11-02 18:02:24 +08:00
parent 9e7fd79225
commit 7cbff5a8c2
No known key found for this signature in database
GPG Key ID: BA173CA2B9956C59

View File

@ -13,6 +13,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.suspendCancellableCoroutine
import net.mamoe.mirai.console.fontend.ProcessProgress
import net.mamoe.mirai.console.terminal.noconsole.NoConsole
import net.mamoe.mirai.utils.ConcurrentLinkedQueue
import net.mamoe.mirai.utils.cast
import net.mamoe.mirai.utils.currentTimeMillis
import org.jline.reader.MaskingCallback
@ -104,6 +105,7 @@ internal class TerminalProcessProgress(
lastTerminalWidth = terminalWidth
// endregion
synchronized(renderedTxt) {
val renderedTextWidth = when (terminalWidth) {
0 -> renderedTxt.length
@ -142,6 +144,7 @@ internal class TerminalProcessProgress(
needUpdateTxt = false
needRerender = false
}
}
override fun rerender() {
updateTerminalDownloadingProgresses()
@ -221,7 +224,7 @@ private val terminalDownloadingProgressesNoticer = Object()
internal var containDownloadingProgress: Boolean = false
get() = field || terminalDownloadingProgresses.isNotEmpty()
internal val terminalDownloadingProgresses = mutableListOf<TerminalProcessProgress>()
internal val terminalDownloadingProgresses = ConcurrentLinkedQueue<TerminalProcessProgress>()
internal var downloadingProgressCoroutine: Continuation<Unit>? = null
@ -254,9 +257,9 @@ internal fun updateTerminalDownloadingProgresses() {
}
terminalDisplay.update(listOf(AttributedString.EMPTY), 0, false)
// Error in idea when more than one bar displaying
terminalDisplay.update(listOf(terminalDownloadingProgresses[0].let {
terminalDisplay.update(listOf(terminalDownloadingProgresses.peek()?.let {
it.updateTxt(0); it.ansiMsg
}), 0)
} ?: AttributedString.EMPTY), 0)
} else {
if (terminalDownloadingProgresses.size > 4) {
// to mush. delete some completed status