packinglib

package
v0.0.0-...-bd5b4b1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllProperties

func AllProperties() map[Property]string

func SortCategories

func SortCategories(cats []Category)

Types

type Category

type Category string

Category is a name for what kind of thing an item is being packed.

type Context

type Context struct {
	// Name of the context ("The Cape", "The Tiny House", "Firefly")
	Name string

	Nights int

	// TemperatureMin is the anticipated minimum temperature.
	TemperatureMin int

	// TemperatureMax is the anticipated maximum temperature.
	TemperatureMax int

	Properties PropertySet
	// contains filtered or unexported fields
}

Context is struct that holds data about the context of the trip

func NewContext

func NewContext(r Registry, name string, nights, tmin, tmax int, properties []string) (*Context, error)

NewContext creates a new context with the given name, temperature range, and properties. Returns nil if any of the properties is unknown. Properties are optional.

type Item

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

Item

func NewItem

func NewItem(name string, allow, disallow []string) *Item

NewItem creates a Basic Item with the provided allow and disallow property prerequisites.

func (*Item) AdjustCount

func (i *Item) AdjustCount(c *Context)

AdjustCount tells the item to calculate how much of itself is needed given the context and returns the item. Mutators multiply together I guess???

func (*Item) Consumable

func (i *Item) Consumable(rate float64) *Item

func (*Item) Count

func (i *Item) Count() float64

Count returns the number of this item should be packed.

func (*Item) Custom

func (i *Item) Custom(f func(count float64, nights int, props PropertySet) float64) *Item

func (*Item) Max

func (i *Item) Max(max float64) *Item

func (*Item) Name

func (i *Item) Name() string

Name returns the name of the item

func (*Item) Pack

func (i *Item) Pack(p bool)

Pack logs the item as packed.

func (*Item) Packed

func (i *Item) Packed() bool

Packed returns true if the item has been packed

func (*Item) Prerequisites

func (i *Item) Prerequisites() PropertySet

Prerequisites returns the PropertySet of prereqs for this item

func (*Item) Satisfies

func (i *Item) Satisfies(c *Context) bool

Satisfies returns true if the context satisfies the item's requirements.

func (*Item) String

func (i *Item) String() string

String constructs a pretty string for printing this item

func (*Item) TemperatureRange

func (i *Item) TemperatureRange(tMin, tMax int) *Item

func (*Item) Units

func (i *Item) Units(u string) *Item

type ItemList

type ItemList struct {
	Name  string
	Items []*Item
}

type PackList

type PackList map[Category][]*Item

PackList is a map from category name to slice of items

type PackMenuItem

type PackMenuItem struct {
	// Name is the display name with formatting whitespace
	Name string

	// Type determines how the item will be handled
	Type PackMenuType

	// Code is the machine-readable code for determining how the item will be
	// handled.
	Code string
}

PackMenuItem is a struct for each item in a promptui selection

func NewMenuItem

func NewMenuItem(name string, t PackMenuType, code string) PackMenuItem

NewMenuItem creates a new menu item with the given name, type, and code.

func (PackMenuItem) Equals

func (i PackMenuItem) Equals(other PackMenuItem) bool

Equals return true if this menu item equals the other.

type PackMenuType

type PackMenuType int

PackMenuType is a type for items in a promptui selection.

const (
	// MenuCategory is the type for a packing category
	MenuCategory PackMenuType = iota

	// MenuPackable is the type for individual packable items
	MenuPackable

	// MenuProperty is the type for packing properties.
	MenuProperty

	// MenuAction is the type for prompt interaction operations (back, quit, etc)
	MenuAction
)

type Property

type Property string

Property is used to describe an attribute of a context that should be user understandable. Users will choose which properties apply to a given context.

type PropertySet

type PropertySet map[Property]bool

PropertySet is a map holding a list of Properties. A value of true indicates that the Property is allowed. A value of false indicates that the presence of that property is not allowed. Properties are ORed together: Any allowed Property satisfies the item, but any disallowed Property causes the item to reject.

