Anton Yalyshev [JB]
06/12/2024, 6:18 PM"""...""".trimIndent().replace(Regex("is[A-Z][A-Za-z0-9]*:false\n?"), "").replace("\n", ""
))
• generate additional text in resulting string literals (for loggers, for example)
• perform conditional formatting
• maybe something else
So, in theory, some ceremonies around string processing, could be incapsulated into custom String Templates, and make coding easier.Emil Kantis
06/12/2024, 6:55 PMs
matches template t
)
Could perhaps be used to decorate text with terminal colors, that are only rendered if the string is rendered to a color-capable terminal?
disclaimer: didn't think this through a whole lot, perhaps there's issues with the suggestions 🙂Adam S
06/12/2024, 9:04 PMsam
06/12/2024, 11:18 PMsam
06/12/2024, 11:19 PMOliver.O
06/13/2024, 12:05 AMtest("multi-target update || read") {
tasks(
"""
|<<|A1|B1|a1|b1| |>>|
| | | |<<|a0|b0|a0|b0|>>|
| | | | | | | |<<|a1|b1|>>|
"""
)
}
I agree that clue formatting in Kotest could improve (and I have ideas about how to achieve that). I am actually using Kotest's clues for larger outputs (`DebugTrace`s = object-attached logs). Example in this KotlinConf talk, corresponding repo here.
For easier formatting of test output, I wonder if formatting options like Python's f-strings would help, although we could easily build stuff like this:
val amount = 123.45
val precision = 1
fun Double.f(precision: Int) = "%.${precision}f".format(this)
println("${amount.f(1)}") // 123.5
Does that help?Alex Kuznetsov
06/14/2024, 3:09 PMsam
06/14/2024, 6:25 PMsam
06/14/2024, 6:25 PMAlex Kuznetsov
06/17/2024, 3:24 PMAnton Yalyshev [JB]
06/17/2024, 8:47 PMfun Double.f(precision: Int) = “%.${precision}f”.format(this)yes, that a thing that string_templates could encapsulate. And then, having custom settings, process given strings.
dave08
07/01/2024, 9:59 AMAlexander Ioffe
07/08/2024, 4:22 PMInterpolate("dollar $sign variables")
---
parts: ["dollar ", " variables"]
params: [sign]
The system is also typesafe because you define the type that the params need to be.
https://github.com/deusaquilus/TerpalAlexander Ioffe
07/08/2024, 4:23 PMAlexander Ioffe
07/08/2024, 4:30 PMAnton Yalyshev [JB]
07/08/2024, 4:33 PMAlexander Ioffe
07/08/2024, 4:42 PMNick
07/09/2024, 2:01 AMAlexander Ioffe
07/09/2024, 10:57 AMval text = styledText("${bold("Lorem Ipsum")} is simply ${Yellow("dummy text", target = Background)} of the printing and typesetting industry. It has been the industry's standard dummy text ${decoration("ever since the 1500s")}, when an unknown printer took a galley of type and scrambled it to make a type specimen book.")
It would only be possible on JVM for now but I can eventually change that too.CLOVIS
07/09/2024, 11:20 AMAlexander Ioffe
07/09/2024, 6:34 PMobject Styled: Interpolator<StyledText, StyledText> {
override fun interpolate(parts: () -> List<String>, params: () -> List<StyledText>): StyledText {
var output = StyledText("")
val parts = parts().iterator()
val params = params().iterator()
while (parts.hasNext()) {
output = output..parts.next()
if (params.hasNext()) {
output = output..params.next()
}
}
return output
}
}
Then I could do:
val text = Styled("${bold("Lorem Ipsum")} is simply ${Yellow("dummy text", target = Background)} of the printing and typesetting industry. It has been the industry's standard dummy text ${decoration("ever since the 1500s")}, when an unknown printer took a galley of type and scrambled it to make a type specimen book.")
Alexander Ioffe
07/09/2024, 6:36 PM