Minimal terminal UI

This commit is contained in:
Andrew Golovashevich 2025-03-25 10:47:18 +03:00
parent af2f50a3b8
commit 36c55ab1c7

View File

@ -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<String>) {
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<UInt>(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)
}
}
}
}
}
}
}
}