engine

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 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", "commandRun",
}

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"`
	Command string   `json:"command,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
	ModeCmdline
	ModeVisual
	ModeVisualBlock
)

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

	CmdQuery string // the command being typed after :

	VisualAnchor Pos // where v was pressed; the selection's fixed end

	BlockAnchor Pos // where ctrl+v was pressed; the block's fixed corner
	// contains filtered or unexported fields
}

func New

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

func (*Simulator) BlockSelection added in v1.0.0

func (s *Simulator) BlockSelection() (r0, r1, c0, c1 int)

BlockSelection exposes the rectangle's inclusive bounds for rendering.

func (*Simulator) LastCommand added in v1.0.0

func (s *Simulator) LastCommand() string

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) Recording added in v1.0.0

func (s *Simulator) Recording() bool

Recording reports whether a macro is being recorded (for the HUD).

func (*Simulator) Selection added in v1.0.0

func (s *Simulator) Selection() (Pos, Pos)

Selection returns the visual range ordered start ≤ end (inclusive).

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