Unified code style

This commit is contained in:
Karlatemp 2020-09-11 20:52:50 +08:00
parent a72fe42aaa
commit a666dc5448
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
3 changed files with 11 additions and 53 deletions

View File

@ -36,10 +36,10 @@ public object ConsolePureSettings {
var noConsole: Boolean = false var noConsole: Boolean = false
@JvmField @JvmField
var noAnsi = false var noAnsi: Boolean = false
@JvmField @JvmField
var noConsoleSafeReading = false var noConsoleSafeReading: Boolean = false
@JvmField @JvmField
var noConsoleReadingReplacement: String = "" var noConsoleReadingReplacement: String = ""

View File

@ -92,8 +92,6 @@ internal val SystemOutputPrintStream by lazy {
private val ANSI_REGEX = """\u001b\[[0-9a-zA-Z;]*?m""".toRegex() private val ANSI_REGEX = """\u001b\[[0-9a-zA-Z;]*?m""".toRegex()
internal object AllEmptyLineReader : LineReader { internal object AllEmptyLineReader : LineReader {
private fun <T> ignored(): T = error("Ignored")
override fun defaultKeyMaps(): MutableMap<String, KeyMap<Binding>> = ignored()
override fun printAbove(str: String?) { override fun printAbove(str: String?) {
if (str == null) return if (str == null) return
@ -107,16 +105,13 @@ internal object AllEmptyLineReader : LineReader {
if (ConsolePureSettings.noConsoleSafeReading) ConsolePureSettings.noConsoleReadingReplacement if (ConsolePureSettings.noConsoleSafeReading) ConsolePureSettings.noConsoleReadingReplacement
else error("Unsupported Reading line when console front-end closed.") else error("Unsupported Reading line when console front-end closed.")
// region
private fun <T> ignored(): T = error("Ignored")
override fun readLine(mask: Char?): String = readLine() override fun readLine(mask: Char?): String = readLine()
override fun readLine(prompt: String?): String = readLine() override fun readLine(prompt: String?): String = readLine()
override fun readLine(prompt: String?, mask: Char?): String = readLine() override fun readLine(prompt: String?, mask: Char?): String = readLine()
override fun readLine(prompt: String?, mask: Char?, buffer: String?): String = readLine() override fun readLine(prompt: String?, mask: Char?, buffer: String?): String = readLine()
override fun readLine(prompt: String?, rightPrompt: String?, mask: Char?, buffer: String?): String = "" override fun readLine(prompt: String?, rightPrompt: String?, mask: Char?, buffer: String?): String = ""
override fun readLine( override fun readLine(
prompt: String?, prompt: String?,
rightPrompt: String?, rightPrompt: String?,
@ -124,83 +119,48 @@ internal object AllEmptyLineReader : LineReader {
buffer: String? buffer: String?
): String = "" ): String = ""
override fun printAbove(str: AttributedString?) { override fun printAbove(str: AttributedString?) {
str?.let { printAbove(it.toAnsi()) } str?.let { printAbove(it.toAnsi()) }
} }
override fun defaultKeyMaps(): MutableMap<String, KeyMap<Binding>> = ignored()
override fun isReading(): Boolean = false override fun isReading(): Boolean = false
override fun variable(name: String?, value: Any?) = this override fun variable(name: String?, value: Any?) = this
override fun option(option: LineReader.Option?, value: Boolean) = this override fun option(option: LineReader.Option?, value: Boolean) = this
override fun callWidget(name: String?) {} override fun callWidget(name: String?) {}
override fun getVariables(): MutableMap<String, Any> = ignored() override fun getVariables(): MutableMap<String, Any> = ignored()
override fun getVariable(name: String?): Any = ignored() override fun getVariable(name: String?): Any = ignored()
override fun setVariable(name: String?, value: Any?) {} override fun setVariable(name: String?, value: Any?) {}
override fun isSet(option: LineReader.Option?): Boolean = ignored() override fun isSet(option: LineReader.Option?): Boolean = ignored()
override fun setOpt(option: LineReader.Option?) {} override fun setOpt(option: LineReader.Option?) {}
override fun unsetOpt(option: LineReader.Option?) {} override fun unsetOpt(option: LineReader.Option?) {}
override fun getTerminal(): Terminal = NoConsole override fun getTerminal(): Terminal = NoConsole
override fun getWidgets(): MutableMap<String, Widget> = ignored() override fun getWidgets(): MutableMap<String, Widget> = ignored()
override fun getBuiltinWidgets(): MutableMap<String, Widget> = ignored() override fun getBuiltinWidgets(): MutableMap<String, Widget> = ignored()
override fun getBuffer(): Buffer = ignored() override fun getBuffer(): Buffer = ignored()
override fun getAppName(): String = "Mirai Console" override fun getAppName(): String = "Mirai Console"
override fun runMacro(macro: String?) {} override fun runMacro(macro: String?) {}
override fun readMouseEvent(): MouseEvent = ignored() override fun readMouseEvent(): MouseEvent = ignored()
override fun getHistory(): History = ignored() override fun getHistory(): History = ignored()
override fun getParser(): Parser = ignored() override fun getParser(): Parser = ignored()
override fun getHighlighter(): Highlighter = ignored() override fun getHighlighter(): Highlighter = ignored()
override fun getExpander(): Expander = ignored() override fun getExpander(): Expander = ignored()
override fun getKeyMaps(): MutableMap<String, KeyMap<Binding>> = ignored() override fun getKeyMaps(): MutableMap<String, KeyMap<Binding>> = ignored()
override fun getKeyMap(): String = ignored() override fun getKeyMap(): String = ignored()
override fun setKeyMap(name: String?): Boolean = ignored() override fun setKeyMap(name: String?): Boolean = ignored()
override fun getKeys(): KeyMap<Binding> = ignored() override fun getKeys(): KeyMap<Binding> = ignored()
override fun getParsedLine(): ParsedLine = ignored() override fun getParsedLine(): ParsedLine = ignored()
override fun getSearchTerm(): String = ignored() override fun getSearchTerm(): String = ignored()
override fun getRegionActive(): LineReader.RegionType = ignored() override fun getRegionActive(): LineReader.RegionType = ignored()
override fun getRegionMark(): Int = ignored() override fun getRegionMark(): Int = ignored()
override fun addCommandsInBuffer(commands: MutableCollection<String>?) {} override fun addCommandsInBuffer(commands: MutableCollection<String>?) {}
override fun editAndAddInBuffer(file: File?) {} override fun editAndAddInBuffer(file: File?) {}
override fun getLastBinding(): String = ignored() override fun getLastBinding(): String = ignored()
override fun getTailTip(): String = ignored() override fun getTailTip(): String = ignored()
override fun setTailTip(tailTip: String?) {} override fun setTailTip(tailTip: String?) {}
override fun setAutosuggestion(type: LineReader.SuggestionType?) {} override fun setAutosuggestion(type: LineReader.SuggestionType?) {}
override fun getAutosuggestion(): LineReader.SuggestionType = ignored() override fun getAutosuggestion(): LineReader.SuggestionType = ignored()
// endregion
} }
internal object NoConsole : AbstractTerminal( internal object NoConsole : AbstractTerminal(
@ -209,11 +169,8 @@ internal object NoConsole : AbstractTerminal(
override fun reader(): NonBlockingReader = NoConsoleNonBlockingReader override fun reader(): NonBlockingReader = NoConsoleNonBlockingReader
private val AllIgnoredPrintWriter = object : PrintWriter(AllIgnoredOutputStream) { private val AllIgnoredPrintWriter = object : PrintWriter(AllIgnoredOutputStream) {
override fun close() { override fun close() {}
} override fun flush() {}
override fun flush() {
}
} }
// We don't need it. Mirai-Console using LineReader to print messages. // We don't need it. Mirai-Console using LineReader to print messages.
@ -222,6 +179,7 @@ internal object NoConsole : AbstractTerminal(
override fun input(): InputStream = AllNextLineInputStream override fun input(): InputStream = AllNextLineInputStream
override fun output(): OutputStream = AllIgnoredOutputStream override fun output(): OutputStream = AllIgnoredOutputStream
private val attributes0 = Attributes() private val attributes0 = Attributes()
override fun getAttributes(): Attributes { override fun getAttributes(): Attributes {
return Attributes(attributes0) return Attributes(attributes0)