I have been really enjoying trying out <Mosaic>. I...
# compose
d
I have been really enjoying trying out Mosaic. I have been slowly introducing it into a bot I am making for a game. Super enjoyable so far. I would encourage anyone making a CLI / Bot to give it a go.
🦜 6
🎮 4
I have a MutableStateList for the list of characters and a MutableState containing a LinkedList for the logs.
Copy code
@Composable
fun BotScreen(host: BotHost) {
    Column {
        val characterList = host.playerStateMap()

        HorizontalRule()

        ListCharacters(list = characterList)

        HorizontalRule()

        ListLogs(state = LogController.state)

        HorizontalRule()
    }
}
c
Way coool! I'm trying to convert a few of my lengthy bash scripts to this!
t
This is really cool! How was the experience working with Mosaic and getting everything integrated?
e
This looks so cool! Will definitely try it out!
d
It was bumpy to begin with. I spent an embarrassing amount of time not understanding why the plugin wasn't being found. The dependency was
com.
(in code it was
org.
). Then I had issues with it not updating. It turns out that when the
runMosaic
scope body is at the end, the whole Mosaic system stops. Which makes sense. You just need to keep it running. Which can probably be done by waiting for user input. My bot doesn't accept command line input yet, so it uses a naughty function to keep it going:
Copy code
suspend fun MosaicScope.neverStop() = let { while (true) yield() }

fun main() = runMosaic {
    val host = BotHost(this)

    setContent {
        BotScreen(host = host)
    }

    neverStop()
}
👍🏼 1
🙏 1
Another thing, is that when output wraps a line, it affects every other line. So it is important to keep the line length down. I ended up implementing this:
Copy code
@Composable
fun PaddedText(text: String, maxLength: Int) {
    Text(text.take(maxLength - 1).padEnd(maxLength))
}
e
Nice! @David Edwards. You should consider using
awaitCancellation
instead of the loop (
neverStop
)
d
@efemoney TIL: Thanks for the tip. That works better.