mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-27 13:48:49 +08:00
Fix pointer and SplitFixed test
* Add DefaultSplitFixed const * Add comments to SplitFixed
This commit is contained in:
parent
b6986c9b4c
commit
c80b59da13
@ -523,7 +523,7 @@ func TestNew(t *testing.T) {
|
|||||||
Bottom(
|
Bottom(
|
||||||
Border(linestyle.Light),
|
Border(linestyle.Light),
|
||||||
),
|
),
|
||||||
SplitPercent(-4),
|
SplitFixed(-2),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -39,13 +39,13 @@ func applyOptions(c *Container, opts ...Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure all the container identifiers are either empty or unique.
|
// ensure all the container identifiers are either empty or unique.
|
||||||
func validateIds(c *Container, seen *(map[string]bool)) error {
|
func validateIds(c *Container, seen map[string]bool) error {
|
||||||
if c.opts.id == "" {
|
if c.opts.id == "" {
|
||||||
return nil
|
return nil
|
||||||
} else if (*seen)[c.opts.id] {
|
} else if seen[c.opts.id] {
|
||||||
return fmt.Errorf("duplicate container ID %q", c.opts.id)
|
return fmt.Errorf("duplicate container ID %q", c.opts.id)
|
||||||
}
|
}
|
||||||
(*seen)[c.opts.id] = true
|
seen[c.opts.id] = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ func validateOptions(c *Container) error {
|
|||||||
var errStr string
|
var errStr string
|
||||||
seenID := map[string]bool{}
|
seenID := map[string]bool{}
|
||||||
preOrder(c, &errStr, func(c *Container) error {
|
preOrder(c, &errStr, func(c *Container) error {
|
||||||
if err := validateIds(c, &seenID); err != nil {
|
if err := validateIds(c, seenID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := validateSplits(c); err != nil {
|
if err := validateSplits(c); err != nil {
|
||||||
@ -192,7 +192,7 @@ func newOptions(parent *options) *options {
|
|||||||
hAlign: align.HorizontalCenter,
|
hAlign: align.HorizontalCenter,
|
||||||
vAlign: align.VerticalMiddle,
|
vAlign: align.VerticalMiddle,
|
||||||
splitPercent: DefaultSplitPercent,
|
splitPercent: DefaultSplitPercent,
|
||||||
splitFixed: -1,
|
splitFixed: DefaultSplitFixed,
|
||||||
}
|
}
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
opts.inherited = parent.inherited
|
opts.inherited = parent.inherited
|
||||||
@ -225,6 +225,9 @@ func (so splitOption) setSplit(opts *options) error {
|
|||||||
// DefaultSplitPercent is the default value for the SplitPercent option.
|
// DefaultSplitPercent is the default value for the SplitPercent option.
|
||||||
const DefaultSplitPercent = 50
|
const DefaultSplitPercent = 50
|
||||||
|
|
||||||
|
// DefaultSplitFixed is the default value for the SplitFixed option.
|
||||||
|
const DefaultSplitFixed = -1
|
||||||
|
|
||||||
// SplitPercent sets the relative size of the split as percentage of the available space.
|
// SplitPercent sets the relative size of the split as percentage of the available space.
|
||||||
// When using SplitVertical, the provided size is applied to the new left
|
// When using SplitVertical, the provided size is applied to the new left
|
||||||
// container, the new right container gets the reminder of the size.
|
// container, the new right container gets the reminder of the size.
|
||||||
@ -243,8 +246,12 @@ func SplitPercent(p int) SplitOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SplitFixed sets the size as a fixed value of the available space.
|
// SplitFixed sets the size as a fixed value of the available space.
|
||||||
// FIXME: More comments
|
// When using SplitVertical, the provided size is applied to the new left
|
||||||
// Allows values greater or equal to zero.
|
// container, the new right container gets the reminder of the size.
|
||||||
|
// When using SplitHorizontal, the provided size is applied to the new top
|
||||||
|
// container, the new bottom container gets the reminder of the size.
|
||||||
|
// The provided value must be a positive number in the range 0 <= cells.
|
||||||
|
// If not provided, defaults to DefaultSplitFixed.
|
||||||
func SplitFixed(cells int) SplitOption {
|
func SplitFixed(cells int) SplitOption {
|
||||||
return splitOption(func(opts *options) error {
|
return splitOption(func(opts *options) error {
|
||||||
if cells < 0 {
|
if cells < 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user