mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 09:47:31 +08:00
[console] Fix another concurrently logic
This commit is contained in:
parent
9e7fd79225
commit
7cbff5a8c2
@ -13,6 +13,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import net.mamoe.mirai.console.fontend.ProcessProgress
|
import net.mamoe.mirai.console.fontend.ProcessProgress
|
||||||
import net.mamoe.mirai.console.terminal.noconsole.NoConsole
|
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.cast
|
||||||
import net.mamoe.mirai.utils.currentTimeMillis
|
import net.mamoe.mirai.utils.currentTimeMillis
|
||||||
import org.jline.reader.MaskingCallback
|
import org.jline.reader.MaskingCallback
|
||||||
@ -104,43 +105,45 @@ internal class TerminalProcessProgress(
|
|||||||
|
|
||||||
lastTerminalWidth = terminalWidth
|
lastTerminalWidth = terminalWidth
|
||||||
// endregion
|
// endregion
|
||||||
|
synchronized(renderedTxt) {
|
||||||
|
|
||||||
val renderedTextWidth = when (terminalWidth) {
|
val renderedTextWidth = when (terminalWidth) {
|
||||||
0 -> renderedTxt.length
|
0 -> renderedTxt.length
|
||||||
else -> terminalWidth
|
else -> terminalWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
val finalAnsiLineBuilder = AttributedStringBuilder()
|
val finalAnsiLineBuilder = AttributedStringBuilder()
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
finalAnsiLineBuilder.style(
|
|
||||||
AttributedStyle.DEFAULT
|
|
||||||
.background(AttributedStyle.RED)
|
|
||||||
.foreground(AttributedStyle.BLACK)
|
|
||||||
)
|
|
||||||
finalAnsiLineBuilder.append(renderedTxt, 0, renderedTextWidth)
|
|
||||||
} else {
|
|
||||||
val downpcent = (renderedTextWidth * processed / totalSize).toInt()
|
|
||||||
if (downpcent > 0) {
|
|
||||||
finalAnsiLineBuilder.style(
|
finalAnsiLineBuilder.style(
|
||||||
AttributedStyle.DEFAULT
|
AttributedStyle.DEFAULT
|
||||||
.background(AttributedStyle.GREEN)
|
.background(AttributedStyle.RED)
|
||||||
.foreground(AttributedStyle.BLACK)
|
.foreground(AttributedStyle.BLACK)
|
||||||
)
|
)
|
||||||
finalAnsiLineBuilder.append(renderedTxt, 0, downpcent)
|
finalAnsiLineBuilder.append(renderedTxt, 0, renderedTextWidth)
|
||||||
}
|
} else {
|
||||||
if (downpcent < renderedTextWidth) {
|
val downpcent = (renderedTextWidth * processed / totalSize).toInt()
|
||||||
finalAnsiLineBuilder.style(
|
if (downpcent > 0) {
|
||||||
AttributedStyle.DEFAULT
|
finalAnsiLineBuilder.style(
|
||||||
.background(AttributedStyle.WHITE)
|
AttributedStyle.DEFAULT
|
||||||
.foreground(AttributedStyle.BLACK)
|
.background(AttributedStyle.GREEN)
|
||||||
)
|
.foreground(AttributedStyle.BLACK)
|
||||||
finalAnsiLineBuilder.append(renderedTxt, downpcent, renderedTextWidth)
|
)
|
||||||
|
finalAnsiLineBuilder.append(renderedTxt, 0, downpcent)
|
||||||
|
}
|
||||||
|
if (downpcent < renderedTextWidth) {
|
||||||
|
finalAnsiLineBuilder.style(
|
||||||
|
AttributedStyle.DEFAULT
|
||||||
|
.background(AttributedStyle.WHITE)
|
||||||
|
.foreground(AttributedStyle.BLACK)
|
||||||
|
)
|
||||||
|
finalAnsiLineBuilder.append(renderedTxt, downpcent, renderedTextWidth)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ansiMsg = finalAnsiLineBuilder.toAttributedString()
|
||||||
|
needUpdateTxt = false
|
||||||
|
needRerender = false
|
||||||
}
|
}
|
||||||
ansiMsg = finalAnsiLineBuilder.toAttributedString()
|
|
||||||
needUpdateTxt = false
|
|
||||||
needRerender = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun rerender() {
|
override fun rerender() {
|
||||||
@ -221,7 +224,7 @@ private val terminalDownloadingProgressesNoticer = Object()
|
|||||||
internal var containDownloadingProgress: Boolean = false
|
internal var containDownloadingProgress: Boolean = false
|
||||||
get() = field || terminalDownloadingProgresses.isNotEmpty()
|
get() = field || terminalDownloadingProgresses.isNotEmpty()
|
||||||
|
|
||||||
internal val terminalDownloadingProgresses = mutableListOf<TerminalProcessProgress>()
|
internal val terminalDownloadingProgresses = ConcurrentLinkedQueue<TerminalProcessProgress>()
|
||||||
|
|
||||||
|
|
||||||
internal var downloadingProgressCoroutine: Continuation<Unit>? = null
|
internal var downloadingProgressCoroutine: Continuation<Unit>? = null
|
||||||
@ -254,9 +257,9 @@ internal fun updateTerminalDownloadingProgresses() {
|
|||||||
}
|
}
|
||||||
terminalDisplay.update(listOf(AttributedString.EMPTY), 0, false)
|
terminalDisplay.update(listOf(AttributedString.EMPTY), 0, false)
|
||||||
// Error in idea when more than one bar displaying
|
// 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
|
it.updateTxt(0); it.ansiMsg
|
||||||
}), 0)
|
} ?: AttributedString.EMPTY), 0)
|
||||||
} else {
|
} else {
|
||||||
if (terminalDownloadingProgresses.size > 4) {
|
if (terminalDownloadingProgresses.size > 4) {
|
||||||
// to mush. delete some completed status
|
// to mush. delete some completed status
|
||||||
|
Loading…
Reference in New Issue
Block a user