type Registry

type Registry interface {
	ContextList() []string
	AllItems() PackList
	AllProperties() map[Property]string
	GetDescription(p Property) string
	Context(name string) (*Context, error)

	// Not clear how registration should work... probably just "add"
	RegisterContext(c Context)
	RegisterProperty(prop Property, desc string)
	RegisterItems(category Category, items []*Item)
	ListProperties() []Property
	GetContext(name string) (*Context, error)
	GetConcreteContext(name string, nights, tmin, tmax int) (*Context, error)
	HasProperty(p Property) bool
}

ContextRegistry is a generic interface for uhhh doing things with contexts.

func NewStructRegistry

func NewStructRegistry() Registry

type StructRegistry

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

StructRegistry is a simple in-memory impl of a ContextRegistry

func (*StructRegistry) AllItems

func (r *StructRegistry) AllItems() PackList

func (*StructRegistry) AllProperties

func (r *StructRegistry) AllProperties() map[Property]string

func (*StructRegistry) Context

func (r *StructRegistry) Context(name string) (*Context, error)

func (*StructRegistry) ContextList

func (r *StructRegistry) ContextList() []string

ContextList returns a sorted slice of strings of the contexts.

func (*StructRegistry) GetConcreteContext

func (r *StructRegistry) GetConcreteContext(name string, nights, tmin, tmax int) (*Context, error)

GetConcreteContext loads the given context and substitutes the provided temperature range.

func (*StructRegistry) GetContext

func (r *StructRegistry) GetContext(name string) (*Context, error)

GetContext returns the context of the given name, or returns error if not found.

func (*StructRegistry) GetDescription

func (r *StructRegistry) GetDescription(p Property) string

func (*StructRegistry) HasProperty

func (r *StructRegistry) HasProperty(p Property) bool

func (*StructRegistry) ListProperties

func (r *StructRegistry) ListProperties() []Property

ListProperties returns all of the registered properties as a slice of strings.

func (*StructRegistry) RegisterContext

func (r *StructRegistry) RegisterContext(c Context)

RegisterContext registers the given context with the system. Also registers a property with the context name.

func (*StructRegistry) RegisterItems

func (r *StructRegistry) RegisterItems(category Category, items []*Item)

RegisterItems appends the given slice of Items to the registry under the given category. Duplicate categories will be appended. Items with duplicate case-insensitive names, even across categories, cause a panic.

func (*StructRegistry) RegisterProperty

func (r *StructRegistry) RegisterProperty(prop Property, desc string)

RegisterProperty adds a new Property to the database so it can be used. desc should be a user-visible description of the property. Does not verify that all of the properties are in the allProperties map.

type Trip

type Trip struct {
	// list??? XXXX this happens because we build a big context out of little
	// ones... but basically what we should do is give the trip a context and a
	// property list I guess????  right now a trip is just a big context with a
	// bunch of bullshit convenience functions and a list of what is actually
	// packed (which itself is a convenience list).
	C *Context
	// contains filtered or unexported fields
}

XXXXXXXXXXXXXXXX OK the main thing we want to do is make this more of an API -- a trip is a thing we modify and then something about can ask questions about it or make mutations.

Trip describes a trip, which includes a length and a context

func LoadFromCSV

func LoadFromCSV(r Registry, nights int, f string) (*Trip, error)

func LoadFromFile

func LoadFromFile(r Registry, nights int, f string) (*Trip, error)

LoadFromFile initializes the trip from the given file. Old file format: first line: number of nights, context name following lines: true/false string, name of packed item

New file format: first line: "V2", number of nights, tmin, tmax, context name, contexts... if context_name is known, other contexts are added to it.

func LoadFromYAML

func LoadFromYAML(r Registry, nights int, f string) (*Trip, error)

func NewTrip

func NewTrip(registry Registry, nights int, cname string) (*Trip, error)

NewTrip returns a constructed trip for the given named context and number of nights.

