From 109e2a9efd6005d1560bb453ad5a42c4c117368a Mon Sep 17 00:00:00 2001 From: milarin Date: Mon, 24 Apr 2023 11:55:04 +0200 Subject: [PATCH] migrated to milar.in --- go.mod | 9 +++++---- go.sum | 14 ++++++++------ layouts/layout_border.go | 2 +- layouts/layout_coord.go | 2 +- layouts/layout_flow.go | 2 +- layouts/layout_separator.go | 2 +- layouts/utils.go | 29 ++++++----------------------- modals/modal_info.go | 14 ++++++-------- screen.go | 10 +++++----- tests/screen_test.go | 14 ++++++++++---- types.go | 2 +- views/utils.go | 18 ------------------ views/view_border.go | 2 +- views/view_constrain.go | 7 ++++--- views/view_frame.go | 2 +- views/view_grow.go | 2 +- views/view_margin.go | 2 +- views/view_scroll.go | 9 +++++---- views/view_text.go | 2 +- 19 files changed, 59 insertions(+), 85 deletions(-) diff --git a/go.mod b/go.mod index a6819a5..0b91197 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ -module git.tordarus.net/Tordarus/tui +module git.milar.in/milarin/tui go 1.18 require ( - git.tordarus.net/Tordarus/adverr v0.2.0 - git.tordarus.net/Tordarus/buf2d v1.1.6 - git.tordarus.net/Tordarus/dstruct v0.0.3 + git.milar.in/milarin/adverr v1.1.0 + git.milar.in/milarin/buf2d v1.1.7 + git.milar.in/milarin/ds v0.0.2 + git.milar.in/milarin/gmath v0.0.3 github.com/gdamore/tcell v1.4.0 github.com/mattn/go-runewidth v0.0.7 ) diff --git a/go.sum b/go.sum index fb49202..71a932d 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,11 @@ -git.tordarus.net/Tordarus/adverr v0.2.0 h1:kLYjR2/Vb2GHiSAMvAv+WPNaHR9BRphKanf8H/pCZdA= -git.tordarus.net/Tordarus/adverr v0.2.0/go.mod h1:XRf0+7nhOkIEr0gi9DUG4RvV2KaOFB0fYPDaR1KLenw= -git.tordarus.net/Tordarus/buf2d v1.1.6 h1:qBLHSRj0eDxaG/IOUncJpWr1xwEKD4SCZReLo5r5eJw= -git.tordarus.net/Tordarus/buf2d v1.1.6/go.mod h1:XXPpS8nQK0gUI0ki7ftV/qlprsGCRWFVSD4ybvDuUL8= -git.tordarus.net/Tordarus/dstruct v0.0.3 h1:cnUOM2rf96skIXGwBhSyzGMcT65ks8lFrOjpg6k23K8= -git.tordarus.net/Tordarus/dstruct v0.0.3/go.mod h1:RvLL2G4lUCGzwr8KaBGQRi3qlMG0WTgGhcVN6iyZZuw= +git.milar.in/milarin/adverr v1.1.0 h1:jD9WnOvs40lfMhvqQ7cllOaRJNBMWr1f07/s9jAadp0= +git.milar.in/milarin/adverr v1.1.0/go.mod h1:joU9sBb7ySyNv4SpTXB0Z4o1mjXsArBw4N27wjgzj9E= +git.milar.in/milarin/buf2d v1.1.7 h1:c+YEM4jthzaLmifx9PfP1Gy4ozQxh9+0menyShj0qU0= +git.milar.in/milarin/buf2d v1.1.7/go.mod h1:yiJgXMuUXTQ/Dzc/N3iIMa4riyL5y1aQgZOZfzNIWHo= +git.milar.in/milarin/ds v0.0.2 h1:vCA3mDxZUNfvHpzrdz7SeBUKiPn74NTopo915IUG7I0= +git.milar.in/milarin/ds v0.0.2/go.mod h1:HJK7QERcRvV9j7xzEocrKUtW+1q4JB1Ly4Bj54chfwI= +git.milar.in/milarin/gmath v0.0.3 h1:ii6rKNItS55O/wtIFhD1cTN2BMwDZjTBmiOocKURvxM= +git.milar.in/milarin/gmath v0.0.3/go.mod h1:HDLftG5RLpiNGKiIWh+O2G1PYkNzyLDADO8Cd/1abiE= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= diff --git a/layouts/layout_border.go b/layouts/layout_border.go index 309eb71..8235e23 100644 --- a/layouts/layout_border.go +++ b/layouts/layout_border.go @@ -1,7 +1,7 @@ package layouts import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/tui" ) // BorderLayout ia a tui.Layout which places its children onto a given tui.Side diff --git a/layouts/layout_coord.go b/layouts/layout_coord.go index 6e0d852..4287ed7 100644 --- a/layouts/layout_coord.go +++ b/layouts/layout_coord.go @@ -1,6 +1,6 @@ package layouts -import "git.tordarus.net/Tordarus/tui" +import "git.milar.in/milarin/tui" // CoordLayout is a tui.Layout which places its children on predefined coordinates type CoordLayout struct { diff --git a/layouts/layout_flow.go b/layouts/layout_flow.go index 0675526..79daf21 100644 --- a/layouts/layout_flow.go +++ b/layouts/layout_flow.go @@ -1,7 +1,7 @@ package layouts import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/tui" ) // FlowLayout ia a tui.Layout which places its children in a linear layout diff --git a/layouts/layout_separator.go b/layouts/layout_separator.go index d4ea868..babe18a 100644 --- a/layouts/layout_separator.go +++ b/layouts/layout_separator.go @@ -1,7 +1,7 @@ package layouts import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/tui" ) // SeperatorLayout ia a tui.Layout which separates its view into gravity-based portions diff --git a/layouts/utils.go b/layouts/utils.go index 75197bd..242b125 100644 --- a/layouts/utils.go +++ b/layouts/utils.go @@ -3,27 +3,10 @@ package layouts import ( "math" - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/gmath" + "git.milar.in/milarin/tui" ) -func min(x, y int) int { - if x < y { - return x - } - return y -} - -func max(x, y int) int { - if x > y { - return x - } - return y -} - -func limit(v, minv, maxv int) int { - return min(max(v, minv), maxv) -} - func iff[T any](condition bool, trueValue, falseValue T) T { if condition { return trueValue @@ -71,16 +54,16 @@ func CalculateLayoutResult(views []tui.View) *LayoutResult { if width > 0 { result.Sum.Width += width - result.Min.Width = min(result.Min.Width, width) - result.Max.Width = max(result.Max.Width, width) + result.Min.Width = gmath.Min(result.Min.Width, width) + result.Max.Width = gmath.Max(result.Max.Width, width) } else if width < 0 { result.HorizontalNegativeCount++ } if height > 0 { result.Sum.Height += height - result.Min.Height = min(result.Min.Height, height) - result.Max.Height = max(result.Max.Height, height) + result.Min.Height = gmath.Min(result.Min.Height, height) + result.Max.Height = gmath.Max(result.Max.Height, height) } else if height < 0 { result.VerticalNegativeCount++ } diff --git a/modals/modal_info.go b/modals/modal_info.go index ee9a295..4483ae5 100644 --- a/modals/modal_info.go +++ b/modals/modal_info.go @@ -1,9 +1,7 @@ package modals import ( - "git.tordarus.net/Tordarus/tui" - "git.tordarus.net/Tordarus/tui/views" - "github.com/gdamore/tcell" + "git.milar.in/milarin/tui/views" ) type InfoModal struct { @@ -20,12 +18,12 @@ func NewInfoModal(message string) *InfoModal { FrameView: fv, } - m.KeyPressed = func(event *tui.KeyEvent) (consumed bool) { - if event.Key() == tcell.KeyEnter || event.Key() == tcell.KeyESC { + // m.KeyPressed = func(event *tui.KeyEvent) (consumed bool) { + // // if event.Key() == tcell.KeyEnter || event.Key() == tcell.KeyESC { - } - return true - } + // // } + // return true + // } return m } diff --git a/screen.go b/screen.go index e21f2ef..1f38569 100644 --- a/screen.go +++ b/screen.go @@ -3,9 +3,9 @@ package tui import ( "fmt" - "git.tordarus.net/Tordarus/adverr" - "git.tordarus.net/Tordarus/buf2d" - "git.tordarus.net/Tordarus/dstruct" + "git.milar.in/milarin/adverr" + "git.milar.in/milarin/buf2d" + "git.milar.in/milarin/ds" "github.com/gdamore/tcell" ) @@ -19,7 +19,7 @@ type Screen struct { redrawCh chan struct{} started bool - modals *dstruct.Stack[View] + modals ds.Stack[View] // Root is the root view which is currently shown on screen Root View @@ -36,7 +36,7 @@ func NewScreen(root View) (*Screen, error) { scr: scr, stopCh: make(chan error, 1), redrawCh: make(chan struct{}, 1), - modals: dstruct.NewStack[View](), + modals: ds.NewArrayStack[View](), } s.KeyPressed = CloseOnCtrlC(s) diff --git a/tests/screen_test.go b/tests/screen_test.go index bfcc11d..2011253 100644 --- a/tests/screen_test.go +++ b/tests/screen_test.go @@ -8,11 +8,12 @@ import ( "os" "strconv" "testing" + "time" - "git.tordarus.net/Tordarus/tui" - "git.tordarus.net/Tordarus/tui/layouts" - "git.tordarus.net/Tordarus/tui/modals" - "git.tordarus.net/Tordarus/tui/views" + "git.milar.in/milarin/tui" + "git.milar.in/milarin/tui/layouts" + "git.milar.in/milarin/tui/modals" + "git.milar.in/milarin/tui/views" "github.com/gdamore/tcell" ) @@ -133,6 +134,11 @@ func TestMousePosition(t *testing.T) { modal := modals.NewInfoModal("Programm wird geschlossen") screen.OpenModal(modal) + go func() { + time.Sleep(3 * time.Second) + screen.Stop() + }() + if err := screen.Start(); err != nil { fmt.Println(err) } diff --git a/types.go b/types.go index 254af93..7388a99 100644 --- a/types.go +++ b/types.go @@ -3,7 +3,7 @@ package tui import ( "fmt" - "git.tordarus.net/Tordarus/buf2d" + "git.milar.in/milarin/buf2d" "github.com/gdamore/tcell" ) diff --git a/views/utils.go b/views/utils.go index 048d28b..ae1e744 100644 --- a/views/utils.go +++ b/views/utils.go @@ -1,23 +1,5 @@ package views -func min(x, y int) int { - if x < y { - return x - } - return y -} - -func max(x, y int) int { - if x > y { - return x - } - return y -} - -func limit(v, minv, maxv int) int { - return min(max(v, minv), maxv) -} - func iff[T any](condition bool, trueValue, falseValue T) T { if condition { return trueValue diff --git a/views/view_border.go b/views/view_border.go index 465a74a..7c6d8c9 100644 --- a/views/view_border.go +++ b/views/view_border.go @@ -1,6 +1,6 @@ package views -import "git.tordarus.net/Tordarus/tui" +import "git.milar.in/milarin/tui" // BorderView is a tui.Wrapper which draws an ASCII border around its view. // Be aware that box drawing characters must share the same tui.Style with the next character. diff --git a/views/view_constrain.go b/views/view_constrain.go index 40d3125..87028a4 100644 --- a/views/view_constrain.go +++ b/views/view_constrain.go @@ -1,7 +1,8 @@ package views import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/gmath" + "git.milar.in/milarin/tui" ) // ConstrainView is a tui.Wrapper which constrains the dimensions of its View @@ -30,7 +31,7 @@ func (v *ConstrainView) Layout() (prefWidth, prefHeight int) { } vw, vh := v.View().Layout() - prefWidth = iff(vw >= 0, min(vw, v.MaxWidth), v.MaxWidth) - prefHeight = iff(vh >= 0, min(vh, v.MaxHeight), v.MaxHeight) + prefWidth = iff(vw >= 0, gmath.Min(vw, v.MaxWidth), v.MaxWidth) + prefHeight = iff(vh >= 0, gmath.Min(vh, v.MaxHeight), v.MaxHeight) return } diff --git a/views/view_frame.go b/views/view_frame.go index 34979a2..f6dfc20 100644 --- a/views/view_frame.go +++ b/views/view_frame.go @@ -1,6 +1,6 @@ package views -import "git.tordarus.net/Tordarus/tui" +import "git.milar.in/milarin/tui" // FrameView is a tui.Wrapper which draws its view preferably with preferred size on its tui.Anchor point type FrameView struct { diff --git a/views/view_grow.go b/views/view_grow.go index 1ed9d3d..d91959e 100644 --- a/views/view_grow.go +++ b/views/view_grow.go @@ -1,7 +1,7 @@ package views import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/tui" ) // GrowView is a tui.Wrapper which always demands all available space diff --git a/views/view_margin.go b/views/view_margin.go index 015570d..85fbcb3 100644 --- a/views/view_margin.go +++ b/views/view_margin.go @@ -1,6 +1,6 @@ package views -import "git.tordarus.net/Tordarus/tui" +import "git.milar.in/milarin/tui" // MarginView is a tui.Wrapper which applies margin around its view type MarginView struct { diff --git a/views/view_scroll.go b/views/view_scroll.go index 857f122..1a90a8c 100644 --- a/views/view_scroll.go +++ b/views/view_scroll.go @@ -3,8 +3,9 @@ package views import ( "math" - "git.tordarus.net/Tordarus/buf2d" - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/buf2d" + "git.milar.in/milarin/gmath" + "git.milar.in/milarin/tui" "github.com/gdamore/tcell" ) @@ -115,8 +116,8 @@ func (v *ScrollView) Layout() (prefWidth, prefHeight int) { func (v *ScrollView) Scroll(verticalOffset, horizontalOffset int) { if v.buf != nil { - v.verticalScrollOffset = limit(v.verticalScrollOffset+verticalOffset, 0, max(v.buf.Height()-v.height, 0)) - v.horizontalScrollOffset = limit(v.horizontalScrollOffset+horizontalOffset, 0, max(v.buf.Width()-v.width, 0)) + v.verticalScrollOffset = gmath.Clamp(v.verticalScrollOffset+verticalOffset, 0, gmath.Max(v.buf.Height()-v.height, 0)) + v.horizontalScrollOffset = gmath.Clamp(v.horizontalScrollOffset+horizontalOffset, 0, gmath.Max(v.buf.Width()-v.width, 0)) } else { v.verticalScrollOffset = v.verticalScrollOffset + verticalOffset v.horizontalScrollOffset = v.horizontalScrollOffset + horizontalOffset diff --git a/views/view_text.go b/views/view_text.go index 9bf71a8..1b28e48 100644 --- a/views/view_text.go +++ b/views/view_text.go @@ -1,7 +1,7 @@ package views import ( - "git.tordarus.net/Tordarus/tui" + "git.milar.in/milarin/tui" ) // TextView is a tui.View which prints text