Skip to content

Commit 72ed805

Browse files
committed
Merge branch 'johan/back-to-go-1.25'
Fixes: #459
2 parents b01e25c + 54f6139 commit 72ed805

75 files changed

Lines changed: 230 additions & 4227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmd/moor/alt-screen_test.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"testing"
1111

1212
"gotest.tools/v3/assert"
13+
14+
"github.com/walles/moor/v2/internal/ptr"
1315
)
1416

1517
// Paging input that doesn't fit on one screen happens on the alternate screen,
@@ -19,7 +21,7 @@ func TestLongInputUsesAlternateScreen(t *testing.T) {
1921
t.Run(fmt.Sprintf("fromPipe=%t", fromPipe), func(t *testing.T) {
2022
options := moorOptions{answerBackgroundQuery: true}
2123
if fromPipe {
22-
options.stdin = new(textLines(100))
24+
options.stdin = ptr.To(textLines(100))
2325
} else {
2426
options.args = []string{createTextFile(t, 100)}
2527
}
@@ -118,7 +120,7 @@ func TestQuitIfOneScreenNeverEntersAlternateScreen(t *testing.T) {
118120
args: []string{"--quit-if-one-screen"},
119121
}
120122
if fromPipe {
121-
options.stdin = new("hello world 1\nhello world 2\n")
123+
options.stdin = ptr.To("hello world 1\nhello world 2\n")
122124
} else {
123125
options.args = append(options.args, createTextFile(t, 2))
124126
}
@@ -168,7 +170,7 @@ func TestQuitIfOneScreenNeverEntersAlternateScreenWhenHighlighted(t *testing.T)
168170
args: []string{"--quit-if-one-screen"},
169171
}
170172
if fromPipe {
171-
options.stdin = new(jsonLines(lineCount, marker))
173+
options.stdin = ptr.To(jsonLines(lineCount, marker))
172174
} else {
173175
options.args = append(options.args, createSourceFile(t, lineCount, marker))
174176
}

‎cmd/moor/moor.go‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import (
2121
log "github.com/sirupsen/logrus"
2222
"golang.org/x/term"
2323

24+
"github.com/walles/twin"
25+
2426
"github.com/walles/moor/v2/internal"
2527
"github.com/walles/moor/v2/internal/linemetadata"
28+
"github.com/walles/moor/v2/internal/ptr"
2629
"github.com/walles/moor/v2/internal/reader"
2730
"github.com/walles/moor/v2/internal/textstyles"
2831
"github.com/walles/moor/v2/internal/util"
29-
"github.com/walles/moor/v2/twin"
3032
)
3133

3234
var versionString = ""
@@ -357,7 +359,7 @@ func getVersion() string {
357359
// Can return a nil pager on --help or --version, or if pumping to stdout.
358360
func pagerFromArgs(
359361
args []string,
360-
newScreen func(mouseMode twin.MouseMode, terminalColorCount twin.ColorCount) (twin.Screen, error),
362+
newScreen func(options twin.Options) (twin.Screen, error),
361363
stdinIsRedirected bool,
362364
stdoutIsRedirected bool,
363365
) (
@@ -579,7 +581,11 @@ func pagerFromArgs(
579581

580582
// We got the first byte, this means sudo is done (if it was used) and we
581583
// can set up the UI.
582-
screen, err := newScreen(*mouseMode, *terminalColorsCount)
584+
screen, err := newScreen(twin.Options{
585+
MouseMode: *mouseMode,
586+
TerminalColorCount: *terminalColorsCount,
587+
Logger: &util.TwinLogger{},
588+
})
583589
if err != nil {
584590
// Ref: https://github.com/walles/moor/issues/149
585591
log.Info("Failed to set up screen for paging, pumping to stdout instead: ", err)
@@ -628,7 +634,7 @@ func pagerFromArgs(
628634

629635
pager.TargetLine = targetLine
630636
if *follow && pager.TargetLine == nil {
631-
pager.TargetLine = new(linemetadata.IndexMax())
637+
pager.TargetLine = ptr.To(linemetadata.IndexMax())
632638
}
633639

634640
return pager, screen, style, &formatter, logsRequested, nil
@@ -638,7 +644,6 @@ func main() {
638644
var loglines internal.LogWriter
639645
logsRequested := false
640646
log.SetOutput(&loglines)
641-
twin.SetLogger(&util.TwinLogger{})
642647
russiaNotSupported()
643648

644649
defer func() {
@@ -673,7 +678,7 @@ func main() {
673678

674679
pager, screen, style, formatter, _logsRequested, err := pagerFromArgs(
675680
os.Args,
676-
twin.NewScreenWithMouseModeAndColorCount,
681+
twin.NewScreen,
677682
stdinIsRedirected,
678683
stdoutIsRedirected,
679684
)

‎cmd/moor/moor_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/walles/moor/v2/internal/textstyles"
7-
"github.com/walles/moor/v2/twin"
7+
"github.com/walles/twin"
88
"gotest.tools/v3/assert"
99
)
1010

@@ -31,7 +31,7 @@ func TestUnescapeManPn(t *testing.T) {
3131
func TestPageOneInputFile(t *testing.T) {
3232
pager, screen, _, formatter, _, err := pagerFromArgs(
3333
[]string{"", "moor_test.go"},
34-
func(_ twin.MouseMode, _ twin.ColorCount) (twin.Screen, error) {
34+
func(_ twin.Options) (twin.Screen, error) {
3535
return twin.NewFakeScreen(80, 24), nil
3636
},
3737
false, // stdin is redirected

‎cmd/moor/plusparser.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/walles/moor/v2/internal/linemetadata"
8+
"github.com/walles/moor/v2/internal/ptr"
89
)
910

1011
// Parses arguments starting with '+':
@@ -59,13 +60,13 @@ func parseLineNumber(withoutPlus string) *linemetadata.Index {
5960
lineNumber = 1
6061
}
6162

62-
return new(linemetadata.IndexFromOneBased(int(lineNumber)))
63+
return ptr.To(linemetadata.IndexFromOneBased(int(lineNumber)))
6364
}
6465

6566
func parseSearchPattern(withoutPlus string) *string {
6667
if !strings.HasPrefix(withoutPlus, "/") {
6768
return nil
6869
}
6970

70-
return new(withoutPlus[1:])
71+
return ptr.To(withoutPlus[1:])
7172
}

‎cmd/moor/usage.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
log "github.com/sirupsen/logrus"
1414
"github.com/walles/moor/v2/internal"
15-
"github.com/walles/moor/v2/twin"
15+
"github.com/walles/twin"
1616
)
1717

1818
func renderLessTermcapEnvVar(envVarName string, description string, colors twin.ColorCount) string {

‎go.mod‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module github.com/walles/moor/v2
22

3-
go 1.27.0
3+
// Go version policy: No newer than the most recently end-of-lifed Go release,
4+
// so distro packagers building from source aren't forced onto a toolchain their
5+
// repos don't have yet.
6+
//
7+
// Once this reaches 1.26, the whole internal/ptr package can be replaced with
8+
// Go's builtin new(expr) instead.
9+
go 1.25.0
410

511
require (
612
github.com/adrg/xdg v0.5.3
@@ -14,13 +20,13 @@ require (
1420
github.com/rivo/uniseg v0.4.7
1521
github.com/sirupsen/logrus v1.9.4
1622
github.com/ulikunitz/xz v0.5.16
17-
golang.org/x/sync v0.22.0
18-
golang.org/x/sys v0.47.0
23+
github.com/walles/twin v0.9.1
1924
golang.org/x/term v0.45.0
2025
gotest.tools/v3 v3.5.2
2126
)
2227

2328
require (
2429
github.com/dlclark/regexp2 v1.11.5 // indirect
2530
github.com/go-enry/go-oniguruma v1.2.1 // indirect
31+
golang.org/x/sys v0.47.0 // indirect
2632
)

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4141
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4242
github.com/ulikunitz/xz v0.5.16 h1:ld6NyySjx5lowVKwJvMRLnW5nxKX/xnpSiFYZ/Lxur0=
4343
github.com/ulikunitz/xz v0.5.16/go.mod h1:H9Rt/W6/Qj27PGauhQc6nfCDy7vHpzsOThBSaYDoEhw=
44-
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
45-
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
44+
github.com/walles/twin v0.9.1 h1:FhokRh6EXTd8TwmrH6xf60czQ+J1T+6wL7xdGg3PGWU=
45+
github.com/walles/twin v0.9.1/go.mod h1:3iGyRE6bnLVsQuIPMyW2i1YXe6e9VDjGHcAGOHi/mcA=
4646
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
4747
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
4848
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=

‎internal/detectManPage_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
log "github.com/sirupsen/logrus"
88
"github.com/walles/moor/v2/internal/reader"
9-
"github.com/walles/moor/v2/twin"
9+
"github.com/walles/twin"
1010
"gotest.tools/v3/assert"
1111
)
1212

‎internal/editor.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"strings"
1111

1212
log "github.com/sirupsen/logrus"
13+
1314
"github.com/walles/moor/v2/internal/linemetadata"
15+
"github.com/walles/moor/v2/internal/ptr"
1416
"github.com/walles/moor/v2/internal/reader"
1517
)
1618

@@ -118,7 +120,7 @@ func middleVisibleLine(p *Pager) *linemetadata.Index {
118120
return nil
119121
}
120122

121-
return new(lines[len(lines)/2].inputLineIndex)
123+
return ptr.To(lines[len(lines)/2].inputLineIndex)
122124
}
123125

124126
// check if the editor can accept "+LINENUMBER" argument

‎internal/file-switching_test.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"strings"
55
"testing"
66

7+
"github.com/walles/twin"
8+
"gotest.tools/v3/assert"
9+
710
"github.com/walles/moor/v2/internal/linemetadata"
11+
"github.com/walles/moor/v2/internal/ptr"
812
"github.com/walles/moor/v2/internal/reader"
9-
"github.com/walles/moor/v2/twin"
10-
"gotest.tools/v3/assert"
1113
)
1214

1315
func TestIssue426SwitchingToSmallerFileClearsStaleScrollPosition(t *testing.T) {
@@ -27,7 +29,7 @@ func TestIssue426SwitchingToSmallerFileClearsStaleScrollPosition(t *testing.T) {
2729
// moved to a shorter file, but the scroll position still points below it.
2830
pager.scrollPosition = scrollPosition{
2931
internalDontTouch: scrollPositionInternal{
30-
lineIndex: new(linemetadata.IndexFromZeroBased(70)),
32+
lineIndex: ptr.To(linemetadata.IndexFromZeroBased(70)),
3133
delta: 0,
3234
name: "Issue 426 stale file switch",
3335
},

0 commit comments

Comments
 (0)