cuiutil

cuiutil

import "github.com/yuta-yoshinaga/go_trumpcards/internal/adapter/controller/cuiutil"

Index

Constants

NoMax is a sentinel value meaning “no upper bound” for ParseIntArg.

const NoMax = math.MaxInt

NoMin is a sentinel value meaning “no lower bound” for ParseIntArg.

const NoMin = math.MinInt

PromptPrefix is the sentinel prefix indicating a prompt request. When a controller returns a string starting with this prefix, the game loop should prompt the user for the missing argument and re-dispatch the command with the user’s input.

const PromptPrefix = "PROMPT:"

## func FillTemplate

func FillTemplate(template, value string) string

FillTemplate replaces the {0} placeholder in template with value.

## func FormatSkippedWarning

func FormatSkippedWarning(skipped []string) string

FormatSkippedWarning returns a warning string for skipped values. Returns an empty string if skipped is empty.

## func IsPromptRequest

func IsPromptRequest(s string) bool

IsPromptRequest checks if s starts with PromptPrefix.

## func LevenshteinDistance

func LevenshteinDistance(a, b string) int

LevenshteinDistance returns the Levenshtein edit distance between two strings.

## func ParseBoundedIntSlice

func ParseBoundedIntSlice(args []string, min, max int) ([]int, []string)

ParseBoundedIntSlice parses all elements of args as integers within [min, max], returning skipped or out-of-range values.

## func ParseIntArg

func ParseIntArg(args []string, missingMsg, invalidMsg string, min, max int) (int, string, bool)

ParseIntArg parses args[0] as an integer within [min, max]. Returns (value, errMsg, ok). If ok is false, errMsg should be returned to the user. missingMsg is returned when args is empty. invalidMsg is returned when the value is non-numeric or out of range. If invalidMsg contains “%s”, it is formatted with args[0] via fmt.Sprintf. Only a single %s verb is supported; %%s and multiple verbs are not handled.

## func ParseIntSlice

func ParseIntSlice(args []string) ([]int, []string)

ParseIntSlice parses all elements of args as integers, returning skipped values.

## func ParseOptionalInt

func ParseOptionalInt(args []string, idx, defaultVal int) int

ParseOptionalInt parses args[idx] as an integer, returning defaultVal if absent or invalid.

## func ParsePromptRequest

func ParsePromptRequest(s string) (prompt, template string)

ParsePromptRequest extracts the prompt message and command template from a prompt request string. Returns empty strings if malformed.

## func PrependSkippedWarning

func PrependSkippedWarning(result string, skipped []string) string

PrependSkippedWarning prepends a warning to result if skipped is non-empty.

## func PromptRequest

func PromptRequest(promptMsg, commandTemplate string) string

PromptRequest builds a prompt return string. promptMsg is displayed to the user (e.g., “Enter bet amount:”). commandTemplate is the command to re-dispatch, with {0} as a placeholder for the user’s input (e.g., “b {0}”).

## func SuggestCommand

func SuggestCommand(input string, validCommands []string, maxDistance int) string

SuggestCommand returns the closest matching command from validCommands whose edit distance is at most maxDistance. Returns “” if no match is found.

## func WithParsedInt

func WithParsedInt(args []string, missingMsg, invalidMsg string, min, max int, fn func(int) string) (string, bool)

WithParsedInt はParseIntArgの結果を処理するヘルパー。 パース失敗時は (errMsg, true) を返し、成功時は fn(value) の結果を (result, true) で返す。 戻り値の bool は常に true(コマンドが処理済みであることを示す)。

Generated by gomarkdoc