Documentation
¶
Overview ¶
Package prefs facilitates the storage of preferential values in the Gopher2600 system. It is a key/value system and is quite flexible. The most significant feature is the ability to only specify the preferences you are interested in for a given task. Loading and saving a preference will ignore and preserve values that haven't been added to the "Disk" type.
The Disk type is the key resource in the package. First, create new Disk instance with NewDisk(), specifying the location of the preferences file (using paths.ResourcePath() as necessary).
fn, _ := paths.ResourcePath(prefs.DefaultPrefsFile) prf := prefs.NewDisk(fn)
Preference value can then be added with the Add() function, specifying the "key" value. For clarity, the key value should be similar to the name of the variable as used in the calling code, although this isn't required (note the restrictions on the key value in the documtation for the Add() function).
prf.Add("auto", &auto)
Values that are added to the Disk type must use one of the preference types defined in this package. Currently, there are Bool, String and Int types. There is also a Generic type, that allows the Set() and Get() functions to be defined.
Once added to the disk object, preference values can be changed in the program in the normal way. Changes can be committed to disk wit the Disk.Save() function and restoried with Disk.Load().
Note ¶
While saved preference files are stored in UTF-8 it is not a good idea for the files to be edited by hand. As such, manual editing is discorouaged with the warning at the top of the file:
*** do not edit this file by hand ***
This also serves as the means of identification for the Load() function. ie. if this warning is not present then the Load() operation will fail.
Index ¶
Constants ¶
const DefaultPrefsFile = "preferences"
DefaultPrefsFile is the default filename of the global preferences file
const WarningBoilerPlate = "*** do not edit this file by hand ***"
WarningBoilerPlate is inserted at the beginning of a preferences file
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool implements a boolean type in the prefs system.
type Disk ¶
type Disk struct {
// contains filtered or unexported fields
}
Disk represents preference values as stored on disk.
type Generic ¶
type Generic struct {
// contains filtered or unexported fields
}
Generic is a general purpose prefererences type, useful for values that cannot be represented by a single live value. You must use the NewGeneric() function to initialise a new instance of Generic.
func NewGeneric ¶
NewGeneric is the preferred method of initialisation for the Generic type.
func (Generic) Get ¶
func (p Generic) Get() interface{}
Get triggers the get value procedure for the generic type.
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int implements a string type in the prefs system.