mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-10-10 16:19:37 +00:00
38 lines
729 B
Kotlin
38 lines
729 B
Kotlin
package gay.pizza.pork.common
|
|
|
|
abstract class IndentTracked(val indent: String) {
|
|
private var internalIndentLevel = 0
|
|
private var indentLevelText = ""
|
|
|
|
val indentLevel: Int
|
|
get() = internalIndentLevel
|
|
|
|
fun emitIndent() {
|
|
emit(indentLevelText)
|
|
}
|
|
|
|
fun emitIndentedLine(line: String) {
|
|
emitIndent()
|
|
emitLine(line)
|
|
}
|
|
|
|
fun increaseIndent() {
|
|
internalIndentLevel++
|
|
indentLevelText += indent
|
|
}
|
|
|
|
fun decreaseIndent() {
|
|
internalIndentLevel--
|
|
indentLevelText = indent.repeat(indentLevel)
|
|
}
|
|
|
|
inline fun indented(block: IndentTracked.() -> Unit) {
|
|
increaseIndent()
|
|
block(this)
|
|
decreaseIndent()
|
|
}
|
|
|
|
abstract fun emit(text: String)
|
|
abstract fun emitLine(text: String)
|
|
}
|