feat: add fswatch, sysinfo, and udp demo scripts plus reorder manual sidebar links

Add three new example scripts demonstrating the fswatch, sysinfo, and udp modules with file watching, system metrics, and UDP echo server/client patterns. Reorder the manual API sidebar navigation to list modules alphabetically, removing deprecated entries like websocket, tls, net, json, regex, jinja, os, signal, subprocess, sqlite, and timer while adding argparse, dataset, fswatch, and html.
This commit is contained in:
2026-01-25 12:09:28 +00:00
parent d487109d7c
commit 819bbd5091
72 changed files with 4332 additions and 643 deletions
+34
View File
@@ -0,0 +1,34 @@
// retoor <retoor@molodetz.nl>
import "fswatch" for FileWatcher, FsEvent
import "timer" for Timer
import "io" for File, FileFlags
var testFile = "/tmp/fswatch_test_%(Num.fromString("%(System.clock)".split(".")[1])).txt"
var f = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.create | FileFlags.truncate)
f.writeBytes("initial", 0)
f.close()
var watcher = FileWatcher.new(testFile)
var received = []
watcher.start { |event|
received.add(event)
}
System.print(watcher.isActive) // expect: true
Timer.immediate {
var f2 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
f2.writeBytes("modified", 0)
f2.close()
}
Timer.sleep(100)
System.print(received.count > 0) // expect: true
System.print(received[0] is FsEvent) // expect: true
watcher.stop()
System.print(watcher.isActive) // expect: false
+17
View File
@@ -0,0 +1,17 @@
// retoor <retoor@molodetz.nl>
import "io" for File
var srcFile = "/tmp/test_copy_src.txt"
var dstFile = "/tmp/test_copy_dst.txt"
var content = "Copy me!"
File.write(srcFile, content)
File.copy(srcFile, dstFile)
System.print(File.exists(dstFile)) // expect: true
System.print(File.read(dstFile) == content) // expect: true
File.delete(srcFile)
File.delete(dstFile)
+17
View File
@@ -0,0 +1,17 @@
// retoor <retoor@molodetz.nl>
import "io" for File
var srcFile = "/tmp/test_move_src.txt"
var dstFile = "/tmp/test_move_dst.txt"
var content = "Move me!"
File.write(srcFile, content)
File.move(srcFile, dstFile)
System.print(File.exists(srcFile)) // expect: false
System.print(File.exists(dstFile)) // expect: true
System.print(File.read(dstFile) == content) // expect: true
File.delete(dstFile)
+13
View File
@@ -0,0 +1,13 @@
// retoor <retoor@molodetz.nl>
import "io" for File
var testFile = "/tmp/test_write_static.txt"
var content = "Hello, World!"
File.write(testFile, content)
var read = File.read(testFile)
System.print(read == content) // expect: true
File.delete(testFile)
+13
View File
@@ -0,0 +1,13 @@
// retoor <retoor@molodetz.nl>
import "io" for Stdin
var size = Stdin.windowSize
System.print(size == null || size is List) // expect: true
if (size != null) {
System.print(size.count == 2)
System.print(size[0] > 0)
System.print(size[1] > 0)
}
+12
View File
@@ -0,0 +1,12 @@
// retoor <retoor@molodetz.nl>
import "pathlib" for Path
var testFile = Path.new("/tmp/test_pathlib_size.txt")
var content = "12345678"
testFile.writeText(content)
var size = testFile.size()
System.print(size) // expect: 8
testFile.unlink()
+19
View File
@@ -0,0 +1,19 @@
// retoor <retoor@molodetz.nl>
import "pathlib" for Path
var testFile = Path.new("/tmp/test_pathlib_stat_times.txt")
testFile.writeText("test content")
var mtime = testFile.mtime()
var atime = testFile.atime()
var ctime = testFile.ctime()
System.print(mtime is Num) // expect: true
System.print(atime is Num) // expect: true
System.print(ctime is Num) // expect: true
System.print(mtime > 0) // expect: true
System.print(atime > 0) // expect: true
System.print(ctime > 0) // expect: true
testFile.unlink()
+7
View File
@@ -0,0 +1,7 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var count = SysInfo.cpuCount
System.print(count is Num) // expect: true
System.print(count > 0) // expect: true
+19
View File
@@ -0,0 +1,19 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var cpus = SysInfo.cpuInfo
System.print(cpus is List) // expect: true
System.print(cpus.count > 0) // expect: true
var cpu = cpus[0]
System.print(cpu is Map) // expect: true
System.print(cpu.containsKey("model")) // expect: true
System.print(cpu.containsKey("speed")) // expect: true
System.print(cpu.containsKey("times")) // expect: true
var times = cpu["times"]
System.print(times is Map) // expect: true
System.print(times.containsKey("user")) // expect: true
System.print(times.containsKey("sys")) // expect: true
System.print(times.containsKey("idle")) // expect: true
+7
View File
@@ -0,0 +1,7 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var hostname = SysInfo.hostname
System.print(hostname is String) // expect: true
System.print(hostname.count > 0) // expect: true
+9
View File
@@ -0,0 +1,9 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var t1 = SysInfo.hrtime
var t2 = SysInfo.hrtime
System.print(t1 is Num) // expect: true
System.print(t2 is Num) // expect: true
System.print(t2 >= t1) // expect: true
+10
View File
@@ -0,0 +1,10 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var load = SysInfo.loadAverage
System.print(load is List) // expect: true
System.print(load.count) // expect: 3
System.print(load[0] is Num) // expect: true
System.print(load[1] is Num) // expect: true
System.print(load[2] is Num) // expect: true
+16
View File
@@ -0,0 +1,16 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var total = SysInfo.totalMemory
var free = SysInfo.freeMemory
var resident = SysInfo.residentMemory
System.print(total is Num) // expect: true
System.print(free is Num) // expect: true
System.print(resident is Num) // expect: true
System.print(total > 0) // expect: true
System.print(free > 0) // expect: true
System.print(resident > 0) // expect: true
System.print(total >= free) // expect: true
+23
View File
@@ -0,0 +1,23 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var interfaces = SysInfo.networkInterfaces
System.print(interfaces is Map) // expect: true
System.print(interfaces.count > 0) // expect: true
for (name in interfaces.keys) {
var addrs = interfaces[name]
System.print(addrs is List) // expect: true
for (addr in addrs) {
System.print(addr is Map) // expect: true
System.print(addr.containsKey("family")) // expect: true
System.print(addr.containsKey("address")) // expect: true
System.print(addr.containsKey("internal")) // expect: true
System.print(addr.containsKey("netmask")) // expect: true
System.print(addr.containsKey("mac")) // expect: true
break
}
break
}
+7
View File
@@ -0,0 +1,7 @@
// retoor <retoor@molodetz.nl>
import "sysinfo" for SysInfo
var uptime = SysInfo.uptime
System.print(uptime is Num) // expect: true
System.print(uptime > 0) // expect: true
+15
View File
@@ -0,0 +1,15 @@
// retoor <retoor@molodetz.nl>
import "timer" for Timer
var called = false
Timer.immediate {
called = true
}
System.print(called) // expect: false
Timer.sleep(1)
System.print(called) // expect: true
+20
View File
@@ -0,0 +1,20 @@
// retoor <retoor@molodetz.nl>
import "timer" for Timer, TimerHandle
var count = 0
var handle = Timer.interval(1) {
count = count + 1
}
System.print(handle is TimerHandle) // expect: true
System.print(handle.isActive) // expect: true
Timer.sleep(100)
handle.stop()
System.print(count > 0) // expect: true
System.print(handle.isActive) // expect: false
System.print(count) // nontest
+6
View File
@@ -0,0 +1,6 @@
// retoor <retoor@molodetz.nl>
import "timer" for Timer
Timer.sleep(10)
System.print("after sleep") // expect: after sleep
+11
View File
@@ -0,0 +1,11 @@
// retoor <retoor@molodetz.nl>
import "udp" for UdpSocket
var socket = UdpSocket.new()
socket.bind("127.0.0.1", 0)
System.print(socket.localAddress) // expect: 127.0.0.1
System.print(socket.localPort > 0) // expect: true
socket.close()
+9
View File
@@ -0,0 +1,9 @@
// retoor <retoor@molodetz.nl>
import "udp" for UdpSocket
var socket = UdpSocket.new()
socket.bind("0.0.0.0", 0)
socket.setBroadcast(true)
System.print("broadcast enabled") // expect: broadcast enabled
socket.close()
+30
View File
@@ -0,0 +1,30 @@
// retoor <retoor@molodetz.nl>
import "udp" for UdpSocket
import "timer" for Timer
import "scheduler" for Scheduler
var server = UdpSocket.new()
server.bind("127.0.0.1", 0)
var serverPort = server.localPort
var received = null
Scheduler.add {
received = server.receive()
server.close()
}
var client = UdpSocket.new()
client.bind("127.0.0.1", 0)
Timer.immediate {
client.send("test", "127.0.0.1", serverPort)
client.close()
}
Timer.sleep(100)
System.print(received != null) // expect: true
System.print(received[0]) // expect: test
System.print(received[1]) // expect: 127.0.0.1