engine

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package engine is a small real-time Vim emulator: feed it keystrokes, it mutates buffer/cursor/mode state and reports what happened.

Index

Constants

This section is empty.

Variables

View Source
var GoalTypes = []string{
	"cursorOnWord", "bufferEquals", "lineDeleted",
	"wordDeleted", "containsText", "searchMatchActive",
}

GoalTypes lists every valid Goal.Type, for content validation.

Functions

This section is empty.

Types

type Event

type Event struct {
	Kind EventKind
}

type EventKind

type EventKind int
const (
	EvNone EventKind = iota
	EvMoved
	EvEdited
	EvModeChanged
	EvPending
	EvSearchJumped
	EvInvalid
)

type Goal

type Goal struct {
	Type  string   `json:"type"`
	Word  string   `json:"word,omitempty"`
	Line  string   `json:"line,omitempty"`
	Lines []string `json:"lines,omitempty"`
	Text  string   `json:"text,omitempty"`
	Term  string   `json:"term,omitempty"`
}

Goal is a challenge success condition, decoded straight from lesson JSON.

func (Goal) Met

func (g Goal) Met(s *Simulator) bool

type Mode

type Mode int
const (
	ModeNormal Mode = iota
	ModeInsert
	ModeSearch
)

type Pos

type Pos struct{ Row, Col int }

type Simulator

type Simulator struct {
	Buffer []string
	Cursor Pos
	Mode   Mode

	// AllowedKeys restricts normal-mode commands; nil allows everything.
	AllowedKeys map[string]bool

	SearchQuery string
	// contains filtered or unexported fields
}

func New

func New(lines []string, cursor Pos) *Simulator

func (*Simulator) LastSearch

func (s *Simulator) LastSearch() string

func (*Simulator) Pending

func (s *Simulator) Pending() string

Pending returns the visible pending state ("d", "3", "3d", "di", "g") for the HUD.

func (*Simulator) Press

func (s *Simulator) Press(key string) Event

func (*Simulator) WordAtCursor

func (s *Simulator) WordAtCursor() string

WordAtCursor returns the space-delimited word under the cursor, or "".

Jump to

Keyboard shortcuts

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