func NewTripFromCustomContext

func NewTripFromCustomContext(registry Registry, context *Context) (*Trip, error)

NewTripFromCustomContext returns a constructed trip for the given constructed context and number of nights.

func (*Trip) AddProperty

func (t *Trip) AddProperty(p string) error

func (*Trip) GetItemByCode

func (t *Trip) GetItemByCode(code string) (*Item, bool)

GetItemByCode returns the item with the given code, or false if not found.

func (*Trip) HasProperty

func (t *Trip) HasProperty(p Property) bool

func (*Trip) Pack

func (t *Trip) Pack(i string, pack bool)

Pack tries to pack the provided item first by short code, then by full name.

func (*Trip) PackCategory

func (t *Trip) PackCategory(cat string)

PackCategory packs the entire category.

func (*Trip) PackingMenuItems

func (t *Trip) PackingMenuItems(hiddenCategories map[Category]bool, hidePacked bool) []PackMenuItem

PackingMenuItems returns a list of PackMenuItems for the given trip. Any categories in hiddenCategories will be hidden, and hidePacked will hide all packed items.

func (*Trip) PropertyMenuItems

func (t *Trip) PropertyMenuItems() []PackMenuItem

PropertyMenuItems returns a list of PackMenuItems for the given trip. Any categories in hiddenCategories will be hidden, and hidePacked will hide all packed items.

func (*Trip) RemoveProperty

func (t *Trip) RemoveProperty(p string) error

func (*Trip) SaveToCSV

func (t *Trip) SaveToCSV(f string) error

func (*Trip) SaveToFile

func (t *Trip) SaveToFile(f string) error

SaveToFile saves the trip to the provided filename.

func (*Trip) SaveToYAML

func (t *Trip) SaveToYAML(f string) error

func (*Trip) SortedCategories

func (t *Trip) SortedCategories() []Category

SortedCategories returns a list of all the categories currently represented by the context.

func (*Trip) Strings

func (t *Trip) Strings(showCat string, hideUnpacked bool) []string

Strings returns a slice of pretty strings representing the entire packing list.

func (*Trip) ToggleItemPacked

func (t *Trip) ToggleItemPacked(code string) error

ToggleItemPacked flips the packed state of the given item.

type YamlItem

type YamlItem struct {
	Name     string   `yaml:"name"`
	Units    string   `yaml:"units,omitempty"`
	Allow    []string `yaml:"allow,omitempty"`
	Disallow []string `yaml:"disallowed,omitempty"`

	TempMin        *int     `yaml:"temp_min,omitempty"`
	TempMax        *int     `yaml:"temp_max,omitempty"`
	PerDay         *float64 `yaml:"perday,omitempty"`
	Max            *float64 `yaml:"max,omitempty"`
	CustomFuncName string   `yaml:"custom_func_name,omitempty"`

	Packed *bool `yaml:"packed,omitempty"`
}

func PackItem

func PackItem(i *Item) *YamlItem

PackItem returns an extremely minimal version of YamlItem that only records the name, and whether the item is packed.

type YamlItemList

type YamlItemList struct {
	Name  string     `yaml:"name"`
	Items []YamlItem `yaml:"items"`
}

func (*YamlItemList) AsItemList

func (yl *YamlItemList) AsItemList() (*ItemList, error)

type YamlTrip

type YamlTrip struct {
	Version    int         `yaml:"version"`
	Name       string      `yaml:"name"`
	Nights     int         `yaml:"nights"`
	TempMin    int         `yaml:"temp_min"`
	TempMax    int         `yaml:"temp_max"`
	Properties []string    `yaml:"properties,omitempty"`
	PackList   []*YamlItem `yaml:"pack_list,omitempty"`
}

func FromTrip

func FromTrip(t *Trip) *YamlTrip

func (*YamlTrip) AsTrip

func (yt *YamlTrip) AsTrip(r Registry) (*Trip, error)

Jump to

Keyboard shortcuts

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