Documentation
¶
Overview ¶
Package procio is the root package for robust process I/O and signaling primitives.
It provides a platform-agnostic way to handle process execution and terminal input with safety guarantees (like leak-free process termination using Job Objects on Windows and Pdeathsig on Linux).
Subpackages ¶
- proc: Process management and lifecycle guarantees.
- scan: Context-aware parsing of input streams (Scanner).
- termio: Terminal I/O utilities and interruptible readers.
Observability ¶
procio does not depend on any logging library. Instead, it exposes an Observer interface that you can implement to bridge logs and metrics to your preferred system.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Version string
Functions ¶
func SetObserver ¶
func SetObserver(o Observer)
SetObserver configures the global observer for process events.
Example ¶
package main
import (
"fmt"
"github.com/aretw0/procio"
)
// MyObserver implements procio.Observer
type MyObserver struct{}
func (o *MyObserver) OnProcessStarted(pid int) { fmt.Printf("Started PID: %d\n", pid) }
func (o *MyObserver) OnProcessFailed(err error) { fmt.Printf("Failed: %v\n", err) }
func (o *MyObserver) OnIOError(op string, err error) { fmt.Printf("IO Error (%s): %v\n", op, err) }
func (o *MyObserver) OnScanError(err error) { fmt.Printf("Scan Error: %v\n", err) }
func (o *MyObserver) LogDebug(msg string, args ...any) {}
func (o *MyObserver) LogWarn(msg string, args ...any) { fmt.Printf("%s\n", msg) }
func (o *MyObserver) LogError(msg string, args ...any) {}
func main() {
// Set a custom observer to receive lifecycle and IO hooks
procio.SetObserver(&MyObserver{})
// Emitting a log to demonstrate (internally used by procio packages)
obs := procio.GetObserver()
obs.LogWarn("Observer configured successfully")
// Reset to default (noop) when done
procio.SetObserver(nil)
}
Output: Observer configured successfully
Types ¶
type Observer ¶
type Observer interface {
OnProcessStarted(pid int)
OnProcessFailed(err error)
OnIOError(op string, err error)
OnScanError(err error)
LogDebug(msg string, args ...any)
LogWarn(msg string, args ...any)
LogError(msg string, args ...any)
}
Observer allows external packages to plug in observability (logs, metrics) without coupling this module to specific implementations.
func GetObserver ¶
func GetObserver() Observer
GetObserver returns the current global observer. Useful for sub-packages to access the shared observer.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
composition
command
|
|
|
interruptible
command
|
|
|
lifecycle_bridge
command
Package main demonstrates how to integrate procio with lifecycle.
|
Package main demonstrates how to integrate procio with lifecycle. |
|
observer
command
|
|
|
pty
command
|
|
|
Package proc provides platform-agnostic process management with safety guarantees.
|
Package proc provides platform-agnostic process management with safety guarantees. |
|
Package pty provides pseudo-terminal (PTY) primitives for running interactive applications within child processes.
|
Package pty provides pseudo-terminal (PTY) primitives for running interactive applications within child processes. |
|
Package scan provides a robust, context-aware command and line scanner.
|
Package scan provides a robust, context-aware command and line scanner. |
|
Package termio provides interruptible I/O primitives and terminal handling.
|
Package termio provides interruptible I/O primitives and terminal handling. |