Documentation
¶
Index ¶
- func AllProperties() map[Property]string
- func SortCategories(cats []Category)
- type Category
- type Context
- type Item
- func (i *Item) AdjustCount(c *Context)
- func (i *Item) Consumable(rate float64) *Item
- func (i *Item) Count() float64
- func (i *Item) Custom(f func(count float64, nights int, props PropertySet) float64) *Item
- func (i *Item) Max(max float64) *Item
- func (i *Item) Name() string
- func (i *Item) Pack(p bool)
- func (i *Item) Packed() bool
- func (i *Item) Prerequisites() PropertySet
- func (i *Item) Satisfies(c *Context) bool
- func (i *Item) String() string
- func (i *Item) TemperatureRange(tMin, tMax int) *Item
- func (i *Item) Units(u string) *Item
- type ItemList
- type PackList
- type PackMenuItem
- type PackMenuType
- type Property
- type PropertySet
- type Registry
- type StructRegistry
- func (r *StructRegistry) AllItems() PackList
- func (r *StructRegistry) AllProperties() map[Property]string
- func (r *StructRegistry) Context(name string) (*Context, error)
- func (r *StructRegistry) ContextList() []string
- func (r *StructRegistry) GetConcreteContext(name string, nights, tmin, tmax int) (*Context, error)
- func (r *StructRegistry) GetContext(name string) (*Context, error)
- func (r *StructRegistry) GetDescription(p Property) string
- func (r *StructRegistry) HasProperty(p Property) bool
- func (r *StructRegistry) ListProperties() []Property
- func (r *StructRegistry) RegisterContext(c Context)
- func (r *StructRegistry) RegisterItems(category Category, items []*Item)
- func (r *StructRegistry) RegisterProperty(prop Property, desc string)
- type Trip
- func LoadFromCSV(r Registry, nights int, f string) (*Trip, error)
- func LoadFromFile(r Registry, nights int, f string) (*Trip, error)
- func LoadFromYAML(r Registry, nights int, f string) (*Trip, error)
- func NewTrip(registry Registry, nights int, cname string) (*Trip, error)
- func NewTripFromCustomContext(registry Registry, context *Context) (*Trip, error)
- func (t *Trip) AddProperty(p string) error
- func (t *Trip) GetItemByCode(code string) (*Item, bool)
- func (t *Trip) HasProperty(p Property) bool
- func (t *Trip) Pack(i string, pack bool)
- func (t *Trip) PackCategory(cat string)
- func (t *Trip) PackingMenuItems(hiddenCategories map[Category]bool, hidePacked bool) []PackMenuItem
- func (t *Trip) PropertyMenuItems() []PackMenuItem
- func (t *Trip) RemoveProperty(p string) error
- func (t *Trip) SaveToCSV(f string) error
- func (t *Trip) SaveToFile(f string) error
- func (t *Trip) SaveToYAML(f string) error
- func (t *Trip) SortedCategories() []Category
- func (t *Trip) Strings(showCat string, hideUnpacked bool) []string
- func (t *Trip) ToggleItemPacked(code string) error
- type YamlItem
- type YamlItemList
- type YamlTrip
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllProperties ¶
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
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item
func NewItem ¶
NewItem creates a Basic Item with the provided allow and disallow property prerequisites.
func (*Item) AdjustCount ¶
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 (*Item) Prerequisites ¶
func (i *Item) Prerequisites() PropertySet
Prerequisites returns the PropertySet of prereqs for this item
func (*Item) TemperatureRange ¶
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 ¶
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) 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 LoadFromFile ¶
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 NewTripFromCustomContext ¶
NewTripFromCustomContext returns a constructed trip for the given constructed context and number of nights.
func (*Trip) AddProperty ¶
func (*Trip) GetItemByCode ¶
GetItemByCode returns the item with the given code, or false if not found.
func (*Trip) HasProperty ¶
func (*Trip) PackCategory ¶
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 (*Trip) SaveToFile ¶
SaveToFile saves the trip to the provided filename.
func (*Trip) SaveToYAML ¶
func (*Trip) SortedCategories ¶
SortedCategories returns a list of all the categories currently represented by the context.
func (*Trip) Strings ¶
Strings returns a slice of pretty strings representing the entire packing list.
func (*Trip) ToggleItemPacked ¶
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"`
}
type YamlItemList ¶
func (*YamlItemList) AsItemList ¶
func (yl *YamlItemList) AsItemList() (*ItemList, error)