diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6162d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.log +/go.work +/go.work.sum diff --git a/app.go b/app.go index 686e10e..9517eec 100644 --- a/app.go +++ b/app.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. @@ -101,6 +101,7 @@ type App struct { enableBracketedPaste bool screenInited bool dontOwnScreen bool + tty string lastMouse MouseState // So I can tell if a button was previously clicked MouseState // Track which mouse buttons are currently down @@ -119,6 +120,7 @@ type AppArgs struct { EnableBracketedPaste bool Log log.StdLogger DontActivate bool + Tty string } // IUnhandledInput is used as a handler for application user input that is not handled by any @@ -244,7 +246,7 @@ func newApp(args AppArgs) (rapp *App, rerr error) { screen := args.Screen if screen == nil { var err error - screen, err = tcellScreen() + screen, err = tcellScreen(args.Tty) if err != nil { rerr = WithKVs(err, map[string]interface{}{"TERM": os.Getenv("TERM")}) return @@ -287,6 +289,7 @@ func newApp(args AppArgs) (rapp *App, rerr error) { enableMouseMotion: args.EnableMouseMotion, enableBracketedPaste: args.EnableBracketedPaste, dontOwnScreen: args.Screen != nil, + tty: args.Tty, } if !res.dontOwnScreen && !args.DontActivate { @@ -818,7 +821,7 @@ func (a *App) Quit() { // // Assumes we own the screen... func (a *App) ActivateScreen() error { - screen, err := tcellScreen() + screen, err := tcellScreen(a.tty) if err != nil { return WithKVs(err, map[string]interface{}{"TERM": os.Getenv("TERM")}) } diff --git a/callbacks.go b/callbacks.go index 25b88df..4846848 100644 --- a/callbacks.go +++ b/callbacks.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gowid diff --git a/callbacks_test.go b/callbacks_test.go index c523583..39f07b9 100644 --- a/callbacks_test.go +++ b/callbacks_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gowid diff --git a/canvas.go b/canvas.go index a4de492..df3ba4b 100644 --- a/canvas.go +++ b/canvas.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/canvas_test.go b/canvas_test.go index 5b763bd..d8ae6d4 100644 --- a/canvas_test.go +++ b/canvas_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/cell.go b/cell.go index 2d09c68..471e3e4 100644 --- a/cell.go +++ b/cell.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/decoration.go b/decoration.go index ab4978e..43bbd69 100644 --- a/decoration.go +++ b/decoration.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gowid diff --git a/decoration_test.go b/decoration_test.go index 5ae9bd4..7321fad 100644 --- a/decoration_test.go +++ b/decoration_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gowid diff --git a/examples/gowid-asciigraph/asciigraph.go b/examples/gowid-asciigraph/asciigraph.go index be5cbfd..1ec02fd 100644 --- a/examples/gowid-asciigraph/asciigraph.go +++ b/examples/gowid-asciigraph/asciigraph.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // An example of the gowid asciigraph widget which relies upon the diff --git a/examples/gowid-dir/dir.go b/examples/gowid-dir/dir.go index 5899b76..1dfedaf 100644 --- a/examples/gowid-dir/dir.go +++ b/examples/gowid-dir/dir.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A simple gowid directory browser. diff --git a/examples/gowid-editor/editor.go b/examples/gowid-editor/editor.go index d5714d5..2eecfe9 100644 --- a/examples/gowid-editor/editor.go +++ b/examples/gowid-editor/editor.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A poor-man's editor using gowid widgets - shows dialog, edit and vscroll. diff --git a/examples/gowid-fib/fib.go b/examples/gowid-fib/fib.go index 8ce4493..ef5527c 100644 --- a/examples/gowid-fib/fib.go +++ b/examples/gowid-fib/fib.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A port of urwid's fib.py example using gowid widgets. diff --git a/examples/gowid-graph/graph.go b/examples/gowid-graph/graph.go index a1da3b5..31742e2 100644 --- a/examples/gowid-graph/graph.go +++ b/examples/gowid-graph/graph.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A port of urwid's graph.py example using gowid widgets. diff --git a/examples/gowid-helloworld/helloworld.go b/examples/gowid-helloworld/helloworld.go index 18c1762..ca3c0a3 100644 --- a/examples/gowid-helloworld/helloworld.go +++ b/examples/gowid-helloworld/helloworld.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A port of urwid's "Hello World" example from the tutorial, using gowid widgets. diff --git a/examples/gowid-menu/menu.go b/examples/gowid-menu/menu.go index deeeeb8..c18782b 100644 --- a/examples/gowid-menu/menu.go +++ b/examples/gowid-menu/menu.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A demonstration of gowid's menu, list and overlay widgets. diff --git a/examples/gowid-overlay1/overlay1.go b/examples/gowid-overlay1/overlay1.go index e6c0df3..fbbb4b1 100644 --- a/examples/gowid-overlay1/overlay1.go +++ b/examples/gowid-overlay1/overlay1.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A demonstration of gowid's overlay and fill widgets. diff --git a/examples/gowid-overlay2/overlay2.go b/examples/gowid-overlay2/overlay2.go index dc3ec00..3cd4347 100644 --- a/examples/gowid-overlay2/overlay2.go +++ b/examples/gowid-overlay2/overlay2.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A demonstration of gowid's overlay, fill, asciigraph and radio widgets. diff --git a/examples/gowid-overlay3/overlay3.go b/examples/gowid-overlay3/overlay3.go index 3772ae9..2d12176 100644 --- a/examples/gowid-overlay3/overlay3.go +++ b/examples/gowid-overlay3/overlay3.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A demonstration of gowid's overlay and fill widgets. diff --git a/examples/gowid-palette/palette.go b/examples/gowid-palette/palette.go index b4ff261..ff7c3e0 100644 --- a/examples/gowid-palette/palette.go +++ b/examples/gowid-palette/palette.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A port of urwid's palette_test.py example using gowid widgets. diff --git a/examples/gowid-table/table.go b/examples/gowid-table/table.go index 3d917f7..997a027 100644 --- a/examples/gowid-table/table.go +++ b/examples/gowid-table/table.go @@ -1,6 +1,6 @@ //go:generate statik -src=data -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/examples/gowid-terminal/terminal.go b/examples/gowid-terminal/terminal.go index 4086c0f..a140ed8 100644 --- a/examples/gowid-terminal/terminal.go +++ b/examples/gowid-terminal/terminal.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A very poor-man's tmux written using gowid's terminal widget. diff --git a/examples/gowid-tree/tree.go b/examples/gowid-tree/tree.go index 5b7f645..d750026 100644 --- a/examples/gowid-tree/tree.go +++ b/examples/gowid-tree/tree.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/examples/gowid-tutorial1/tutorial1.go b/examples/gowid-tutorial1/tutorial1.go index 39b1882..92cd8e2 100644 --- a/examples/gowid-tutorial1/tutorial1.go +++ b/examples/gowid-tutorial1/tutorial1.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The first example from the gowid tutorial. diff --git a/examples/gowid-tutorial2/tutorial2.go b/examples/gowid-tutorial2/tutorial2.go index 9afd299..15020d4 100644 --- a/examples/gowid-tutorial2/tutorial2.go +++ b/examples/gowid-tutorial2/tutorial2.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The second example from the gowid tutorial. diff --git a/examples/gowid-tutorial3/tutorial3.go b/examples/gowid-tutorial3/tutorial3.go index 3abccbc..3e0a2dc 100644 --- a/examples/gowid-tutorial3/tutorial3.go +++ b/examples/gowid-tutorial3/tutorial3.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The third example from the gowid tutorial. diff --git a/examples/gowid-tutorial4/tutorial4.go b/examples/gowid-tutorial4/tutorial4.go index e2584a0..876e446 100644 --- a/examples/gowid-tutorial4/tutorial4.go +++ b/examples/gowid-tutorial4/tutorial4.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The fourth example from the gowid tutorial. diff --git a/examples/gowid-tutorial5/tutorial5.go b/examples/gowid-tutorial5/tutorial5.go index a296845..9ce9289 100644 --- a/examples/gowid-tutorial5/tutorial5.go +++ b/examples/gowid-tutorial5/tutorial5.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The fifth example from the gowid tutorial. diff --git a/examples/gowid-tutorial6/tutorial6.go b/examples/gowid-tutorial6/tutorial6.go index d7e84e7..7bd6967 100644 --- a/examples/gowid-tutorial6/tutorial6.go +++ b/examples/gowid-tutorial6/tutorial6.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // The sixth example from the gowid tutorial. diff --git a/examples/gowid-widgets1/widgets1.go b/examples/gowid-widgets1/widgets1.go index d7e087a..af92621 100644 --- a/examples/gowid-widgets1/widgets1.go +++ b/examples/gowid-widgets1/widgets1.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the pile, button, edit and progress widgets. diff --git a/examples/gowid-widgets2/widgets2.go b/examples/gowid-widgets2/widgets2.go index 8930cd3..1362580 100644 --- a/examples/gowid-widgets2/widgets2.go +++ b/examples/gowid-widgets2/widgets2.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the columns, checkbox, edit and styled widgets. diff --git a/examples/gowid-widgets3/widgets3.go b/examples/gowid-widgets3/widgets3.go index 2be9f8d..c99ff17 100644 --- a/examples/gowid-widgets3/widgets3.go +++ b/examples/gowid-widgets3/widgets3.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the button, grid, progress and radio widgets. diff --git a/examples/gowid-widgets4/widgets4.go b/examples/gowid-widgets4/widgets4.go index 955f220..9f91544 100644 --- a/examples/gowid-widgets4/widgets4.go +++ b/examples/gowid-widgets4/widgets4.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the columns, list and framed widgets. diff --git a/examples/gowid-widgets5/widgets5.go b/examples/gowid-widgets5/widgets5.go index 4a4a953..0f60b7a 100644 --- a/examples/gowid-widgets5/widgets5.go +++ b/examples/gowid-widgets5/widgets5.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the edit and vpadding widgets. diff --git a/examples/gowid-widgets6/widgets6.go b/examples/gowid-widgets6/widgets6.go index 9ceb1f6..e944786 100644 --- a/examples/gowid-widgets6/widgets6.go +++ b/examples/gowid-widgets6/widgets6.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the list, edit, columns and styled widgets. diff --git a/examples/gowid-widgets7/widgets7.go b/examples/gowid-widgets7/widgets7.go index 962bc0b..876c2aa 100644 --- a/examples/gowid-widgets7/widgets7.go +++ b/examples/gowid-widgets7/widgets7.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the list, edit and framed widgets. diff --git a/examples/gowid-widgets8/widgets8.go b/examples/gowid-widgets8/widgets8.go index 2fe2452..7645186 100644 --- a/examples/gowid-widgets8/widgets8.go +++ b/examples/gowid-widgets8/widgets8.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // A gowid test app which exercises the checkbox, columns and hpadding widgets. diff --git a/examples/utils.go b/examples/utils.go index 0dc3286..91168b6 100644 --- a/examples/utils.go +++ b/examples/utils.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package examples diff --git a/gwtest/support_test.go b/gwtest/support_test.go index 04265e8..518be5f 100644 --- a/gwtest/support_test.go +++ b/gwtest/support_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gwtest diff --git a/gwtest/testutils.go b/gwtest/testutils.go index a446334..437b348 100644 --- a/gwtest/testutils.go +++ b/gwtest/testutils.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/gwutil/utils.go b/gwutil/utils.go index 260ed27..4c7e9ed 100644 --- a/gwutil/utils.go +++ b/gwutil/utils.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // Package gwutil provides general-purpose utilities that are not used by diff --git a/gwutil/utils_test.go b/gwutil/utils_test.go index 5244276..2e52e02 100644 --- a/gwutil/utils_test.go +++ b/gwutil/utils_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gwutil diff --git a/screen.go b/screen.go index 226a933..f44fb89 100644 --- a/screen.go +++ b/screen.go @@ -14,19 +14,22 @@ import ( //====================================================================== -func tcellScreen() (tcell.Screen, error) { +func tcellScreen(ttys string) (tcell.Screen, error) { var tty tcell.Tty var err error - tty, err = tcell.NewDevTtyFromDev(bestTty()) + tty, err = tcell.NewDevTtyFromDev(bestTty(ttys)) if err != nil { - return nil, WithKVs(err, map[string]interface{}{"GOWID_TTY": os.Getenv("GOWID_TTY")}) + return nil, WithKVs(err, map[string]interface{}{"tty": ttys}) } return tcell.NewTerminfoScreenFromTty(tty) } -func bestTty() string { +func bestTty(tty string) string { + if tty != "" { + return tty + } gwtty := os.Getenv("GOWID_TTY") if gwtty != "" { return gwtty diff --git a/screen_windows.go b/screen_windows.go index 7840e5b..4d356a4 100644 --- a/screen_windows.go +++ b/screen_windows.go @@ -11,7 +11,7 @@ import ( //====================================================================== -func tcellScreen() (tcell.Screen, error) { +func tcellScreen(tty string) (tcell.Screen, error) { return tcell.NewScreen() } diff --git a/support.go b/support.go index 1176141..3541fab 100644 --- a/support.go +++ b/support.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/utils.go b/utils.go index 4ff6a2f..58d9804 100644 --- a/utils.go +++ b/utils.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package gowid diff --git a/vim/vim_test.go b/vim/vim_test.go index 7fd469d..2d0546a 100644 --- a/vim/vim_test.go +++ b/vim/vim_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/asciigraph/asciigraph.go b/widgets/asciigraph/asciigraph.go index ca04b28..79d9b8e 100644 --- a/widgets/asciigraph/asciigraph.go +++ b/widgets/asciigraph/asciigraph.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/asciigraph/asciigraph_test.go b/widgets/asciigraph/asciigraph_test.go index c20a781..5b2955b 100644 --- a/widgets/asciigraph/asciigraph_test.go +++ b/widgets/asciigraph/asciigraph_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/bargraph/bargraph.go b/widgets/bargraph/bargraph.go index 2402ab9..b92dd6f 100644 --- a/widgets/bargraph/bargraph.go +++ b/widgets/bargraph/bargraph.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/boxadapter/boxadapter.go b/widgets/boxadapter/boxadapter.go index 835fe8e..d4015d4 100644 --- a/widgets/boxadapter/boxadapter.go +++ b/widgets/boxadapter/boxadapter.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code // is governed by the MIT license that can be found in the LICENSE file. // Package boxadapter provides a widget that will allow a box widget to be used diff --git a/widgets/boxadapter/boxadapter_test.go b/widgets/boxadapter/boxadapter_test.go index 7927c78..2606ac5 100644 --- a/widgets/boxadapter/boxadapter_test.go +++ b/widgets/boxadapter/boxadapter_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package boxadapter diff --git a/widgets/button/button.go b/widgets/button/button.go index 0483ee8..e9925f7 100644 --- a/widgets/button/button.go +++ b/widgets/button/button.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/button/button_test.go b/widgets/button/button_test.go index 6e331b5..3b20774 100644 --- a/widgets/button/button_test.go +++ b/widgets/button/button_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package button diff --git a/widgets/cellmod/cellmod.go b/widgets/cellmod/cellmod.go index 7c961d0..24bf646 100644 --- a/widgets/cellmod/cellmod.go +++ b/widgets/cellmod/cellmod.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/checkbox/checkbox.go b/widgets/checkbox/checkbox.go index 4c9a7ef..7fa0048 100644 --- a/widgets/checkbox/checkbox.go +++ b/widgets/checkbox/checkbox.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/checkbox/checkbox_test.go b/widgets/checkbox/checkbox_test.go index 2161572..4073fbb 100644 --- a/widgets/checkbox/checkbox_test.go +++ b/widgets/checkbox/checkbox_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package checkbox diff --git a/widgets/clicktracker/clicktracker.go b/widgets/clicktracker/clicktracker.go index f95ef44..cf1a3bb 100644 --- a/widgets/clicktracker/clicktracker.go +++ b/widgets/clicktracker/clicktracker.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/columns/columns.go b/widgets/columns/columns.go index ca729c4..a4ea888 100644 --- a/widgets/columns/columns.go +++ b/widgets/columns/columns.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/columns/columns_test.go b/widgets/columns/columns_test.go index 6fd2545..ccb102c 100644 --- a/widgets/columns/columns_test.go +++ b/widgets/columns/columns_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/dialog/dialog.go b/widgets/dialog/dialog.go index f492cde..823cfa9 100644 --- a/widgets/dialog/dialog.go +++ b/widgets/dialog/dialog.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. @@ -405,7 +405,9 @@ type IOpenExt interface { func OpenExt(w IOpenExt, container gowid.ISettableComposite, width gowid.IWidgetDimension, height gowid.IWidgetDimension, app gowid.IApp) { ov := overlay.New(w, container.SubWidget(), gowid.VAlignMiddle{}, height, // Intended to mean use as much vertical space as you need - gowid.HAlignMiddle{}, width) + gowid.HAlignMiddle{}, width, overlay.Options{ + IgnoreLowerStyle: true, + }) if _, ok := width.(gowid.IRenderFixed); ok { w.SetContentWidth(gowid.RenderFixed{}, app) // fixed or weight:1, ratio:0.5 diff --git a/widgets/disable/disable.go b/widgets/disable/disable.go index 0ad8dfb..1064a52 100644 --- a/widgets/disable/disable.go +++ b/widgets/disable/disable.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/divider/divider.go b/widgets/divider/divider.go index df42c81..bd712ad 100644 --- a/widgets/divider/divider.go +++ b/widgets/divider/divider.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/divider/divider_test.go b/widgets/divider/divider_test.go index 1d99c68..88cd0e0 100644 --- a/widgets/divider/divider_test.go +++ b/widgets/divider/divider_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package divider diff --git a/widgets/edit/edit.go b/widgets/edit/edit.go index 385e1ec..d1fbb2d 100644 --- a/widgets/edit/edit.go +++ b/widgets/edit/edit.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/edit/edit_test.go b/widgets/edit/edit_test.go index 50cd7f1..908cd6d 100644 --- a/widgets/edit/edit_test.go +++ b/widgets/edit/edit_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package edit diff --git a/widgets/fill/fill.go b/widgets/fill/fill.go index 2ec5fe8..6283eb1 100644 --- a/widgets/fill/fill.go +++ b/widgets/fill/fill.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/fill/fill_test.go b/widgets/fill/fill_test.go index 3faf297..b0e73e3 100644 --- a/widgets/fill/fill_test.go +++ b/widgets/fill/fill_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/fixedadapter/fixedadapter.go b/widgets/fixedadapter/fixedadapter.go index 35531c3..2d96249 100644 --- a/widgets/fixedadapter/fixedadapter.go +++ b/widgets/fixedadapter/fixedadapter.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // Package fixedadaptor provides a widget that will render a fixed widget when diff --git a/widgets/fixedadapter/fixedadapter_test.go b/widgets/fixedadapter/fixedadapter_test.go index f69066d..4c42013 100644 --- a/widgets/fixedadapter/fixedadapter_test.go +++ b/widgets/fixedadapter/fixedadapter_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package fixedadapter diff --git a/widgets/framed/framed.go b/widgets/framed/framed.go index 73dcc1d..b700376 100644 --- a/widgets/framed/framed.go +++ b/widgets/framed/framed.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/framed/framed_test.go b/widgets/framed/framed_test.go index 6f96be6..bec6bed 100644 --- a/widgets/framed/framed_test.go +++ b/widgets/framed/framed_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package framed diff --git a/widgets/grid/grid.go b/widgets/grid/grid.go index 2d9678b..3c099c4 100644 --- a/widgets/grid/grid.go +++ b/widgets/grid/grid.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/grid/grid_test.go b/widgets/grid/grid_test.go index 87fa1ca..c763cec 100644 --- a/widgets/grid/grid_test.go +++ b/widgets/grid/grid_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/holder/holder.go b/widgets/holder/holder.go index 07e7c52..d2251f6 100644 --- a/widgets/holder/holder.go +++ b/widgets/holder/holder.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/hpadding/hpadding.go b/widgets/hpadding/hpadding.go index 9fa8169..35b96c3 100644 --- a/widgets/hpadding/hpadding.go +++ b/widgets/hpadding/hpadding.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/hpadding/hpadding_test.go b/widgets/hpadding/hpadding_test.go index 59f6860..0dfa919 100644 --- a/widgets/hpadding/hpadding_test.go +++ b/widgets/hpadding/hpadding_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/isselected/isselected.go b/widgets/isselected/isselected.go index 873769c..ada4b61 100644 --- a/widgets/isselected/isselected.go +++ b/widgets/isselected/isselected.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/keypress/keypress.go b/widgets/keypress/keypress.go index 5c4e4b9..6ea022d 100644 --- a/widgets/keypress/keypress.go +++ b/widgets/keypress/keypress.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/keypress/keypress_test.go b/widgets/keypress/keypress_test.go index 830fbb8..0e1f899 100644 --- a/widgets/keypress/keypress_test.go +++ b/widgets/keypress/keypress_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package keypress diff --git a/widgets/list/list.go b/widgets/list/list.go index d364d50..927f702 100644 --- a/widgets/list/list.go +++ b/widgets/list/list.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/list/list_test.go b/widgets/list/list_test.go index 8a17897..b6583a8 100644 --- a/widgets/list/list_test.go +++ b/widgets/list/list_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package list diff --git a/widgets/menu/menu.go b/widgets/menu/menu.go index 4f8af19..bc55050 100644 --- a/widgets/menu/menu.go +++ b/widgets/menu/menu.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/null/null.go b/widgets/null/null.go index e87cf0c..2987926 100644 --- a/widgets/null/null.go +++ b/widgets/null/null.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/overlay/overlay.go b/widgets/overlay/overlay.go index 68f7ea6..770164e 100644 --- a/widgets/overlay/overlay.go +++ b/widgets/overlay/overlay.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. @@ -70,6 +70,10 @@ type IOverlay interface { BottomGetsCursor() bool } +type IIgnoreLowerStyle interface { + IgnoreLowerStyle() bool +} + type IWidget interface { gowid.IWidget IOverlay @@ -100,6 +104,8 @@ type Widget struct { Callbacks *gowid.Callbacks } +var _ IIgnoreLowerStyle = (*Widget)(nil) + // For callback registration type Top struct{} type Bottom struct{} @@ -108,6 +114,7 @@ type Options struct { BottomGetsFocus bool TopGetsNoFocus bool BottomGetsCursor bool + IgnoreLowerStyle bool } func New(top, bottom gowid.IWidget, @@ -235,6 +242,10 @@ func (w *Widget) SetSubWidget(inner gowid.IWidget, app gowid.IApp) { } } +func (w *Widget) IgnoreLowerStyle() bool { + return w.opts.IgnoreLowerStyle +} + //====================================================================== func UserInput(w IOverlay, ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool { @@ -262,6 +273,30 @@ func UserInput(w IOverlay, ev interface{}, size gowid.IRenderSize, focus gowid.S return res } +// Merge cells as follows - use upper rune if set, use upper colors if set, +// and use upper style only (don't let any lower run style bleed through) +func mergeAllExceptUpperStyle(lower gowid.Cell, upper gowid.Cell) gowid.Cell { + res := lower + if upper.HasRune() { + res = res.WithRune(upper.Rune()) + } + + ufg, ubg, _ := upper.GetDisplayAttrs() + if ubg != gowid.ColorNone { + res = res.WithBackgroundColor(ubg) + } + if ufg != gowid.ColorNone { + res = res.WithForegroundColor(ufg) + } + + res = res.WithStyle(upper.Style()) + return res +} + +type iMergeWithFuncCanvas interface { + MergeWithFunc(gowid.IMergeCanvas, int, int, gowid.CellMergeFunc, bool) +} + func Render(w IOverlay, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas { bfocus := focus.And(w.BottomGetsFocus()) tfocus := focus.And(w.TopGetsFocus()) @@ -273,7 +308,22 @@ func Render(w IOverlay, size gowid.IRenderSize, focus gowid.Selector, app gowid. bottomC2 := bottomC.Duplicate() p2 := padding.New(w.Top(), w.VAlign(), w.Height(), w.HAlign(), w.Width()) topC := p2.Render(size, tfocus, app) - bottomC2.MergeUnder(topC, 0, 0, w.BottomGetsCursor()) + + var bottomC2mc iMergeWithFuncCanvas + ign := false + if wIgn, ok := w.(IIgnoreLowerStyle); ok { + if gc, ok := bottomC2.(iMergeWithFuncCanvas); ok { + bottomC2mc = gc + ign = wIgn.IgnoreLowerStyle() + } + } + + if ign { + bottomC2mc.MergeWithFunc(topC, 0, 0, mergeAllExceptUpperStyle, w.BottomGetsCursor()) + } else { + bottomC2.MergeUnder(topC, 0, 0, w.BottomGetsCursor()) + } + return bottomC2 } } diff --git a/widgets/overlay/overlay_test.go b/widgets/overlay/overlay_test.go new file mode 100644 index 0000000..2e7f860 --- /dev/null +++ b/widgets/overlay/overlay_test.go @@ -0,0 +1,41 @@ +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source +// code is governed by the MIT license that can be found in the LICENSE +// file. + +package overlay + +import ( + "testing" + + "github.com/gcla/gowid" + "github.com/gcla/gowid/gwtest" + "github.com/gcla/gowid/widgets/styled" + "github.com/gcla/gowid/widgets/text" + "github.com/gdamore/tcell/v2" + "github.com/stretchr/testify/assert" +) + +func TestOverlay1(t *testing.T) { + tw := text.New("top") + bw := text.New("bottom") + ov := New(tw, bw, gowid.VAlignTop{}, gowid.RenderFixed{}, gowid.HAlignLeft{}, gowid.RenderFixed{}) + c := ov.Render(gowid.RenderFlowWith{C: 6}, gowid.Focused, gwtest.D) + assert.Equal(t, "toptom", c.String()) + + bwStyled := styled.New(bw, gowid.MakeStyledAs(gowid.StyleBold)) + + // When the widget is created this way, the style from the lower widget bleeds through + ov = New(tw, bwStyled, gowid.VAlignTop{}, gowid.RenderFixed{}, gowid.HAlignLeft{}, gowid.RenderFixed{}) + c = ov.Render(gowid.RenderFlowWith{C: 6}, gowid.Focused, gwtest.D) + assert.Equal(t, "toptom", c.String()) + assert.Equal(t, tcell.AttrBold, c.CellAt(0, 0).Style().OnOff&tcell.AttrBold) + + // When the widget is created this way, the style from the upper widget is set unilaterally + ov = New(tw, bwStyled, gowid.VAlignTop{}, gowid.RenderFixed{}, gowid.HAlignLeft{}, gowid.RenderFixed{}, + Options{ + IgnoreLowerStyle: true, + }) + c = ov.Render(gowid.RenderFlowWith{C: 6}, gowid.Focused, gwtest.D) + assert.Equal(t, "toptom", c.String()) + assert.Equal(t, tcell.AttrMask(0), c.CellAt(0, 0).Style().OnOff&tcell.AttrBold) +} diff --git a/widgets/padding/padding.go b/widgets/padding/padding.go index 51ab224..3841612 100644 --- a/widgets/padding/padding.go +++ b/widgets/padding/padding.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/padding/padding_test.go b/widgets/padding/padding_test.go index 8cedb32..3176527 100644 --- a/widgets/padding/padding_test.go +++ b/widgets/padding/padding_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package padding diff --git a/widgets/palettemap/palettemap.go b/widgets/palettemap/palettemap.go index 1e13e95..e0b639d 100644 --- a/widgets/palettemap/palettemap.go +++ b/widgets/palettemap/palettemap.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/pile/pile.go b/widgets/pile/pile.go index 8538a7b..0ac12d3 100644 --- a/widgets/pile/pile.go +++ b/widgets/pile/pile.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/pile/pile_test.go b/widgets/pile/pile_test.go index d632d22..70f0561 100644 --- a/widgets/pile/pile_test.go +++ b/widgets/pile/pile_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package pile diff --git a/widgets/progress/progress.go b/widgets/progress/progress.go index 8871b08..887e1f8 100644 --- a/widgets/progress/progress.go +++ b/widgets/progress/progress.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/progress/progress_test.go b/widgets/progress/progress_test.go index 7a5f6e9..4f8f2a5 100644 --- a/widgets/progress/progress_test.go +++ b/widgets/progress/progress_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package progress diff --git a/widgets/radio/radio.go b/widgets/radio/radio.go index a37cf06..cde8989 100644 --- a/widgets/radio/radio.go +++ b/widgets/radio/radio.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/radio/radio_test.go b/widgets/radio/radio_test.go index 29065fc..d201a79 100644 --- a/widgets/radio/radio_test.go +++ b/widgets/radio/radio_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package radio diff --git a/widgets/selectable/selectable.go b/widgets/selectable/selectable.go index 29f756a..d23e174 100644 --- a/widgets/selectable/selectable.go +++ b/widgets/selectable/selectable.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/shadow/shadow.go b/widgets/shadow/shadow.go index 6041e85..1e86f70 100644 --- a/widgets/shadow/shadow.go +++ b/widgets/shadow/shadow.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/spinner/spinner.go b/widgets/spinner/spinner.go index ed838e7..139f2c7 100644 --- a/widgets/spinner/spinner.go +++ b/widgets/spinner/spinner.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/styled/styled.go b/widgets/styled/styled.go index e5c0741..7e6e357 100644 --- a/widgets/styled/styled.go +++ b/widgets/styled/styled.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/styled/styled_test.go b/widgets/styled/styled_test.go index 2eb683c..5371e00 100644 --- a/widgets/styled/styled_test.go +++ b/widgets/styled/styled_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/table/simple_model.go b/widgets/table/simple_model.go index 27f0db4..5e0c5af 100644 --- a/widgets/table/simple_model.go +++ b/widgets/table/simple_model.go @@ -1,6 +1,6 @@ //go:generate statik -src=data -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/table/table.go b/widgets/table/table.go index e79e277..5deb166 100644 --- a/widgets/table/table.go +++ b/widgets/table/table.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/table/table_test.go b/widgets/table/table_test.go index d6934e4..7cb183c 100644 --- a/widgets/table/table_test.go +++ b/widgets/table/table_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/terminal/term_canvas.go b/widgets/terminal/term_canvas.go index 8c30018..cfa35ac 100644 --- a/widgets/terminal/term_canvas.go +++ b/widgets/terminal/term_canvas.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/terminal/terminal.go b/widgets/terminal/terminal.go index 34e8c61..bb970ae 100644 --- a/widgets/terminal/terminal.go +++ b/widgets/terminal/terminal.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. @@ -129,14 +129,16 @@ type title struct{} type hotkey struct{} type Options struct { - Command []string - Env []string - HotKey IHotKeyProvider - HotKeyPersistence IHotKeyPersistence // the period of time a hotKey sticks after the first post-hotKey keypress - Scrollback int - Scrollbar bool // disabled regardless of setting if there is no scrollback - HotKeyFns []HotKeyInputFn // allow custom behavior after pressing the hotkey - EnableBracketedPaste bool + Command []string + Env []string + HotKey IHotKeyProvider + HotKeyPersistence IHotKeyPersistence // the period of time a hotKey sticks after the first post-hotKey keypress + Scrollback int + Scrollbar bool // disabled regardless of setting if there is no scrollback + HotKeyFns []HotKeyInputFn // allow custom behavior after pressing the hotkey + EnableBracketedPaste bool + KeyPressToEndScrollMode bool // set to true to enable legacy behavior - when the user has scrolled + // back to the prompt, still require a keypress (q or Q) to end scroll-mode. } // Widget is a widget that hosts a terminal-based application. The user provides the @@ -379,9 +381,18 @@ func (w *Widget) Scroll(dir ScrollDir, page bool, lines int) { } else { lines = w.canvas.ScrollBuffer(dir, false, gwutil.SomeInt(lines)) } - // Scrolling is now true if it (a) was previously, or (b) wasn't, but we - // scrolled more than one line - w.isScrolling = w.isScrolling || lines != 0 + + wasScrolling := w.isScrolling + if lines != 0 { + w.isScrolling = true + } else if !w.params.KeyPressToEndScrollMode && dir == ScrollDown { + // Disable scroll if we are at the bottom and we tried to scroll down + // Thanks @Peter2121 ! + w.isScrolling = false + } + if wasScrolling && !w.isScrolling { + w.ResetScroll() + } } func (w *Widget) ResetScroll() { diff --git a/widgets/terminal/terminal_test.go b/widgets/terminal/terminal_test.go index f0ee2af..934538e 100644 --- a/widgets/terminal/terminal_test.go +++ b/widgets/terminal/terminal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/terminal/utils.go b/widgets/terminal/utils.go index 1ecab02..441f34f 100644 --- a/widgets/terminal/utils.go +++ b/widgets/terminal/utils.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. // Based heavily on vterm.py from urwid diff --git a/widgets/text/testwidget.go b/widgets/text/testwidget.go index a67107e..9ed7288 100644 --- a/widgets/text/testwidget.go +++ b/widgets/text/testwidget.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/text/text.go b/widgets/text/text.go index d51ce47..219b404 100644 --- a/widgets/text/text.go +++ b/widgets/text/text.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/text/text_test.go b/widgets/text/text_test.go index bbf1e98..f284d28 100644 --- a/widgets/text/text_test.go +++ b/widgets/text/text_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package text diff --git a/widgets/tree/tree.go b/widgets/tree/tree.go index 96e210f..e40d8f0 100644 --- a/widgets/tree/tree.go +++ b/widgets/tree/tree.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/tree/tree_test.go b/widgets/tree/tree_test.go index 0fcacc8..2d90080 100644 --- a/widgets/tree/tree_test.go +++ b/widgets/tree/tree_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package tree diff --git a/widgets/vpadding/vpadding.go b/widgets/vpadding/vpadding.go index 13bacd5..26f1ac7 100644 --- a/widgets/vpadding/vpadding.go +++ b/widgets/vpadding/vpadding.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/vpadding/vpadding_test.go b/widgets/vpadding/vpadding_test.go index b8b2df1..fc01ebe 100644 --- a/widgets/vpadding/vpadding_test.go +++ b/widgets/vpadding/vpadding_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package vpadding diff --git a/widgets/vscroll/vscroll.go b/widgets/vscroll/vscroll.go index 13c4b60..8799a34 100644 --- a/widgets/vscroll/vscroll.go +++ b/widgets/vscroll/vscroll.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source // code is governed by the MIT license that can be found in the LICENSE // file. diff --git a/widgets/vscroll/vscroll_test.go b/widgets/vscroll/vscroll_test.go index d1ba80e..d6dd0e6 100644 --- a/widgets/vscroll/vscroll_test.go +++ b/widgets/vscroll/vscroll_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package vscroll