mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-27 13:48:49 +08:00
Merge branch 'devel' into 243-formdemo
This commit is contained in:
commit
37f7af1cc0
@ -28,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
func (*BarChart) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error { ... }
|
func (*BarChart) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error { ... }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- `termdash` no longer crashes when `tcell` is used and the terminal window
|
||||||
|
downsizes while content is being drawn.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
#### Infrastructure changes
|
#### Infrastructure changes
|
||||||
@ -38,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- containers can register into separate focus groups and specific keyboard keys
|
- containers can register into separate focus groups and specific keyboard keys
|
||||||
can be configured to move the focus within each focus group.
|
can be configured to move the focus within each focus group.
|
||||||
- widgets can now request keyboard events exclusively when focused.
|
- widgets can now request keyboard events exclusively when focused.
|
||||||
|
- users can now set a `container` as focused using the new `container.Focused`
|
||||||
|
option.
|
||||||
|
|
||||||
#### Updates to the `button` widget
|
#### Updates to the `button` widget
|
||||||
|
|
||||||
|
@ -541,7 +541,7 @@ func TestFocusTrackerNextAndPrevious(t *testing.T) {
|
|||||||
wantProcessed int
|
wantProcessed int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "initially the root is focused",
|
desc: "initially the root is focused by default",
|
||||||
container: func(ft *faketerm.Terminal) (*Container, error) {
|
container: func(ft *faketerm.Terminal) (*Container, error) {
|
||||||
return New(
|
return New(
|
||||||
ft,
|
ft,
|
||||||
@ -554,6 +554,49 @@ func TestFocusTrackerNextAndPrevious(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantFocused: contLocA,
|
wantFocused: contLocA,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "focus root explicitly",
|
||||||
|
container: func(ft *faketerm.Terminal) (*Container, error) {
|
||||||
|
return New(
|
||||||
|
ft,
|
||||||
|
Focused(),
|
||||||
|
SplitVertical(
|
||||||
|
Left(),
|
||||||
|
Right(),
|
||||||
|
),
|
||||||
|
KeyFocusNext(keyNext),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
wantFocused: contLocA,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "focus can be set to a container other than root",
|
||||||
|
container: func(ft *faketerm.Terminal) (*Container, error) {
|
||||||
|
return New(
|
||||||
|
ft,
|
||||||
|
SplitVertical(
|
||||||
|
Left(Focused()),
|
||||||
|
Right(),
|
||||||
|
),
|
||||||
|
KeyFocusNext(keyNext),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
wantFocused: contLocB,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "option Focused used on multiple containers, the last one takes effect",
|
||||||
|
container: func(ft *faketerm.Terminal) (*Container, error) {
|
||||||
|
return New(
|
||||||
|
ft,
|
||||||
|
SplitVertical(
|
||||||
|
Left(Focused()),
|
||||||
|
Right(Focused()),
|
||||||
|
),
|
||||||
|
KeyFocusNext(keyNext),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
wantFocused: contLocC,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "keyNext does nothing when only root exists",
|
desc: "keyNext does nothing when only root exists",
|
||||||
container: func(ft *faketerm.Terminal) (*Container, error) {
|
container: func(ft *faketerm.Terminal) (*Container, error) {
|
||||||
|
@ -1033,3 +1033,14 @@ func KeyFocusGroupsPrevious(key keyboard.Key, groups ...FocusGroup) Option {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Focused moves the keyboard focus to this container.
|
||||||
|
// If not specified, termdash will start with the root container focused.
|
||||||
|
// If specified on multiple containers, the last container with this option
|
||||||
|
// will be focused.
|
||||||
|
func Focused() Option {
|
||||||
|
return option(func(c *Container) error {
|
||||||
|
c.focusTracker.setActive(c)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -195,21 +195,14 @@ func (c *Canvas) copyTo(offset image.Point, dstSetCell setCellFunc) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply applies the canvas to the corresponding area of the terminal.
|
// Apply applies the canvas to the corresponding area of the terminal.
|
||||||
// Guarantees to stay within limits of the area the canvas was created with.
|
|
||||||
func (c *Canvas) Apply(t terminalapi.Terminal) error {
|
func (c *Canvas) Apply(t terminalapi.Terminal) error {
|
||||||
termArea, err := area.FromSize(t.Size())
|
// Note - the size of the terminal might have changed since we started
|
||||||
if err != nil {
|
// drawing, since terminal windows are inherently racy (the user can resize
|
||||||
return err
|
// them at any time).
|
||||||
}
|
//
|
||||||
|
// This is ok, since the underlying terminal layer will just ignore cells
|
||||||
bufArea, err := area.FromSize(c.buffer.Size())
|
// that are out of bounds and termdash will redraw again once it receives
|
||||||
if err != nil {
|
// the resize event. Regression for #281.
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bufArea.In(termArea) {
|
|
||||||
return fmt.Errorf("the canvas area %+v doesn't fit onto the terminal %+v", bufArea, termArea)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The image.Point{0, 0} of this canvas isn't always exactly at
|
// The image.Point{0, 0} of this canvas isn't always exactly at
|
||||||
// image.Point{0, 0} on the terminal.
|
// image.Point{0, 0} on the terminal.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user