KDoc; Adjust the order of property

This commit is contained in:
Karlatemp 2020-11-08 10:32:18 +08:00
parent 81aa60fe5d
commit cce3749661
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 36 additions and 10 deletions

View File

@ -91,6 +91,17 @@ public interface MiraiConsole : CoroutineScope {
@ConsoleExperimentalApi
public fun createLogger(identity: String?): MiraiLogger
/**
* 是否支持使用 Ansi 输出彩色信息
*
* : 不是每个前端都可能提供 `org.fusesource.jansi:jansi` 库支持,
* 请不要直接使用 `org.fusesource.jansi:jansi`
*
* @see [AnsiMessageBuilder]
*/
@ConsoleExperimentalApi
public val isAnsiSupported: Boolean
public companion object INSTANCE : MiraiConsole by MiraiConsoleImplementationBridge {
/**
* 获取 [MiraiConsole] [Job]
@ -154,16 +165,6 @@ public interface MiraiConsole : CoroutineScope {
}
/**
* 是否支持使用 Ansi 输出彩色信息
*
* : 不是每个前端都可能提供 `org.fusesource.jansi:jansi` 库支持,
* 请不要直接使用 `org.fusesource.jansi:jansi`
*
* @see [AnsiMessageBuilder]
*/
@ConsoleExperimentalApi
public val isAnsiSupported: Boolean
}
/**

View File

@ -83,6 +83,9 @@ public open class AnsiMessageBuilder internal constructor(
public companion object {
private val DROP_ANSI_PATTERN = """\u001b\[([0-9]+)(;[0-9]+)*m""".toRegex()
/**
* [String] 中剔除 ansi 控制符
*/
@JvmStatic
public fun String.dropAnsi(): String = DROP_ANSI_PATTERN.replace(this, "")
@ -107,6 +110,9 @@ public open class AnsiMessageBuilder internal constructor(
noAnsi: Boolean = false
): AnsiMessageBuilder = invoke(StringBuilder(capacity), noAnsi)
/**
* 判断 [sender] 是否支持带 ansi 控制符的正确显示
*/
@ConsoleExperimentalApi
@JvmStatic
public fun isAnsiSupported(sender: CommandSender): Boolean =
@ -114,6 +120,9 @@ public open class AnsiMessageBuilder internal constructor(
MiraiConsoleImplementationBridge.isAnsiSupported
} else false
/**
* [StringBuilder] 追加 ansi 控制符
*/
public inline fun StringBuilder.appendAnsi(
noAnsi: Boolean = false,
action: AnsiMessageBuilder.() -> Unit
@ -172,12 +181,23 @@ public open class AnsiMessageBuilder internal constructor(
/////////////////////////////////////////////////////////////////////////////////
}
/**
* 构建一条 ansi 信息
*
* @see [AnsiMessageBuilder]
*/
public inline fun buildAnsiMessage(
capacity: Int = 16,
action: AnsiMessageBuilder.() -> Unit
): String = AnsiMessageBuilder(capacity, false).apply(action).toString()
// 不在 top-level 使用者会得到 Internal error: Couldn't inline sendAnsiMessage
/**
* [CommandSender] 发送一条带有 ansi 控制符的信息
*
* @see [AnsiMessageBuilder]
*/
public suspend inline fun CommandSender.sendAnsiMessage(
capacity: Int = 16,
builder: AnsiMessageBuilder.() -> Unit
@ -189,6 +209,11 @@ public suspend inline fun CommandSender.sendAnsiMessage(
)
}
/**
* [CommandSender] 发送一条带有 ansi 控制符的信息
*
* @see [AnsiMessageBuilder.Companion.dropAnsi]
*/
public suspend inline fun CommandSender.sendAnsiMessage(message: String) {
sendMessage(
if (AnsiMessageBuilder.isAnsiSupported(this))