{"id":13625045,"url":"https://github.com/JakeWharton/mosaic","last_synced_at":"2025-04-16T06:31:35.939Z","repository":{"id":37753480,"uuid":"292637686","full_name":"JakeWharton/mosaic","owner":"JakeWharton","description":"Build terminal UI in Kotlin using Jetpack Compose","archived":false,"fork":false,"pushed_at":"2024-10-31T01:51:52.000Z","size":5159,"stargazers_count":1916,"open_issues_count":28,"forks_count":57,"subscribers_count":27,"default_branch":"trunk","last_synced_at":"2024-10-31T02:23:57.546Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JakeWharton.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-09-03T17:34:46.000Z","updated_at":"2024-10-29T13:08:18.000Z","dependencies_parsed_at":"2023-10-16T13:16:26.237Z","dependency_job_id":"c52cd725-c224-4702-bf7b-9dd9db7030a7","html_url":"https://github.com/JakeWharton/mosaic","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakeWharton%2Fmosaic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakeWharton%2Fmosaic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakeWharton%2Fmosaic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakeWharton%2Fmosaic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JakeWharton","download_url":"https://codeload.github.com/JakeWharton/mosaic/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223700197,"owners_count":17188266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:01:50.215Z","updated_at":"2025-04-16T06:31:35.930Z","avatar_url":"https://github.com/JakeWharton.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Mosaic\n\nAn experimental tool for building console UI in Kotlin using the Jetpack Compose compiler/runtime.\nInspired by [Ink](https://github.com/vadimdemedes/ink).\n\n\u003cimg src=\"samples/jest/demo.gif\"\u003e\n\nJump to:\n[Introduction](#Introduction) |\n[Usage](#Usage) |\n[Samples](#Samples) |\n[FAQ](#FAQ) |\n[License](#License)\n\n\n## Introduction\n\nThe entrypoint to Mosaic is the `runMosaic` function.\nThe lambda passed to this function is responsible for both output and performing work.\n\n```kotlin\nsuspend fun main() = runMosaic {\n  Text(\"The count is: 0\")\n}\n```\n\nTo change the output dynamically we can use local properties to hold state.\nLet's update our counter to actually count to 20.\n\n```kotlin\nsuspend fun main() = runMosaic {\n  var count by remember { mutableIntStateOf(0) }\n\n  Text(\"The count is: $count\")\n\n  LaunchedEffect(Unit) {\n    for (i in 1..20) {\n      delay(250)\n      count = i\n    }\n  }\n}\n```\n\n(Note: You may need to add imports for `androidx.compose.runtime.getValue` and `import androidx.compose.runtime.setValue` manually.)\n\n\u003cimg src=\"samples/counter/demo.gif\"\u003e\n\nThat is the most basic sample of Mosaic.\nFrom there, the limit is only your imagination.\n\n\u003cimg src=\"samples/jest/demo.gif\"\u003e\n\n\u003cimg src=\"samples/rrtop/demo.gif\"\u003e\n\n_(Note: graphs in the above have rendering problems due to asciinema/agg which do not appear in the real output)_\n\n## Usage\n\nMosaic is a library for Compose, and it relies on JetBrains' Kotlin Compose plugin to be present for use.\nAny module which wants to call `runMosaic` or define `@Composable` functions for use with Mosaic must have this plugin applied.\nFor more information, see [the JetBrains Compose compiler documentation](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compiler.html).\n\nMosaic itself can then be added like any other dependency:\n\n```groovy\ndependencies {\n  implementation(\"com.jakewharton.mosaic:mosaic-runtime:0.17.0\")\n}\n```\n\nDocumentation is available at [jakewharton.github.io/mosaic/docs/0.x/](https://jakewharton.github.io/mosaic/docs/0.x/).\n\n\u003cdetails\u003e\n\u003csummary\u003eSnapshots of the development version are available in Sonatype's snapshots repository.\u003c/summary\u003e\n\u003cp\u003e\n\n```groovy\nrepository {\n  mavenCentral()\n  maven {\n    url 'https://oss.sonatype.org/content/repositories/snapshots/'\n  }\n}\ndependencies {\n  implementation(\"com.jakewharton.mosaic:mosaic-runtime:0.18.0-SNAPSHOT\")\n}\n```\n\nSnapshot documentation is available at [jakewharton.github.io/mosaic/docs/latest/](https://jakewharton.github.io/mosaic/docs/latest/).\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n\n## Samples\n\nRun `./gradlew installDist` to build the sample binaries.\n\n * [Counter](samples/counter): A simple increasing number from 0 until 20.\n\n   `./samples/counter/build/install/counter/bin/counter`\n\n * [Demo](samples/demo): A playground for demonstrating many features of Mosaic.\n\n   `./samples/demo/build/install/demo/bin/demo`\n\n * [Jest](samples/jest): Example output of a test framework (such as JS's 'Jest').\n\n   `./samples/jest/build/install/jest/bin/jest`\n\n * [Robot](samples/robot): An interactive, game-like program with keyboard control.\n\n   `./samples/robot/build/install/robot/bin/robot`\n\n * [rrtop](samples/rrtop): An example inspired by [rrtop](https://github.com/wojciech-zurek/rrtop).\n\n   `./samples/rrtop/build/install/rrtop/bin/rrtop`\n\n * [snake](samples/snake): Snake game.\n\n   `./samples/snake/build/install/snake/bin/snake`\n\n## FAQ\n\n### I thought Jetpack Compose was a UI toolkit for Android?\n\nCompose is, at its core, a general-purpose runtime and compiler for tree and property manipulation\nwhich is trapped inside the AndroidX monorepo and under the Jetpack marketing department. This\ncore can be used for _any_ tree on _any_ platform supported by Kotlin. It's an amazing piece of\ntechnology.\n\nCompose UI is the new UI toolkit for Android (and maybe [Desktop](https://www.jetbrains.com/lp/compose/)?).\nThe lack of differentiation between these two technologies has unfortunately caused Compose UI to\novershadow the core under the single \"Compose\" moniker in an unforced marketing error.\n\nIf you want another example of a non-Compose UI-based Compose project checkout JetBrains' [Compose for Web](https://blog.jetbrains.com/kotlin/2021/05/technology-preview-jetpack-compose-for-web/) project.\n\n### Output repeats with `./gradlew run` and/or inside IntelliJ IDEA\n\nRunning within Gradle or IntelliJ IDEA will not work. Both tools strip ANSI control characters,\nwhich prevent Mosaic from redrawing over a previous frame. The output will likely just render in\nsuccessive lines instead.\n\nIn the future Mosaic will detect this case and do... something. For now, we unconditionally emit\nANSI control characters. Run your programs directly in a terminal emulator–no IDE and no Gradle.\n\n\n# License\n\n    Copyright 2020 Jake Wharton\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJakeWharton%2Fmosaic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJakeWharton%2Fmosaic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJakeWharton%2Fmosaic/lists"}