mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-28 13:48:51 +08:00
Merge pull request #253 from mum4k/scroll-runes
Ability to swap Scroll runes.
This commit is contained in:
commit
aedd69c240
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- the `Text` widget now allows user to specify custom scroll marker runes.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- coveralls again triggers and reports on PRs.
|
- coveralls again triggers and reports on PRs.
|
||||||
|
@ -209,6 +209,7 @@ Termdash uses [this branching model](https://nvie.com/posts/a-successful-git-bra
|
|||||||
- [datadash](https://github.com/keithknott26/datadash): Visualize streaming or tabular data inside the terminal.
|
- [datadash](https://github.com/keithknott26/datadash): Visualize streaming or tabular data inside the terminal.
|
||||||
- [grafterm](https://github.com/slok/grafterm): Metrics dashboards visualization on the terminal.
|
- [grafterm](https://github.com/slok/grafterm): Metrics dashboards visualization on the terminal.
|
||||||
- [perfstat](https://github.com/flaviostutz/perfstat): Analyze and show tips about possible bottlenecks in Linux systems.
|
- [perfstat](https://github.com/flaviostutz/perfstat): Analyze and show tips about possible bottlenecks in Linux systems.
|
||||||
|
- [gex](https://github.com/Tosch110/gex): Cosmos SDK explorer in-terminal.
|
||||||
|
|
||||||
# Disclaimer
|
# Disclaimer
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ type Option interface {
|
|||||||
|
|
||||||
// options stores the provided options.
|
// options stores the provided options.
|
||||||
type options struct {
|
type options struct {
|
||||||
|
scrollUp rune
|
||||||
|
scrollDown rune
|
||||||
wrapMode wrap.Mode
|
wrapMode wrap.Mode
|
||||||
rollContent bool
|
rollContent bool
|
||||||
disableScrolling bool
|
disableScrolling bool
|
||||||
@ -46,6 +48,8 @@ type options struct {
|
|||||||
// newOptions returns a new options instance.
|
// newOptions returns a new options instance.
|
||||||
func newOptions(opts ...Option) *options {
|
func newOptions(opts ...Option) *options {
|
||||||
opt := &options{
|
opt := &options{
|
||||||
|
scrollUp: DefaultScrollUpRune,
|
||||||
|
scrollDown: DefaultScrollDownRune,
|
||||||
mouseUpButton: DefaultScrollMouseButtonUp,
|
mouseUpButton: DefaultScrollMouseButtonUp,
|
||||||
mouseDownButton: DefaultScrollMouseButtonDown,
|
mouseDownButton: DefaultScrollMouseButtonDown,
|
||||||
keyUp: DefaultScrollKeyUp,
|
keyUp: DefaultScrollKeyUp,
|
||||||
@ -84,6 +88,22 @@ func (o option) set(opts *options) {
|
|||||||
o(opts)
|
o(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScrollRunes configures the text widgets scroll runes, shown at the top and
|
||||||
|
// bottom of a scrollable text widget. If not provided, the default scroll
|
||||||
|
// runes will be used.
|
||||||
|
func ScrollRunes(up, down rune) Option {
|
||||||
|
return option(func(opts *options) {
|
||||||
|
opts.scrollUp = up
|
||||||
|
opts.scrollDown = down
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// The default scroll runes for content scrolling
|
||||||
|
const (
|
||||||
|
DefaultScrollUpRune = '⇧'
|
||||||
|
DefaultScrollDownRune = '⇩'
|
||||||
|
)
|
||||||
|
|
||||||
// WrapAtWords configures the text widget so that it automatically wraps lines
|
// WrapAtWords configures the text widget so that it automatically wraps lines
|
||||||
// that are longer than the width of the widget at word boundaries. If not
|
// that are longer than the width of the widget at word boundaries. If not
|
||||||
// provided, long lines are trimmed instead.
|
// provided, long lines are trimmed instead.
|
||||||
|
@ -125,7 +125,7 @@ const minLinesForMarkers = 3
|
|||||||
func (t *Text) drawScrollUp(cvs *canvas.Canvas, cur image.Point, fromLine int) (bool, error) {
|
func (t *Text) drawScrollUp(cvs *canvas.Canvas, cur image.Point, fromLine int) (bool, error) {
|
||||||
height := cvs.Area().Dy()
|
height := cvs.Area().Dy()
|
||||||
if cur.Y == 0 && height >= minLinesForMarkers && fromLine > 0 {
|
if cur.Y == 0 && height >= minLinesForMarkers && fromLine > 0 {
|
||||||
cells, err := cvs.SetCell(cur, '⇧')
|
cells, err := cvs.SetCell(cur, t.opts.scrollUp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ func (t *Text) drawScrollDown(cvs *canvas.Canvas, cur image.Point, fromLine int)
|
|||||||
height := cvs.Area().Dy()
|
height := cvs.Area().Dy()
|
||||||
lines := len(t.wrapped)
|
lines := len(t.wrapped)
|
||||||
if cur.Y == height-1 && height >= minLinesForMarkers && height < lines-fromLine {
|
if cur.Y == height-1 && height >= minLinesForMarkers && height < lines-fromLine {
|
||||||
cells, err := cvs.SetCell(cur, '⇩')
|
cells, err := cvs.SetCell(cur, t.opts.scrollDown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,26 @@ func TestTextDraws(t *testing.T) {
|
|||||||
return ft
|
return ft
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "trims content when longer than canvas and draws a custom bottom scroll marker",
|
||||||
|
canvas: image.Rect(0, 0, 10, 3),
|
||||||
|
opts: []Option{
|
||||||
|
ScrollRunes('^', '.'),
|
||||||
|
},
|
||||||
|
writes: func(widget *Text) error {
|
||||||
|
return widget.Write("line0\nline1\nline2\nline3")
|
||||||
|
},
|
||||||
|
want: func(size image.Point) *faketerm.Terminal {
|
||||||
|
ft := faketerm.MustNew(size)
|
||||||
|
c := testcanvas.MustNew(ft.Area())
|
||||||
|
|
||||||
|
testdraw.MustText(c, "line0", image.Point{0, 0})
|
||||||
|
testdraw.MustText(c, "line1", image.Point{0, 1})
|
||||||
|
testdraw.MustText(c, ".", image.Point{0, 2})
|
||||||
|
testcanvas.MustApply(c, ft)
|
||||||
|
return ft
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "scrolls down on mouse wheel down a line at a time",
|
desc: "scrolls down on mouse wheel down a line at a time",
|
||||||
canvas: image.Rect(0, 0, 10, 3),
|
canvas: image.Rect(0, 0, 10, 3),
|
||||||
@ -571,6 +591,27 @@ func TestTextDraws(t *testing.T) {
|
|||||||
return ft
|
return ft
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "rolls content upwards and draws a custom up scroll marker",
|
||||||
|
canvas: image.Rect(0, 0, 10, 3),
|
||||||
|
opts: []Option{
|
||||||
|
RollContent(),
|
||||||
|
ScrollRunes('^', '.'),
|
||||||
|
},
|
||||||
|
writes: func(widget *Text) error {
|
||||||
|
return widget.Write("line0\nline1\nline2\nline3")
|
||||||
|
},
|
||||||
|
want: func(size image.Point) *faketerm.Terminal {
|
||||||
|
ft := faketerm.MustNew(size)
|
||||||
|
c := testcanvas.MustNew(ft.Area())
|
||||||
|
|
||||||
|
testdraw.MustText(c, "^", image.Point{0, 0})
|
||||||
|
testdraw.MustText(c, "line2", image.Point{0, 1})
|
||||||
|
testdraw.MustText(c, "line3", image.Point{0, 2})
|
||||||
|
testcanvas.MustApply(c, ft)
|
||||||
|
return ft
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "rolls content upwards and wraps lines at rune boundaries",
|
desc: "rolls content upwards and wraps lines at rune boundaries",
|
||||||
canvas: image.Rect(0, 0, 10, 2),
|
canvas: image.Rect(0, 0, 10, 2),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user