migrated to milar.in

This commit is contained in:
milarin 2023-04-24 11:55:04 +02:00
parent 2dbd0cc15e
commit 109e2a9efd
19 changed files with 59 additions and 85 deletions

9
go.mod
View File

@ -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
)

14
go.sum
View File

@ -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=

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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++
}

View File

@ -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
}

View File

@ -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)

View File

@ -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)
}

View File

@ -3,7 +3,7 @@ package tui
import (
"fmt"
"git.tordarus.net/Tordarus/buf2d"
"git.milar.in/milarin/buf2d"
"github.com/gdamore/tcell"
)

View File

@ -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

View File

@ -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.

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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