Patterns/state Machine

State Machine Pattern pattern for C development

majiayu000 7f35a0d 2 files · 1.4 KB Updated 567 repo stars

File contents

State Machine Pattern

Model system behavior as discrete states with defined transitions. Current state determines which actions are valid and what state comes next.

ikigai Application

Input parser: Tracks escape sequence state (normal, escape, CSI, etc.) to interpret terminal input bytes.

Streaming response: States like idle → requesting → streaming → complete → idle.

Implementation: Enum for states, switch or function pointer table for transitions:

typedef enum { STATE_IDLE, STATE_STREAMING, STATE_ERROR } stream_state_t;

REPL states: Input mode, scrolling mode, command mode.

Benefit: Complex input handling becomes manageable. Each state handles its valid inputs.

majiayu000/claude-skill-registry-data/tree/main/development/patternsstate-machine commit 7f35a0d236

Frequently asked questions

npx skillmds add majiayu000/patterns-state-machine