From 36c55ab1c7229964ca1f59fa672c8da62352a098 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Tue, 25 Mar 2025 10:47:18 +0300 Subject: [PATCH] Minimal terminal UI --- programs/test/src/linuxX64Main/kotlin/main.kt | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/programs/test/src/linuxX64Main/kotlin/main.kt b/programs/test/src/linuxX64Main/kotlin/main.kt index 3bdea24..5d7a66d 100644 --- a/programs/test/src/linuxX64Main/kotlin/main.kt +++ b/programs/test/src/linuxX64Main/kotlin/main.kt @@ -1,5 +1,7 @@ import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.supervisorScope import ru.landgrafhomyak.bgtu.networks0.icmp.pinger_IPv4 import ru.landgrafhomyak.bgtu.networks0.low_level.multithreading.Thread import ru.landgrafhomyak.bgtu.networks0.low_level.sockets.EpollSocketEventLoop @@ -17,19 +19,35 @@ class EventLoopRoutine(private val loop: EpollSocketEventLoop) : Thread.Routine } } -fun main() { +fun main(argv: Array) { try { EpollSocketEventLoop().use { loop -> Thread(EventLoopRoutine(loop)).use { loopThread -> loopThread.start() - loop.pinger_IPv4("8.8.8.8").use { googleSock -> - - runBlocking { - for (i in 0..10) { - print("google: ${googleSock.ping(1000u)}ms\n") + val values = arrayOfNulls(argv.size) + runBlocking { + launch { + while (true) { + for ((addr, time) in (argv zip values)) { + println(time.toString().padStart(5, ' ') + " ${addr}") + } + print("\u001B[${argv.size}A\r") delay(1000) } } + + supervisorScope { + argv.forEachIndexed { i, addr -> + launch { + loop.pinger_IPv4(addr).use { pinger -> + while (true) { + values[i] = pinger.ping(1000u) + delay(1000) + } + } + } + } + } } } }