mosaic icon indicating copy to clipboard operation
mosaic copied to clipboard

Create `Logger` for output logs to another terminal or file

Open EpicDima opened this issue 11 months ago • 1 comments

Solution for https://github.com/JakeWharton/mosaic/issues/494

Counter with logs
@file:JvmName("Main")

package example

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.jakewharton.mosaic.Logger
import com.jakewharton.mosaic.runMosaicBlocking
import com.jakewharton.mosaic.ui.Text
import kotlin.jvm.JvmName
import kotlinx.coroutines.delay

@Composable
fun Counter() {
	var count by remember { mutableIntStateOf(0) }

	Text("The count is: $count")

	LaunchedEffect(Unit) {
		for (i in 1..20) {
			delay(250)
			Logger.d { "Counter: $i" } // <-- log
			count = i
		}
	}
}

fun main() = runMosaicBlocking {
	Counter()
}
Result Screenshot 2025-01-03 at 03 39 34

The video demo is below in the comments - https://github.com/JakeWharton/mosaic/pull/603#issuecomment-2569228936


  • [x] CHANGELOG.md's "Unreleased" section has been updated, if applicable.

EpicDima avatar Jan 03 '25 00:01 EpicDima

Added this to the demo sample in the TerminalInfo function:

LaunchedEffect(screenSize) {
    Logger.d { "Demo - terminal size: ${screenWidth}x${screenHeight}" }
}
Result (720p compressed video due to 10MB file size limits)

https://github.com/user-attachments/assets/be3c88ec-f38c-4e5b-9130-b23eec5c8724

This is a demo sample with animations that I did not attach in the mosaic-animation pull request (https://github.com/JakeWharton/mosaic/pull/600#issuecomment-2568615904), I am correcting myself here.

EpicDima avatar Jan 03 '25 13:01 EpicDima