blob: 3b8a884a9e8f29401224a036c849dad597adc35c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package at.hannibal2.skyhanni.events
import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor
class DebugDataCollectEvent(private val list: MutableList<String>, private val search: String) : LorenzEvent() {
var empty = true
private var currentTitle = ""
private var irrelevant = false
fun title(title: String) {
if (currentTitle != "") error("Title already set: '$currentTitle'")
currentTitle = title
}
fun addIrrelevant(builder: MutableList<String>.() -> Unit) = addIrrelevant(buildList(builder))
fun addIrrelevant(text: String) = addIrrelevant(listOf(text))
fun addIrrelevant(text: List<String>) {
irrelevant = true
addData(text)
}
fun addData(builder: MutableList<String>.() -> Unit) = addData(buildList(builder))
fun addData(text: String) = addData(listOf(text))
fun addData(text: List<String>) {
if (currentTitle == "") error("Title not set")
writeData(text)
currentTitle = ""
irrelevant = false
}
private fun writeData(text: List<String>) {
if (irrelevant && search.isEmpty()) return
if (search.isNotEmpty()) {
if (!search.equalsIgnoreColor("all")) {
if (!currentTitle.contains(search, ignoreCase = true)) {
return
}
}
}
empty = false
list.add("")
list.add("== $currentTitle ==")
for (line in text) {
list.add(" $line")
}
}
}
|