This commit is contained in:
2025-02-05 10:16:25 +03:00
parent 757358fded
commit be9f37a459
6 changed files with 173 additions and 33 deletions

View File

@@ -12,7 +12,7 @@ pub enum NotifyEvent {
}
// NotifyCallback is the function signature for event callbacks
pub type NotifyCallback = fn (event NotifyEvent, path string)
pub type NotifyCallback = fn (event NotifyEvent, path string , args map[string]string)
// WatchEntry represents a watched path and its associated callback
struct WatchEntry {
@@ -28,6 +28,7 @@ pub mut:
name string
watch_list []WatchEntry
is_watching bool
args map[string]string
}
// new creates a new Notifier instance
@@ -84,10 +85,15 @@ pub fn (mut n Notifier) start() ! {
}
n.is_watching = true
if n.watch_list.len>1{
return error("only support watchers with len 1 for now")
}
// Start a watcher for each path
for mut entry in n.watch_list {
go n.watch_path(mut entry)
//spawn n.watch_path(mut entry)
n.watch_path(mut entry)
}
}
@@ -134,7 +140,7 @@ fn (mut n Notifier) watch_path(mut entry WatchEntry) {
}
if cb := entry.callback {
cb(event, path)
cb(event, path,n.args)
}
}
}

View File

@@ -11,17 +11,16 @@ Create a file `screen_example.vsh`:
import freeflowuniverse.herolib.osal.screen
// Create a new screen session with hardcoded parameters
mut s := screen.Screen{
name: 'test_session'
cmd: '/bin/bash' // Default shell
}
// Create a new screen factory
mut sf := screen.new()!
// Check if screen is running
is_running := s.is_running() or {
println('Error checking screen status: ${err}')
return
}
// Add a new screen session
mut s := sf.add(
name: 'myscreen'
cmd: '/bin/bash' // optional, defaults to /bin/bash
start: true // optional, defaults to true
attach: false // optional, defaults to false
)!
// Get session status
status := s.status() or {
@@ -40,6 +39,12 @@ s.attach() or {
println('Error attaching: ${err}')
return
}
// Kill the screen when done
sf.kill('myscreen') or {
println('Error killing screen: ${err}')
return
}
```
## Basic Screen Commands

View File

@@ -7,8 +7,8 @@ import os
import time
@[heap]
struct Screen {
mut:
pub struct Screen {
pub mut:
cmd string
name string
pid int
@@ -16,7 +16,7 @@ mut:
// factory ?&ScreensFactory @[skip; str: skip]
}
enum ScreenState {
pub enum ScreenState {
unknown
detached
}