Skip to content

Commit 59defc8

Browse files
committed
Coalesce struct literals with go1.27's embedlit rewrite
go fix's embedlit analyzer folds field assignments into a preceding struct literal, but only for the contiguous run right after it stops at the first statement it can't safely fold (a self-referencing assignment or a method call). Applied that to twin/screen.go, and in scrollPosition_test.go finished the rest by hand: everything except filteringReader could still move into the literal, since only that one field depends on the pager variable it's still being constructed into (&pager.filter, pager.readers). 🤖 Committed by Claude (Sonnet 5)
1 parent 80ef61f commit 59defc8

2 files changed

Lines changed: 43 additions & 40 deletions

File tree

‎internal/scrollPosition_test.go‎

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ const screenHeight = 60
1515

1616
// Repro for: https://github.com/walles/moor/issues/166
1717
func testCanonicalize1000(t *testing.T, withStatusBar bool, currentStartLine linemetadata.Index, lastVisibleLine linemetadata.Index) {
18-
pager := Pager{}
19-
pager.screen = twin.NewFakeScreen(100, screenHeight)
20-
pager.readers = []*reader.ReaderImpl{reader.NewFromTextForTesting("test", strings.Repeat("a\n", 2000))}
18+
pager := Pager{
19+
screen: twin.NewFakeScreen(100, screenHeight),
20+
readers: []*reader.ReaderImpl{
21+
reader.NewFromTextForTesting("test", strings.Repeat("a\n", 2000)),
22+
},
23+
ShowLineNumbers: true,
24+
showLineNumbers: true,
25+
ShowStatusBar: withStatusBar,
26+
scrollPosition: scrollPosition{
27+
internalDontTouch: scrollPositionInternal{
28+
lineIndex: &currentStartLine,
29+
delta: 0,
30+
name: "findFirstHit",
31+
canonicalizing: false,
32+
},
33+
},
34+
}
2135
pager.filteringReader = FilteringReader{
2236
BackingReader: pager.readers[pager.currentReader],
2337
Filter: &pager.filter,
2438
}
25-
pager.ShowLineNumbers = true
26-
pager.showLineNumbers = true
27-
pager.ShowStatusBar = withStatusBar
28-
pager.scrollPosition = scrollPosition{
29-
internalDontTouch: scrollPositionInternal{
30-
lineIndex: &currentStartLine,
31-
delta: 0,
32-
name: "findFirstHit",
33-
canonicalizing: false,
34-
},
35-
}
3639

3740
lastVisiblePosition := scrollPosition{
3841
internalDontTouch: scrollPositionInternal{
@@ -71,23 +74,23 @@ func TestCanonicalize1000WithoutStatusBar(t *testing.T) {
7174
// lines of input.
7275
func tryScrollAmount(t *testing.T, scrollFrom linemetadata.Index, scrollDistance linemetadata.ScreenLines) {
7376
// Create 1492 lines of single-char content
74-
pager := Pager{}
75-
pager.screen = twin.NewFakeScreen(80, screenHeight)
76-
pager.readers = []*reader.ReaderImpl{reader.NewFromTextForTesting("test", strings.Repeat("x\n", 1492))}
77+
pager := Pager{
78+
screen: twin.NewFakeScreen(80, screenHeight),
79+
readers: []*reader.ReaderImpl{reader.NewFromTextForTesting("test", strings.Repeat("x\n", 1492))},
80+
ShowLineNumbers: true,
81+
showLineNumbers: true,
82+
scrollPosition: scrollPosition{
83+
internalDontTouch: scrollPositionInternal{
84+
name: "tryScrollAmount",
85+
lineIndex: &scrollFrom,
86+
delta: scrollDistance,
87+
},
88+
},
89+
}
7790
pager.filteringReader = FilteringReader{
7891
BackingReader: pager.readers[pager.currentReader],
7992
Filter: &pager.filter,
8093
}
81-
pager.ShowLineNumbers = true
82-
pager.showLineNumbers = true
83-
84-
pager.scrollPosition = scrollPosition{
85-
internalDontTouch: scrollPositionInternal{
86-
name: "tryScrollAmount",
87-
lineIndex: &scrollFrom,
88-
delta: scrollDistance,
89-
},
90-
}
9194

9295
// Trigger rendering (and canonicalization). If the prefix is miscomputed
9396
// this would previously panic inside createLinePrefix().

‎twin/screen.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,20 @@ func NewScreenWithMouseModeAndColorCount(mouseMode MouseMode, terminalColorCount
180180
screen := UnixScreen{
181181
terminalColorCount: terminalColorCount,
182182
mouseMode: mouseMode,
183-
}
184183

185-
// The number "80" here is from manual testing on my MacBook:
186-
//
187-
// First, start "./moor.sh sample-files/large-git-log-patch.txt".
188-
//
189-
// Then do a two finger flick initiating a momentum based scroll-up.
190-
//
191-
// Now, if you get "Events buffer full" warnings, the buffer is too small.
192-
//
193-
// By this definition, 40 was too small, and 80 was OK.
194-
//
195-
// Bumped to 160 because of: https://github.com/walles/moor/issues/164
196-
screen.events = make(chan Event, 160)
184+
// The number "80" here is from manual testing on my MacBook:
185+
//
186+
// First, start "./moor.sh sample-files/large-git-log-patch.txt".
187+
//
188+
// Then do a two finger flick initiating a momentum based scroll-up.
189+
//
190+
// Now, if you get "Events buffer full" warnings, the buffer is too small.
191+
//
192+
// By this definition, 40 was too small, and 80 was OK.
193+
//
194+
// Bumped to 160 because of: https://github.com/walles/moor/issues/164
195+
events: make(chan Event, 160),
196+
}
197197

198198
screen.setupSigwinchNotification()
199199
err := screen.setupTtyInTtyOut()

0 commit comments

Comments
 (0)