malib

package
v0.4.192 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: ISC Imports: 15 Imported by: 0

Documentation

Overview

Package malib provides functions supporting mains package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForPanic

func CheckForPanic(err error) (panicString string)

CheckForPanic returns a non-empty string when err contains a panic

  • the string contains code location for the panic and the recovery

func KeystrokesThread

func KeystrokesThread(silent bool, errorSink parl.ErrorSink1, stdin parl.ClosableSink[string])

keystrokesThread reads blocking from os.Stdin therefore cannot be canceled

  • silent true: nothing is printed on os.Stdin closing
  • silent false: “mains.keystrokesThread standard input closed” may be printed to standard error on os.Stdin closing
  • errorSink present: receives any errors returned by or panic in os.Stdin.Read
  • errorSink nil: errors are printed to standard error
  • stdin receives text lines from standard input with line terminator removed
  • on os.Stdin closing, keystrokesThread closes the stdin line-input channel
  • — the close may be deferred until a key is pressed or the process exits -
  • Because os.Stdin cannot be closed and os.Stdin.Read is blocking:
  • — the thread may blockindfinitiely until process exit
  • — therefore, keystrokesThread is a top-level function not waited upon
  • — purpose is to minimize objects kept in memory until the thread exits
  • on [Keystrokes.CloseNow], keystrokesThread exits on the following keypress
  • StdinReader converts any error to io.EOF
  • parl.Infallible prints any errors to standard error, should not be any
  • -verbose=mains.keystrokesThread

func ProcessStart

func ProcessStart(pid int) (processStart time.Time, err error)

ProcessStart returns start time for process pid with second resolution

func ProcessStartTime

func ProcessStartTime() (createTime time.Time)

ProcessStartTime returns start time for process pid with second resolution

  • panic on troubles

func SystemUpSince

func SystemUpSince() (upSince time.Time, err error)

SystemUpSince returns boot time second resolution

Types

type ErrStore

type ErrStore struct {
	IsFirstLong atomic.Bool
	// contains filtered or unexported fields
}

ErrStore is a slice to distinguish multiple invocations of AddErr

  • must be initialization free
  • must be thread-safe

func (*ErrStore) Add

func (e *ErrStore) Add(err error)

func (*ErrStore) Count

func (e *ErrStore) Count() (count int)

func (*ErrStore) Get

func (e *ErrStore) Get() (errs []error)

func (*ErrStore) GetN

func (e *ErrStore) GetN(index ...int) (err error)

type StdinReader

type StdinReader struct {
	// contains filtered or unexported fields
}

StdinReader is a reader wrapping the unclosable os.Stdin.Read

func NewStdinReader

func NewStdinReader(errorSink parl.ErrorSink1, isError ...*atomic.Bool) (stdinReader *StdinReader)

NewStdinReader returns a error-free reader of standard input that closes on error

  • errorSink pressent: receives any errors returned by os.Stdin.Read or runtime panic in this method.
  • errorSink nil: errors are printed to standard error
  • isError: optional atomic set to true on first error or standard input closing -
  • StdinReader.Read returns bytes read from os.Stdin standard input until close or error
  • os.Stdin.Read is blocking and os.Stdin cannot be closed
  • Therefore, the thread invoking Read may remain until the process exits
  • StdinReader removes all inband errors and panics and only propagates the fact that no more bytes are available via EOF error

func (*StdinReader) Read

func (r *StdinReader) Read(p []byte) (n int, err error)

Read reads from standard input

  • p buffer, max length to read
  • n: the number of bytes read
  • err: Read never returns any other error than io.EOF on error, panic or close
  • — subsequent invocations after first EOF receives EOF -
  • errors and runtime panics are sent to the errorSink or printed to stderr
  • os.Stdin cannot be closed so a blocking StdinReader.Read cannot be canceled
  • the thread invoking Read may remain blocked until process exit
  • if the stdin pipe is closed by another process, Read keeps blocking but returns on the next keypress. Then, an error os.ErrClosed is sent to errorSink and io.EOF is returned
  • on process exit, Read is unblocked as stdin is closed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL