Skip to content
Myr

Replace utils Min, Max with builtin min, max

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Marcel Meyer · committed by Junegunn Choi · parent 6032401 · Browse files · 13 files+93 added−196 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

13 files+93 added−196 removed

  • other:+93 added−196 removed

13 files+93 added−196 removed

modified:src/algo/algo_test.go+1 added-1 removed
84 unmodified lines
85 scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+bonusCamel123*2+86 scoreGapStart*2+scoreGapExtension*2)87 assertMatch(t, fn, true, forward, "FooBar Baz", "FooB", 0, 4,88 scoreMatch*4+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite)*2+89 util.Max(bonusCamel123, int(bonusBoundaryWhite)))89 max(bonusCamel123, int(bonusBoundaryWhite)))9091 // Consecutive bonus updated92 assertMatch(t, fn, true, forward, "foo-bar", "o-ba", 2, 6,93 scoreMatch*4+bonusBoundary*3)
118 unmodified lines
modified:src/algo/algo.go+6 added-6 removed
501 unmodified lines
502 if char == pchar {503 if pidx < M {504 F[pidx] = int32(off)505 pidx++506 pchar = pattern[util.Min(pidx, M-1)]506 pchar = pattern[min(pidx, M-1)]507 }508 lastIdx = off509 }510
9 unmodified lines
520 }521 inGap = false522 } else {523 if inGap {524 H0[off] = util.Max16(prevH0+scoreGapExtension, 0)524 H0[off] = max(prevH0+scoreGapExtension, 0)525 } else {526 H0[off] = util.Max16(prevH0+scoreGapStart, 0)526 H0[off] = max(prevH0+scoreGapStart, 0)527 }528 C0[off] = 0529 inGap = true530 }
57 unmodified lines
588 // Break consecutive chunk589 if b >= bonusBoundary && b > fb {590 consecutive = 1591 } else {592 b = util.Max16(b, util.Max16(bonusConsecutive, fb))592 b = max(b, max(bonusConsecutive, fb))593 }594 }595 if s1+b < s2 {596 s1 += Bsub[off]
4 unmodified lines
601 }602 Csub[off] = consecutive603604 inGap = s1 < s2605 score := util.Max16(util.Max16(s1, s2), 0)605 score := max(max(s1, s2), 0)606 if pidx == M-1 && (forward && score > maxScore || !forward && score >= maxScore) {607 maxScore, maxScorePos = score, col608 }609 Hsub[off] = score
75 unmodified lines
685 // Break consecutive chunk686 if bonus >= bonusBoundary && bonus > firstBonus {687 firstBonus = bonus688 }689 bonus = util.Max16(util.Max16(bonus, firstBonus), bonusConsecutive)689 bonus = max(max(bonus, firstBonus), bonusConsecutive)690 }691 if pidx == 0 {692 score += int(bonus * bonusFirstCharMultiplier)693 } else {
341 unmodified lines
modified:src/tui/light.go+2 added-2 removed
1031 unmodified lines
1032 return r.height1033}10341035func (r *LightRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window {1036 width = util.Max(0, width)1037 height = util.Max(0, height)1036 width = max(0, width)1037 height = max(0, height)1038 w := &LightWindow{1039 renderer: r,1040 colored: r.theme.Colored,1041 windowType: windowType,
464 unmodified lines
modified:src/tui/tcell.go+2 added-2 removed
727 unmodified lines
728 _screen.Show()729}730731func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window {732 width = util.Max(0, width)733 height = util.Max(0, height)732 width = max(0, width)733 height = max(0, height)734 normal := ColBorder735 switch windowType {736 case WindowList:737 normal = ColNormal
329 unmodified lines
modified:src/util/chars.go+1 added-1 removed
185 unmodified lines
186187func (chars *Chars) TrimTrailingWhitespaces(maxIndex int) {188 whitespaces := chars.TrailingWhitespaces()189 end := len(chars.slice) - whitespaces190 chars.slice = chars.slice[0:Max(end, maxIndex)]190 chars.slice = chars.slice[0:max(end, maxIndex)]191}192193func (chars *Chars) TrimSuffix(runes []rune) {194 lastIdx := len(chars.slice)
141 unmodified lines
modified:src/util/util_test.go-63 removed
5 unmodified lines
6 "testing"7 "time"8)910func TestMax(t *testing.T) {11 if Max(10, 1) != 10 {12 t.Error("Expected", 10)13 }14 if Max(-2, 5) != 5 {15 t.Error("Expected", 5)16 }17}1819func TestMax16(t *testing.T) {20 if Max16(10, 1) != 10 {21 t.Error("Expected", 10)22 }23 if Max16(-2, 5) != 5 {24 t.Error("Expected", 5)25 }26 if Max16(math.MaxInt16, 0) != math.MaxInt16 {27 t.Error("Expected", math.MaxInt16)28 }29 if Max16(0, math.MinInt16) != 0 {30 t.Error("Expected", 0)31 }32}3334func TestMax32(t *testing.T) {35 if Max32(10, 1) != 10 {36 t.Error("Expected", 10)37 }38 if Max32(-2, 5) != 5 {39 t.Error("Expected", 5)40 }41 if Max32(math.MaxInt32, 0) != math.MaxInt32 {42 t.Error("Expected", math.MaxInt32)43 }44 if Max32(0, math.MinInt32) != 0 {45 t.Error("Expected", 0)46 }47}4849func TestMin(t *testing.T) {50 if Min(10, 1) != 1 {51 t.Error("Expected", 1)52 }53 if Min(-2, 5) != -2 {54 t.Error("Expected", -2)55 }56}5758func TestMin32(t *testing.T) {59 if Min32(10, 1) != 1 {60 t.Error("Expected", 1)61 }62 if Min32(-2, 5) != -2 {63 t.Error("Expected", -2)64 }65 if Min32(math.MaxInt32, 0) != 0 {66 t.Error("Expected", 0)67 }68 if Min32(0, math.MinInt32) != math.MinInt32 {69 t.Error("Expected", math.MinInt32)70 }71}7210func TestConstrain(t *testing.T) {11 if Constrain(-3, -1, 3) != -1 {12 t.Error("Expected", -1)13 }
166 unmodified lines
modified:src/util/util.go+5 added-45 removed
53 unmodified lines
54 }55 return runes, width56}5758// Max returns the largest integer59func Max(first int, second int) int {60 if first >= second {61 return first62 }63 return second64}6566// Max16 returns the largest integer67func Max16(first int16, second int16) int16 {68 if first >= second {69 return first70 }71 return second72}7374// Max32 returns the largest 32-bit integer75func Max32(first int32, second int32) int32 {76 if first > second {77 return first78 }79 return second80}8182// Min returns the smallest integer83func Min(first int, second int) int {84 if first <= second {85 return first86 }87 return second88}8990// Min32 returns the smallest 32-bit integer91func Min32(first int32, second int32) int32 {92 if first <= second {93 return first94 }95 return second96}9758// Constrain32 limits the given 32-bit integer with the upper and lower bounds99func Constrain32(val int32, min int32, max int32) int32 {100 return Max32(Min32(val, max), min)59func Constrain32(val int32, minimum int32, maximum int32) int32 {60 return max(min(val, maximum), minimum)61}6263// Constrain limits the given integer with the upper and lower bounds104func Constrain(val int, min int, max int) int {105 return Max(Min(val, max), min)64func Constrain(val int, minimum int, maximum int) int {65 return max(min(val, maximum), minimum)66}6768func AsUint16(val int) uint16 {69 if val > math.MaxUint16 {
86 unmodified lines
156 }157 return n158 }159200 for i := 0; i < Max(len(parts1), len(parts2)); i++ {160 for i := 0; i < max(len(parts1), len(parts2)); i++ {161 var p1, p2 int162 if i < len(parts1) {163 p1 = atoi(parts1[i])164 }
12 unmodified lines
modified:src/core.go+2 added-2 removed
157 unmodified lines
158 var maxColorOffset int32159 if item.colors != nil {160 for _, ansi := range *item.colors {161 if ansi.color.bg >= 0 {162 maxColorOffset = util.Max32(maxColorOffset, ansi.offset[1])162 maxColorOffset = max(maxColorOffset, ansi.offset[1])163 }164 }165 }166 item.text.TrimTrailingWhitespaces(int(maxColorOffset))
165 unmodified lines
332 if heightUnknown {333 if total >= maxFit || final {334 deferred = false335 heightUnknown = false336 terminal.startChan <- fitpad{util.Min(total, maxFit), padHeight}336 terminal.startChan <- fitpad{min(total, maxFit), padHeight}337 }338 } else if deferred {339 deferred = false340 terminal.startChan <- fitpad{-1, -1}
200 unmodified lines
modified:src/matcher.go+1 added-1 removed
53 unmodified lines
5455// NewMatcher returns a new Matcher56func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern,57 sort bool, tac bool, eventBox *util.EventBox, revision revision) *Matcher {58 partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)58 partitions := min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)59 return &Matcher{60 cache: cache,61 patternBuilder: patternBuilder,62 sort: sort,
212 unmodified lines
modified:src/reader.go+1 added-1 removed
176 unmodified lines
177 leftover := []byte{}178 var err error179 for {180 n := 0181 scope := slab[:util.Min(len(slab), readerBufferSize)]181 scope := slab[:min(len(slab), readerBufferSize)]182 for range 100 {183 n, err = src.Read(scope)184 if n > 0 || err != nil {185 break
188 unmodified lines
modified:src/result.go+3 added-3 removed
40 unmodified lines
41 validOffsetFound := false42 for _, offset := range offsets {43 b, e := int(offset[0]), int(offset[1])44 if b < e {45 minBegin = util.Min(b, minBegin)46 minEnd = util.Min(e, minEnd)47 maxEnd = util.Max(e, maxEnd)45 minBegin = min(b, minBegin)46 minEnd = min(e, minEnd)47 maxEnd = max(e, maxEnd)48 validOffsetFound = true49 }50 }51
285 unmodified lines
modified:src/terminal.go+68 added-68 removed
898 unmodified lines
899 if opts.Height.percent {900 if opts.Height.inverse {901 size = 100 - size902 }903 return util.Max(int(size*float64(termHeight)/100.0), opts.MinHeight)903 return max(int(size*float64(termHeight)/100.0), opts.MinHeight)904 }905 if opts.Height.inverse {906 size = float64(termHeight) - size907 }
47 unmodified lines
955 if opts.noSeparatorLine() {956 effectiveMinHeight--957 }958 effectiveMinHeight += borderLines(opts.BorderShape)959 return util.Min(termHeight, util.Max(evaluateHeight(opts, termHeight), effectiveMinHeight))959 return min(termHeight, max(evaluateHeight(opts, termHeight), effectiveMinHeight))960 }961 renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc)962 }963 if err != nil {
188 unmodified lines
1152 if t.pointerLen == 0 {1153 t.pointerEmpty = ""1154 t.pointerEmptyRaw = ""1155 } else {1156 t.pointerEmpty = gutterChar + strings.Repeat(" ", util.Max(0, t.pointerLen-1))1157 t.pointerEmptyRaw = gutterRawChar + strings.Repeat(" ", util.Max(0, t.pointerLen-1))1156 t.pointerEmpty = gutterChar + strings.Repeat(" ", max(0, t.pointerLen-1))1157 t.pointerEmptyRaw = gutterRawChar + strings.Repeat(" ", max(0, t.pointerLen-1))1158 }1159 t.markerEmpty = strings.Repeat(" ", t.markerLen)11601161 // Labels
186 unmodified lines
1348 env = append(env, fmt.Sprintf("FZF_MATCH_COUNT=%d", t.resultMerger.Length()))1349 env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected)))1350 env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines))1351 env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))1352 env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1)))1352 env = append(env, fmt.Sprintf("FZF_POS=%d", min(t.merger.Length(), t.cy+1)))1353 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))1354 env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))1355 env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_LINE=%d", t.clickFooterLine))1356 env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_COLUMN=%d", t.clickFooterColumn))
228 unmodified lines
1585func getScrollbar(perLine int, total int, height int, offset int) (int, int) {1586 if total == 0 || total*perLine <= height {1587 return 0, 01588 }1589 barLength := util.Max(1, height*height/(total*perLine))1589 barLength := max(1, height*height/(total*perLine))1590 var barStart int1591 if total == height {1592 barStart = 01593 } else {1594 barStart = util.Min(height-barLength, (height*perLine-barLength)*offset/(total*perLine-height))1594 barStart = min(height-barLength, (height*perLine-barLength)*offset/(total*perLine-height))1595 }1596 return barLength, barStart1597}1598
7 unmodified lines
1606func (t *Terminal) wrapCols() int {1607 if !t.wrap {1608 return 0 // No wrap1609 }1610 return util.Max(t.window.Width()-(t.pointerLen+t.markerLen+t.barCol()), 1)1610 return max(t.window.Width()-(t.pointerLen+t.markerLen+t.barCol()), 1)1611}16121613func (t *Terminal) clearNumLinesCache() {1614 t.numLinesCache = make(map[int32]numLinesCacheValue)
46 unmodified lines
1661 maxItems := t.maxItems()1662 numLines := 01663 count := 01664 total := t.merger.Length()1665 offset := util.Max(0, util.Min(t.offset, total-maxItems-1))1665 offset := max(0, min(t.offset, total-maxItems-1))1666 for idx := 0; idx < maxItems && idx+offset < total; idx++ {1667 result := t.merger.Get(idx + offset)1668 lines, _ := t.numItemLines(result.item, maxItems)1669 numLines += lines
151 unmodified lines
1821 t.cy = pos1822 t.offset = 01823 } else if t.cy > count {1824 // Try to keep the vertical position when the list shrinks1825 t.cy = count - util.Min(count, t.maxItems()) + pos1825 t.cy = count - min(count, t.maxItems()) + pos1826 }1827 }1828 needActivation := false1829 if !t.reading {
156 unmodified lines
1986 }1987 marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx]1988 }19891990 adjust := func(idx1 int, idx2 int, max int, min int) {1991 if min > max {1992 min = max1990 adjust := func(idx1 int, idx2 int, maximum int, minimum int) {1991 if minimum > maximum {1992 minimum = maximum1993 }1994 margin := marginInt[idx1] + marginInt[idx2] + paddingInt[idx1] + paddingInt[idx2]1995 if max-margin < min {1996 desired := max - min1995 if maximum-margin < minimum {1996 desired := maximum - minimum1997 paddingInt[idx1] = desired * paddingInt[idx1] / margin1998 paddingInt[idx2] = desired * paddingInt[idx2] / margin1999 marginInt[idx1] = util.Max(extraMargin[idx1], desired*marginInt[idx1]/margin)2000 marginInt[idx2] = util.Max(extraMargin[idx2], desired*marginInt[idx2]/margin)1999 marginInt[idx1] = max(extraMargin[idx1], desired*marginInt[idx1]/margin)2000 marginInt[idx2] = max(extraMargin[idx2], desired*marginInt[idx2]/margin)2001 }2002 }20032004 minAreaWidth := minWidth
8 unmodified lines
2013 minPreviewWidth, minPreviewHeight := t.minPreviewSize(t.activePreviewOpts)2014 switch t.activePreviewOpts.position {2015 case posUp, posDown:2016 minAreaHeight += minPreviewHeight2017 minAreaWidth = util.Max(minPreviewWidth, minAreaWidth)2017 minAreaWidth = max(minPreviewWidth, minAreaWidth)2018 case posLeft, posRight:2019 minAreaWidth += minPreviewWidth2020 minAreaHeight = util.Max(minPreviewHeight, minAreaHeight)2020 minAreaHeight = max(minPreviewHeight, minAreaHeight)2021 }2022 }2023 adjust(1, 3, screenWidth, minAreaWidth)2024 adjust(0, 2, screenHeight, minAreaHeight)
465 unmodified lines
2490 if shape.HasRight() {2491 width++2492 }2493 // Make sure that the width does not exceed the list width2494 width = util.Min(t.window.Width()+t.headerIndentImpl(0, shape), width)2494 width = min(t.window.Width()+t.headerIndentImpl(0, shape), width)2495 height := b.Height() - borderLines(shape)2496 return t.tui.NewWindow(top, left, width, height, windowType, noBorder, true)2497 }2498
155 unmodified lines
2654 return2655 }2656 var col int2657 if opts.column == 0 {2658 col = util.Max(0, (window.Width()-length)/2)2658 col = max(0, (window.Width()-length)/2)2659 } else if opts.column < 0 {2660 col = util.Max(0, window.Width()+opts.column+1-length)2660 col = max(0, window.Width()+opts.column+1-length)2661 } else {2662 col = util.Min(opts.column-1, window.Width()-length)2662 col = min(opts.column-1, window.Width()-length)2663 }2664 row := 02665 if borderShape == tui.BorderBottom || opts.bottom {2666 row = window.Height() - 1
46 unmodified lines
2713 // We're limiting the length of the query not to make fzf unresponsive when2714 // the user accidentally pastes a huge chunk of text. Therefore, we're not2715 // interested in the exact display width of the query. We just limit the2716 // number of runes.2717 t.input = t.input[:util.Min(len(t.input), maxPatternLength)]2717 t.input = t.input[:min(len(t.input), maxPatternLength)]2718 t.cx = util.Constrain(t.cx, 0, len(t.input))2719}27202721func (t *Terminal) updatePromptOffset() ([]rune, []rune) {2722 w := t.window2723 if t.inputWindow != nil {2724 w = t.inputWindow2725 }2726 maxWidth := util.Max(1, w.Width()-t.promptLen-1)2726 maxWidth := max(1, w.Width()-t.promptLen-1)27272728 _, overflow := t.trimLeft(t.input[:t.cx], maxWidth, 0)2729 minOffset := int(overflow)2730 maxOffset := minOffset + (maxWidth-util.Max(0, maxWidth-t.cx))/22730 maxOffset := minOffset + (maxWidth-max(0, maxWidth-t.cx))/22731 t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset)2732 before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth, 0)2733 beforeLen := t.displayWidth(before)2734 after, _ := t.trimRight(t.input[t.cx:], maxWidth-beforeLen)
13 unmodified lines
2748 }2749 if !t.noSeparatorLine() {2750 max--2751 }2752 return util.Min(t.visibleHeaderLinesInList(), max)2752 return min(t.visibleHeaderLinesInList(), max)2753 }2754 return 02755}2756
6 unmodified lines
2763 y := t.inputWindow.Height() - 12764 if t.layout == layoutReverse {2765 y = 02766 }2767 x = util.Min(x, t.inputWindow.Width()-1)2767 x = min(x, t.inputWindow.Width()-1)2768 t.inputWindow.Move(y, x)2769 return2770 }2771 x = util.Min(x, t.window.Width()-1)2771 x = min(x, t.window.Width()-1)2772 t.move(t.promptLine(), x, false)2773}27742775func (t *Terminal) printPrompt() {
10 unmodified lines
2786 t.prompt()27872788 before, after := t.updatePromptOffset()2789 if len(before) == 0 && len(after) == 0 && len(t.ghost) > 0 {2790 maxWidth := util.Max(1, w.Width()-t.promptLen-1)2790 maxWidth := max(1, w.Width()-t.promptLen-1)2791 runes, _ := t.trimRight([]rune(t.ghost), maxWidth)2792 w.CPrint(tui.ColGhost, string(runes))2793 return2794 }
81 unmodified lines
2876 return2877 }28782879 found := t.resultMerger.Length()2880 total := util.Max(found, t.count)2880 total := max(found, t.count)2881 output := fmt.Sprintf("%d/%d", found, total)2882 if t.toggleSort {2883 if t.sort {2884 output += " +S"
85 unmodified lines
29702971 if t.infoStyle == infoInlineRight {2972 if len(t.infoPrefix) == 0 {2973 move(line, pos, false)2974 newPos := util.Max(pos, t.window.Width()-outputLen-3)2974 newPos := max(pos, t.window.Width()-outputLen-3)2975 t.window.Print(strings.Repeat(" ", newPos-pos))2976 pos = newPos2977 if pos < t.window.Width() {2978 printSpinner()
3 unmodified lines
2982 t.window.Print(" ")2983 pos++2984 }2985 } else {2986 pos = util.Max(pos, t.window.Width()-outputLen-util.StringWidth(t.infoPrefix)-1)2986 pos = max(pos, t.window.Width()-outputLen-util.StringWidth(t.infoPrefix)-1)2987 printInfoPrefix()2988 }2989 }2990
87 unmodified lines
3078 return3079 }3080 indentSize := t.headerIndent(t.footerBorderShape)3081 indent := strings.Repeat(" ", indentSize)3082 max := util.Min(len(t.footer), t.footerWindow.Height())3082 max := min(len(t.footer), t.footerWindow.Height())30833084 // Wrapping is not supported for footer3085 wrap := t.wrap3086 t.wrap = false
216 unmodified lines
3303 alt = index%2 == 03304 } else {3305 alt = index%2 == 13306 }3307 label = t.jumpLabels[index:index+1] + strings.Repeat(" ", util.Max(0, t.pointerLen-1))3307 label = t.jumpLabels[index:index+1] + strings.Repeat(" ", max(0, t.pointerLen-1))3308 if t.pointerLen == 0 {3309 extraWidth = 13310 }3311 }
161 unmodified lines
3473 return width3474}34753476func (t *Terminal) trimLeft(runes []rune, width int, ellipsisWidth int) ([]rune, int32) {3477 width = util.Max(0, width)3477 width = max(0, width)3478 var trimmed int323479 // Assume that each rune takes at least one column on screen3480 if len(runes) > width {3481 diff := len(runes) - width
82 unmodified lines
3564 // 0 | 1 | 2 | 3 | 4 | 53565 // ------> <------3566 if t.freezeLeft > 0 {3567 if len(tokens) > 0 {3568 token := tokens[util.Min(t.freezeLeft, len(tokens))-1]3568 token := tokens[min(t.freezeLeft, len(tokens))-1]3569 splitOffset1 = int(token.prefixLength) + token.text.Length() - token.text.TrailingWhitespaces()3570 }3571 }3572 if t.freezeRight > 0 {3573 index := util.Max(t.freezeLeft-1, len(tokens)-t.freezeRight-1)3573 index := max(t.freezeLeft-1, len(tokens)-t.freezeRight-1)3574 if index < 0 {3575 splitOffset2 = 03576 } else if index >= t.freezeLeft {3577 token := tokens[index]3578 delimiter := strings.TrimLeftFunc(GetLastDelimiter(token.text.ToString(), t.delimiter), unicode.IsSpace)3579 splitOffset2 = int(token.prefixLength) + token.text.Length() - len([]rune(delimiter))3580 }3581 splitOffset2 = util.Max(splitOffset2, splitOffset1)3581 splitOffset2 = max(splitOffset2, splitOffset1)3582 }3583 }35843585 maxLines := 1
81 unmodified lines
36673668 var maxEnd int3669 for _, offset := range offsets {3670 if offset.match {3671 maxEnd = util.Max(maxEnd, int(offset.offset[1]))3671 maxEnd = max(maxEnd, int(offset.offset[1]))3672 }3673 }36743675 actualLineNum := lineNum
90 unmodified lines
3766 adjustedMaxWidth -= ellipsisWidth3767 }3768 displayWidth = t.displayWidthWithLimit(runes, 0, adjustedMaxWidth)3769 if !t.wrap && displayWidth > adjustedMaxWidth {3770 maxe = util.Constrain(maxe+util.Min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))3770 maxe = util.Constrain(maxe+min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))3771 transformOffsets := func(diff int32, rightTrim bool) {3772 for idx, offset := range offs {3773 b, e := offset.offset[0], offset.offset[1]3774 el := int32(len(ellipsis))3775 b += el - diff3776 e += el - diff3777 b = util.Max32(b, el)3777 b = max(b, el)3778 if rightTrim {3779 e = util.Min32(e, int32(maxWidth-ellipsisWidth))3779 e = min(e, int32(maxWidth-ellipsisWidth))3780 }3781 offs[idx].offset[0] = b3782 offs[idx].offset[1] = util.Max32(b, e)3782 offs[idx].offset[1] = max(b, e)3783 }3784 }3785 if t.hscroll {3786 if fidx == 1 || fidx == 2 && t.keepRight && pos == nil {
23 unmodified lines
3810 runes, _ = t.trimRight(runes, maxWidth-ellipsisWidth)3811 runes = append(runes, ellipsis...)38123813 for idx, offset := range offs {3814 offs[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-len(ellipsis)))3815 offs[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth))3814 offs[idx].offset[0] = min(offset.offset[0], int32(maxWidth-len(ellipsis)))3815 offs[idx].offset[1] = min(offset.offset[1], int32(maxWidth))3816 }3817 }3818 displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth)3819 }
120 unmodified lines
3940 height := t.pwindow.Height()3941 body := t.previewer.lines3942 headerLines := t.activePreviewOpts.headerLines3943 // Do not enable preview header lines if it's value is too large3944 if headerLines > 0 && headerLines < util.Min(len(body), height) {3944 if headerLines > 0 && headerLines < min(len(body), height) {3945 header := t.previewer.lines[0:headerLines]3946 body = t.previewer.lines[headerLines:]3947 // Always redraw header3948 t.renderPreviewText(height, header, 0, false)
9 unmodified lines
3958 return3959 }39603961 effectiveHeight := height - headerLines3962 barLength, barStart := getScrollbar(1, len(body), effectiveHeight, util.Min(len(body)-effectiveHeight, t.previewer.offset-headerLines))3962 barLength, barStart := getScrollbar(1, len(body), effectiveHeight, min(len(body)-effectiveHeight, t.previewer.offset-headerLines))3963 t.renderPreviewScrollbar(headerLines, barLength, barStart)3964}39653966func (t *Terminal) makeImageBorder(width int, top bool) string {
6 unmodified lines
3973 tr = "+"3974 h = "-"3975 v = "|"3976 }3977 repeat := util.Max(0, width-2)3977 repeat := max(0, width-2)3978 if top {3979 return tl + strings.Repeat(h, repeat) + tr3980 }3981 return v + strings.Repeat(" ", repeat) + v
526 unmodified lines
4508 return n4509 }45104511 base := -14512 height := util.Max(0, t.pwindow.Height()-t.activePreviewOpts.headerLines)4512 height := max(0, t.pwindow.Height()-t.activePreviewOpts.headerLines)4513 for _, component := range offsetComponentRegex.FindAllString(offsetExpr, -1) {4514 if strings.HasPrefix(component, "-/") {4515 component = component[1:]4516 }
5 unmodified lines
4522 break4523 }4524 base += atoi(component)4525 }4526 return util.Max(0, base)4526 return max(0, base)4527}45284529func replacePlaceholder(params replacePlaceholderParams) (string, []string) {4530 tempFiles := []string{}
611 unmodified lines
5142 if t.needPreviewWindow() {5143 if t.activePreviewOpts.aboveOrBelow() {5144 if t.activePreviewOpts.size.percent {5145 newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size))5146 contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight)5146 contentHeight = max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight)5147 } else {5148 contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border())5149 }5150 } else {5151 // Minimum height if preview window can appear5152 contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.Border()))5152 contentHeight = max(contentHeight, 1+borderLines(t.activePreviewOpts.Border()))5153 }5154 }5155 return util.Min(termHeight, contentHeight+pad)5155 return min(termHeight, contentHeight+pad)5156 })5157 }51585159 // Context
392 unmodified lines
5552 }5553 t.previewer.lines = result.lines5554 t.previewer.spinner = result.spinner5555 if t.hasPreviewWindow() && t.previewer.following.Enabled() {5556 t.previewer.offset = util.Max(t.previewer.offset, len(t.previewer.lines)-(t.pwindow.Height()-t.activePreviewOpts.headerLines))5556 t.previewer.offset = max(t.previewer.offset, len(t.previewer.lines)-(t.pwindow.Height()-t.activePreviewOpts.headerLines))5557 } else if result.offset >= 0 {5558 t.previewer.offset = util.Constrain(result.offset, t.activePreviewOpts.headerLines, len(t.previewer.lines)-1)5559 }5560 t.printPreview()
734 unmodified lines
6295 t.raw = newRaw62966297 // Try to retain position6298 if prevIndex != minItem.Index() {6299 t.cy = util.Max(0, t.merger.FindIndex(prevIndex))6299 t.cy = max(0, t.merger.FindIndex(prevIndex))6300 t.offset = t.cy - prevPos6301 }63026303 // List needs to be rerendered
87 unmodified lines
6391 if a.t == actHalfPageUp || a.t == actHalfPageDown {6392 linesToMove = maxItems / 26393 }6394 // Move at least one line even in a very short window6395 linesToMove = util.Max(1, linesToMove)6395 linesToMove = max(1, linesToMove)63966397 // Determine the direction of the movement6398 direction := -16399 if a.t == actPageUp || a.t == actHalfPageUp {
300 unmodified lines
6700 pbarDragging = me.Down && (pbarDragging || click && t.hasPreviewWindow() && my >= t.pwindow.Top()+headerLines && my < t.pwindow.Top()+t.pwindow.Height() && mx == t.pwindow.Left()+t.pwindow.Width())6701 if pbarDragging {6702 effectiveHeight := t.pwindow.Height() - headerLines6703 numLines := len(t.previewer.lines) - headerLines6704 barLength, _ := getScrollbar(1, numLines, effectiveHeight, util.Min(numLines-effectiveHeight, t.previewer.offset-headerLines))6704 barLength, _ := getScrollbar(1, numLines, effectiveHeight, min(numLines-effectiveHeight, t.previewer.offset-headerLines))6705 if barLength > 0 {6706 y := my - t.pwindow.Top() - headerLines - barLength/26707 y = util.Constrain(y, 0, effectiveHeight-barLength)6708 // offset = (total - maxItems) * barStart / (maxItems - barLength)
511 unmodified lines
72207221 numItems = numItemsFound7222 }72237224 t.cy = util.Constrain(t.cy, 0, util.Max(0, count-1))7225 minOffset := util.Max(t.cy-numItems+1, 0)7226 maxOffset := util.Max(util.Min(count-numItems, t.cy), 0)7224 t.cy = util.Constrain(t.cy, 0, max(0, count-1))7225 minOffset := max(t.cy-numItems+1, 0)7226 maxOffset := max(min(count-numItems, t.cy), 0)7227 prevOffset := t.offset7228 t.offset = util.Constrain(t.offset, minOffset, maxOffset)7229 if t.scrollOff > 0 {7230 scrollOff := util.Min(maxLines/2, t.scrollOff)7230 scrollOff := min(maxLines/2, t.scrollOff)7231 newOffset := t.offset7232 // 2-phase adjustment to avoid infinite loop of alternating between moving up and down7233 for phase := range 2 {7234 for {
18 unmodified lines
7253 break7254 }72557256 if phase == 0 && linesBefore < scrollOff {7257 newOffset = util.Max(minOffset, newOffset-1)7257 newOffset = max(minOffset, newOffset-1)7258 } else if phase == 1 && linesAfter < scrollOff {7259 newOffset = util.Min(maxOffset, newOffset+1)7259 newOffset = min(maxOffset, newOffset+1)7260 }7261 if newOffset == prevOffset {7262 break7263 }
48 unmodified lines
7312}73137314// Number of item lines in the list window7315func (t *Terminal) maxItems() int {7316 max := t.window.Height() - t.visibleHeaderLinesInList() - t.promptLines()7317 return util.Max(max, 0)7316 maximum := t.window.Height() - t.visibleHeaderLinesInList() - t.promptLines()7317 return max(maximum, 0)7318}73197320func (t *Terminal) dumpItem(i *Item) StatusItem {7321 if i == nil {
28 unmodified lines
7350 }7351 defer t.mutex.Unlock()73527353 selectedItems := t.sortSelected()7354 selected := make([]StatusItem, util.Max(0, util.Min(params.limit, len(selectedItems)-params.offset)))7354 selected := make([]StatusItem, max(0, min(params.limit, len(selectedItems)-params.offset)))7355 for i := range selected {7356 selected[i] = t.dumpItem(selectedItems[i+params.offset].item)7357 }73587359 matches := make([]StatusItem, util.Max(0, util.Min(params.limit, t.resultMerger.Length()-params.offset)))7359 matches := make([]StatusItem, max(0, min(params.limit, t.resultMerger.Length()-params.offset)))7360 for i := range matches {7361 matches[i] = t.dumpItem(t.resultMerger.Get(i + params.offset).item)7362 }7363
22 unmodified lines
modified:src/tokenizer.go+1 added-1 removed
300 unmodified lines
301 if end < 0 {302 end += numTokens + 1303 }304 }305 minIdx = util.Max(0, begin-1)305 minIdx = max(0, begin-1)306 for idx := begin; idx <= end; idx++ {307 if idx >= 1 && idx <= numTokens {308 parts = append(parts, tokens[idx-1].text)309 }
27 unmodified lines