Skip to content

Commit

Permalink
[6.2.0] 调整 StringBar 工具
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Oct 19, 2024
1 parent 338c460 commit 41a840c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions common-util/src/main/kotlin/taboolib/common/util/StringBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package taboolib.common.util
*
* 你还可以使用 builder 参数来进一步自定义每个字符的显示:
* ```
* val coloredBar = buildBarWith("0(#)9", 0.6, 20) { code ->
* val coloredBar = buildBarWith("0(#)9", 0.6, 20) { _, code ->
* when (code) {
* "0", "9" -> code.red()
* "#" -> code.green()
Expand All @@ -34,7 +34,7 @@ package taboolib.common.util
* 默认为 { it },即直接返回原字符
* @return 构建好的 Bar 字符串
*/
fun buildStringBarWith(template: String, value: Double, length: Int, reverse: Boolean = false, builder: (code: String) -> String = { it }): String {
fun buildStringBarWith(template: String, value: Double, length: Int, reverse: Boolean = false, builder: (index: Int, code: String) -> String = { _, code -> code }): String {
val (prefix, body, suffix) = parseTemplate(template)
return buildStringBar(value, length, reverse) { index, state ->
val code = if (state) {
Expand All @@ -49,7 +49,7 @@ fun buildStringBarWith(template: String, value: Double, length: Int, reverse: Bo
} else {
" "
}
builder(code)
builder(index, code)
}
}

Expand Down

0 comments on commit 41a840c

Please sign in to comment.