userq

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package userq provides User Questions, matching interaction/user-questions. Ask collects selections or custom input through an interchangeable provider. The synchronous test stub returns defaults; production SDKs inject real UI or callbacks. Multi-selection and intent labels keep decision logic independent of the presentation backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// Ask blocks until an answer and returns its result or error.
	Ask(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)
}

Provider is the question backend interface.

type QuestionOptions

type QuestionOptions struct {
	// Prompt is the user-facing question.
	Prompt string
	// Choices lists candidate answers.
	Choices []string
	// DefaultIndex is the default selection; -1 means none.
	DefaultIndex int
	// MultiSelect permits multiple selected indices.
	MultiSelect bool
	// Intent labels the question, such as approval, plan-exit, or goal-blocker.
	Intent string
}

QuestionOptions describes a question and its options.

type QuestionResult

type QuestionResult struct {
	// SelectedIndex is the selected option, or the first in a multi-selection.
	SelectedIndex int
	// Custom contains user-entered custom input.
	Custom string
	// SelectedIndices contains all multi-selected indices.
	SelectedIndices []int
}

QuestionResult contains a response.

type Service

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

Service supports replaceable question providers.

func New

func New(p Provider) *Service

New creates a question service.

func (*Service) Ask

func (s *Service) Ask(ctx context.Context, opts QuestionOptions) (int, string, error)

Ask returns selection index, custom text, and error, matching the upstream signature.

func (*Service) AskDetailed

func (s *Service) AskDetailed(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)

AskDetailed returns the complete response, including multiple indices.

func (*Service) Provider

func (s *Service) Provider() Provider

Provider returns the current provider for assertions.

func (*Service) SetProvider

func (s *Service) SetProvider(p Provider)

SetProvider replaces the provider at runtime for SDK integration.

type StubProvider

type StubProvider struct {
	// DefaultIndex is the default returned selection.
	DefaultIndex int
}

StubProvider returns default selections synchronously for tests.

func NewStub

func NewStub() *StubProvider

NewStub creates a stub defaulting to the first option.

func (*StubProvider) Ask

Ask implements Provider with a default selection and empty custom text.

Jump to

Keyboard shortcuts

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