diff --git a/src/algo/algo.go b/src/algo/algo.go index ebb07d3e..8e74ce1f 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -503,7 +503,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util. if pidx < M { F[pidx] = int32(off) pidx++ - pchar = pattern[util.Min(pidx, M-1)] + pchar = pattern[min(pidx, M-1)] } lastIdx = off } @@ -521,9 +521,9 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util. inGap = false } else { if inGap { - H0[off] = util.Max16(prevH0+scoreGapExtension, 0) + H0[off] = max(prevH0+scoreGapExtension, 0) } else { - H0[off] = util.Max16(prevH0+scoreGapStart, 0) + H0[off] = max(prevH0+scoreGapStart, 0) } C0[off] = 0 inGap = true @@ -589,7 +589,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util. if b >= bonusBoundary && b > fb { consecutive = 1 } else { - b = util.Max16(b, util.Max16(bonusConsecutive, fb)) + b = max(b, max(bonusConsecutive, fb)) } } if s1+b < s2 { @@ -602,7 +602,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util. Csub[off] = consecutive inGap = s1 < s2 - score := util.Max16(util.Max16(s1, s2), 0) + score := max(max(s1, s2), 0) if pidx == M-1 && (forward && score > maxScore || !forward && score >= maxScore) { maxScore, maxScorePos = score, col } @@ -686,7 +686,7 @@ func calculateScore(caseSensitive bool, normalize bool, text *util.Chars, patter if bonus >= bonusBoundary && bonus > firstBonus { firstBonus = bonus } - bonus = util.Max16(util.Max16(bonus, firstBonus), bonusConsecutive) + bonus = max(max(bonus, firstBonus), bonusConsecutive) } if pidx == 0 { score += int(bonus * bonusFirstCharMultiplier) diff --git a/src/algo/algo_test.go b/src/algo/algo_test.go index aab03b0a..c2ed9e2c 100644 --- a/src/algo/algo_test.go +++ b/src/algo/algo_test.go @@ -86,7 +86,7 @@ func TestFuzzyMatch(t *testing.T) { scoreGapStart*2+scoreGapExtension*2) assertMatch(t, fn, true, forward, "FooBar Baz", "FooB", 0, 4, scoreMatch*4+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite)*2+ - util.Max(bonusCamel123, int(bonusBoundaryWhite))) + max(bonusCamel123, int(bonusBoundaryWhite))) // Consecutive bonus updated assertMatch(t, fn, true, forward, "foo-bar", "o-ba", 2, 6, diff --git a/src/core.go b/src/core.go index 145382b2..024c6378 100644 --- a/src/core.go +++ b/src/core.go @@ -159,7 +159,7 @@ func Run(opts *Options) (int, error) { if item.colors != nil { for _, ansi := range *item.colors { if ansi.color.bg >= 0 { - maxColorOffset = util.Max32(maxColorOffset, ansi.offset[1]) + maxColorOffset = max(maxColorOffset, ansi.offset[1]) } } } @@ -333,7 +333,7 @@ func Run(opts *Options) (int, error) { if total >= maxFit || final { deferred = false heightUnknown = false - terminal.startChan <- fitpad{util.Min(total, maxFit), padHeight} + terminal.startChan <- fitpad{min(total, maxFit), padHeight} } } else if deferred { deferred = false diff --git a/src/matcher.go b/src/matcher.go index 7fd01353..bc02c77b 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -55,7 +55,7 @@ const ( // NewMatcher returns a new Matcher func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern, sort bool, tac bool, eventBox *util.EventBox, revision revision) *Matcher { - partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions) + partitions := min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions) return &Matcher{ cache: cache, patternBuilder: patternBuilder, diff --git a/src/reader.go b/src/reader.go index 3c42edc1..85cc2853 100644 --- a/src/reader.go +++ b/src/reader.go @@ -178,7 +178,7 @@ func (r *Reader) feed(src io.Reader) { var err error for { n := 0 - scope := slab[:util.Min(len(slab), readerBufferSize)] + scope := slab[:min(len(slab), readerBufferSize)] for range 100 { n, err = src.Read(scope) if n > 0 || err != nil { diff --git a/src/result.go b/src/result.go index aa63480b..190ffc25 100644 --- a/src/result.go +++ b/src/result.go @@ -42,9 +42,9 @@ func buildResult(item *Item, offsets []Offset, score int) Result { for _, offset := range offsets { b, e := int(offset[0]), int(offset[1]) if b < e { - minBegin = util.Min(b, minBegin) - minEnd = util.Min(e, minEnd) - maxEnd = util.Max(e, maxEnd) + minBegin = min(b, minBegin) + minEnd = min(e, minEnd) + maxEnd = max(e, maxEnd) validOffsetFound = true } } diff --git a/src/terminal.go b/src/terminal.go index ae4ab14f..6b8d3715 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -900,7 +900,7 @@ func evaluateHeight(opts *Options, termHeight int) int { if opts.Height.inverse { size = 100 - size } - return util.Max(int(size*float64(termHeight)/100.0), opts.MinHeight) + return max(int(size*float64(termHeight)/100.0), opts.MinHeight) } if opts.Height.inverse { size = float64(termHeight) - size @@ -956,7 +956,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor effectiveMinHeight-- } effectiveMinHeight += borderLines(opts.BorderShape) - return util.Min(termHeight, util.Max(evaluateHeight(opts, termHeight), effectiveMinHeight)) + return min(termHeight, max(evaluateHeight(opts, termHeight), effectiveMinHeight)) } renderer, err = tui.NewLightRenderer(opts.TtyDefault, ttyin, opts.Theme, opts.Black, opts.Mouse, opts.Tabstop, opts.ClearOnExit, false, maxHeightFunc) } @@ -1153,8 +1153,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor t.pointerEmpty = "" t.pointerEmptyRaw = "" } else { - t.pointerEmpty = gutterChar + strings.Repeat(" ", util.Max(0, t.pointerLen-1)) - t.pointerEmptyRaw = gutterRawChar + strings.Repeat(" ", util.Max(0, t.pointerLen-1)) + t.pointerEmpty = gutterChar + strings.Repeat(" ", max(0, t.pointerLen-1)) + t.pointerEmptyRaw = gutterRawChar + strings.Repeat(" ", max(0, t.pointerLen-1)) } t.markerEmpty = strings.Repeat(" ", t.markerLen) @@ -1349,7 +1349,7 @@ func (t *Terminal) environImpl(forPreview bool) []string { env = append(env, fmt.Sprintf("FZF_SELECT_COUNT=%d", len(t.selected))) env = append(env, fmt.Sprintf("FZF_LINES=%d", t.areaLines)) env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns)) - env = append(env, fmt.Sprintf("FZF_POS=%d", util.Min(t.merger.Length(), t.cy+1))) + env = append(env, fmt.Sprintf("FZF_POS=%d", min(t.merger.Length(), t.cy+1))) env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine)) env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn)) env = append(env, fmt.Sprintf("FZF_CLICK_FOOTER_LINE=%d", t.clickFooterLine)) @@ -1586,12 +1586,12 @@ func getScrollbar(perLine int, total int, height int, offset int) (int, int) { if total == 0 || total*perLine <= height { return 0, 0 } - barLength := util.Max(1, height*height/(total*perLine)) + barLength := max(1, height*height/(total*perLine)) var barStart int if total == height { barStart = 0 } else { - barStart = util.Min(height-barLength, (height*perLine-barLength)*offset/(total*perLine-height)) + barStart = min(height-barLength, (height*perLine-barLength)*offset/(total*perLine-height)) } return barLength, barStart } @@ -1607,7 +1607,7 @@ func (t *Terminal) wrapCols() int { if !t.wrap { return 0 // No wrap } - return util.Max(t.window.Width()-(t.pointerLen+t.markerLen+t.barCol()), 1) + return max(t.window.Width()-(t.pointerLen+t.markerLen+t.barCol()), 1) } func (t *Terminal) clearNumLinesCache() { @@ -1662,7 +1662,7 @@ func (t *Terminal) avgNumLines() int { numLines := 0 count := 0 total := t.merger.Length() - offset := util.Max(0, util.Min(t.offset, total-maxItems-1)) + offset := max(0, min(t.offset, total-maxItems-1)) for idx := 0; idx < maxItems && idx+offset < total; idx++ { result := t.merger.Get(idx + offset) lines, _ := t.numItemLines(result.item, maxItems) @@ -1822,7 +1822,7 @@ func (t *Terminal) UpdateList(result MatchResult) { t.offset = 0 } else if t.cy > count { // Try to keep the vertical position when the list shrinks - t.cy = count - util.Min(count, t.maxItems()) + pos + t.cy = count - min(count, t.maxItems()) + pos } } needActivation := false @@ -1987,17 +1987,17 @@ func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) { marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx] } - adjust := func(idx1 int, idx2 int, max int, min int) { - if min > max { - min = max + adjust := func(idx1 int, idx2 int, maximum int, minimum int) { + if minimum > maximum { + minimum = maximum } margin := marginInt[idx1] + marginInt[idx2] + paddingInt[idx1] + paddingInt[idx2] - if max-margin < min { - desired := max - min + if maximum-margin < minimum { + desired := maximum - minimum paddingInt[idx1] = desired * paddingInt[idx1] / margin paddingInt[idx2] = desired * paddingInt[idx2] / margin - marginInt[idx1] = util.Max(extraMargin[idx1], desired*marginInt[idx1]/margin) - marginInt[idx2] = util.Max(extraMargin[idx2], desired*marginInt[idx2]/margin) + marginInt[idx1] = max(extraMargin[idx1], desired*marginInt[idx1]/margin) + marginInt[idx2] = max(extraMargin[idx2], desired*marginInt[idx2]/margin) } } @@ -2014,10 +2014,10 @@ func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) { switch t.activePreviewOpts.position { case posUp, posDown: minAreaHeight += minPreviewHeight - minAreaWidth = util.Max(minPreviewWidth, minAreaWidth) + minAreaWidth = max(minPreviewWidth, minAreaWidth) case posLeft, posRight: minAreaWidth += minPreviewWidth - minAreaHeight = util.Max(minPreviewHeight, minAreaHeight) + minAreaHeight = max(minPreviewHeight, minAreaHeight) } } adjust(1, 3, screenWidth, minAreaWidth) @@ -2491,7 +2491,7 @@ func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) { width++ } // Make sure that the width does not exceed the list width - width = util.Min(t.window.Width()+t.headerIndentImpl(0, shape), width) + width = min(t.window.Width()+t.headerIndentImpl(0, shape), width) height := b.Height() - borderLines(shape) return t.tui.NewWindow(top, left, width, height, windowType, noBorder, true) } @@ -2655,11 +2655,11 @@ func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts label } var col int if opts.column == 0 { - col = util.Max(0, (window.Width()-length)/2) + col = max(0, (window.Width()-length)/2) } else if opts.column < 0 { - col = util.Max(0, window.Width()+opts.column+1-length) + col = max(0, window.Width()+opts.column+1-length) } else { - col = util.Min(opts.column-1, window.Width()-length) + col = min(opts.column-1, window.Width()-length) } row := 0 if borderShape == tui.BorderBottom || opts.bottom { @@ -2714,7 +2714,7 @@ func (t *Terminal) truncateQuery() { // the user accidentally pastes a huge chunk of text. Therefore, we're not // interested in the exact display width of the query. We just limit the // number of runes. - t.input = t.input[:util.Min(len(t.input), maxPatternLength)] + t.input = t.input[:min(len(t.input), maxPatternLength)] t.cx = util.Constrain(t.cx, 0, len(t.input)) } @@ -2723,11 +2723,11 @@ func (t *Terminal) updatePromptOffset() ([]rune, []rune) { if t.inputWindow != nil { w = t.inputWindow } - maxWidth := util.Max(1, w.Width()-t.promptLen-1) + maxWidth := max(1, w.Width()-t.promptLen-1) _, overflow := t.trimLeft(t.input[:t.cx], maxWidth, 0) minOffset := int(overflow) - maxOffset := minOffset + (maxWidth-util.Max(0, maxWidth-t.cx))/2 + maxOffset := minOffset + (maxWidth-max(0, maxWidth-t.cx))/2 t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset) before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth, 0) beforeLen := t.displayWidth(before) @@ -2749,7 +2749,7 @@ func (t *Terminal) promptLine() int { if !t.noSeparatorLine() { max-- } - return util.Min(t.visibleHeaderLinesInList(), max) + return min(t.visibleHeaderLinesInList(), max) } return 0 } @@ -2764,11 +2764,11 @@ func (t *Terminal) placeCursor() { if t.layout == layoutReverse { y = 0 } - x = util.Min(x, t.inputWindow.Width()-1) + x = min(x, t.inputWindow.Width()-1) t.inputWindow.Move(y, x) return } - x = util.Min(x, t.window.Width()-1) + x = min(x, t.window.Width()-1) t.move(t.promptLine(), x, false) } @@ -2787,7 +2787,7 @@ func (t *Terminal) printPrompt() { before, after := t.updatePromptOffset() if len(before) == 0 && len(after) == 0 && len(t.ghost) > 0 { - maxWidth := util.Max(1, w.Width()-t.promptLen-1) + maxWidth := max(1, w.Width()-t.promptLen-1) runes, _ := t.trimRight([]rune(t.ghost), maxWidth) w.CPrint(tui.ColGhost, string(runes)) return @@ -2877,7 +2877,7 @@ func (t *Terminal) printInfoImpl() { } found := t.resultMerger.Length() - total := util.Max(found, t.count) + total := max(found, t.count) output := fmt.Sprintf("%d/%d", found, total) if t.toggleSort { if t.sort { @@ -2971,7 +2971,7 @@ func (t *Terminal) printInfoImpl() { if t.infoStyle == infoInlineRight { if len(t.infoPrefix) == 0 { move(line, pos, false) - newPos := util.Max(pos, t.window.Width()-outputLen-3) + newPos := max(pos, t.window.Width()-outputLen-3) t.window.Print(strings.Repeat(" ", newPos-pos)) pos = newPos if pos < t.window.Width() { @@ -2983,7 +2983,7 @@ func (t *Terminal) printInfoImpl() { pos++ } } else { - pos = util.Max(pos, t.window.Width()-outputLen-util.StringWidth(t.infoPrefix)-1) + pos = max(pos, t.window.Width()-outputLen-util.StringWidth(t.infoPrefix)-1) printInfoPrefix() } } @@ -3079,7 +3079,7 @@ func (t *Terminal) printFooter() { } indentSize := t.headerIndent(t.footerBorderShape) indent := strings.Repeat(" ", indentSize) - max := util.Min(len(t.footer), t.footerWindow.Height()) + max := min(len(t.footer), t.footerWindow.Height()) // Wrapping is not supported for footer wrap := t.wrap @@ -3304,7 +3304,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu } else { alt = index%2 == 1 } - label = t.jumpLabels[index:index+1] + strings.Repeat(" ", util.Max(0, t.pointerLen-1)) + label = t.jumpLabels[index:index+1] + strings.Repeat(" ", max(0, t.pointerLen-1)) if t.pointerLen == 0 { extraWidth = 1 } @@ -3474,7 +3474,7 @@ func (t *Terminal) displayWidthWithLimit(runes []rune, prefixWidth int, limit in } func (t *Terminal) trimLeft(runes []rune, width int, ellipsisWidth int) ([]rune, int32) { - width = util.Max(0, width) + width = max(0, width) var trimmed int32 // Assume that each rune takes at least one column on screen if len(runes) > width { @@ -3565,12 +3565,12 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat // ------> <------ if t.freezeLeft > 0 { if len(tokens) > 0 { - token := tokens[util.Min(t.freezeLeft, len(tokens))-1] + token := tokens[min(t.freezeLeft, len(tokens))-1] splitOffset1 = int(token.prefixLength) + token.text.Length() - token.text.TrailingWhitespaces() } } if t.freezeRight > 0 { - index := util.Max(t.freezeLeft-1, len(tokens)-t.freezeRight-1) + index := max(t.freezeLeft-1, len(tokens)-t.freezeRight-1) if index < 0 { splitOffset2 = 0 } else if index >= t.freezeLeft { @@ -3578,7 +3578,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat delimiter := strings.TrimLeftFunc(GetLastDelimiter(token.text.ToString(), t.delimiter), unicode.IsSpace) splitOffset2 = int(token.prefixLength) + token.text.Length() - len([]rune(delimiter)) } - splitOffset2 = util.Max(splitOffset2, splitOffset1) + splitOffset2 = max(splitOffset2, splitOffset1) } } @@ -3668,7 +3668,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat var maxEnd int for _, offset := range offsets { if offset.match { - maxEnd = util.Max(maxEnd, int(offset.offset[1])) + maxEnd = max(maxEnd, int(offset.offset[1])) } } @@ -3767,19 +3767,19 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat } displayWidth = t.displayWidthWithLimit(runes, 0, adjustedMaxWidth) if !t.wrap && displayWidth > adjustedMaxWidth { - maxe = util.Constrain(maxe+util.Min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes)) + maxe = util.Constrain(maxe+min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes)) transformOffsets := func(diff int32, rightTrim bool) { for idx, offset := range offs { b, e := offset.offset[0], offset.offset[1] el := int32(len(ellipsis)) b += el - diff e += el - diff - b = util.Max32(b, el) + b = max(b, el) if rightTrim { - e = util.Min32(e, int32(maxWidth-ellipsisWidth)) + e = min(e, int32(maxWidth-ellipsisWidth)) } offs[idx].offset[0] = b - offs[idx].offset[1] = util.Max32(b, e) + offs[idx].offset[1] = max(b, e) } } if t.hscroll { @@ -3811,8 +3811,8 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat runes = append(runes, ellipsis...) for idx, offset := range offs { - offs[idx].offset[0] = util.Min32(offset.offset[0], int32(maxWidth-len(ellipsis))) - offs[idx].offset[1] = util.Min32(offset.offset[1], int32(maxWidth)) + offs[idx].offset[0] = min(offset.offset[0], int32(maxWidth-len(ellipsis))) + offs[idx].offset[1] = min(offset.offset[1], int32(maxWidth)) } } displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth) @@ -3941,7 +3941,7 @@ func (t *Terminal) renderPreviewArea(unchanged bool) { body := t.previewer.lines headerLines := t.activePreviewOpts.headerLines // Do not enable preview header lines if it's value is too large - if headerLines > 0 && headerLines < util.Min(len(body), height) { + if headerLines > 0 && headerLines < min(len(body), height) { header := t.previewer.lines[0:headerLines] body = t.previewer.lines[headerLines:] // Always redraw header @@ -3959,7 +3959,7 @@ func (t *Terminal) renderPreviewArea(unchanged bool) { } effectiveHeight := height - headerLines - barLength, barStart := getScrollbar(1, len(body), effectiveHeight, util.Min(len(body)-effectiveHeight, t.previewer.offset-headerLines)) + barLength, barStart := getScrollbar(1, len(body), effectiveHeight, min(len(body)-effectiveHeight, t.previewer.offset-headerLines)) t.renderPreviewScrollbar(headerLines, barLength, barStart) } @@ -3974,7 +3974,7 @@ func (t *Terminal) makeImageBorder(width int, top bool) string { h = "-" v = "|" } - repeat := util.Max(0, width-2) + repeat := max(0, width-2) if top { return tl + strings.Repeat(h, repeat) + tr } @@ -4509,7 +4509,7 @@ func (t *Terminal) evaluateScrollOffset() int { } base := -1 - height := util.Max(0, t.pwindow.Height()-t.activePreviewOpts.headerLines) + height := max(0, t.pwindow.Height()-t.activePreviewOpts.headerLines) for _, component := range offsetComponentRegex.FindAllString(offsetExpr, -1) { if strings.HasPrefix(component, "-/") { component = component[1:] @@ -4523,7 +4523,7 @@ func (t *Terminal) evaluateScrollOffset() int { } base += atoi(component) } - return util.Max(0, base) + return max(0, base) } func replacePlaceholder(params replacePlaceholderParams) (string, []string) { @@ -5143,16 +5143,16 @@ func (t *Terminal) Loop() error { if t.activePreviewOpts.aboveOrBelow() { if t.activePreviewOpts.size.percent { newContentHeight := int(float64(contentHeight) * 100. / (100. - t.activePreviewOpts.size.size)) - contentHeight = util.Max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight) + contentHeight = max(contentHeight+1+borderLines(t.activePreviewOpts.Border()), newContentHeight) } else { contentHeight += int(t.activePreviewOpts.size.size) + borderLines(t.activePreviewOpts.Border()) } } else { // Minimum height if preview window can appear - contentHeight = util.Max(contentHeight, 1+borderLines(t.activePreviewOpts.Border())) + contentHeight = max(contentHeight, 1+borderLines(t.activePreviewOpts.Border())) } } - return util.Min(termHeight, contentHeight+pad) + return min(termHeight, contentHeight+pad) }) } @@ -5553,7 +5553,7 @@ func (t *Terminal) Loop() error { t.previewer.lines = result.lines t.previewer.spinner = result.spinner if t.hasPreviewWindow() && t.previewer.following.Enabled() { - t.previewer.offset = util.Max(t.previewer.offset, len(t.previewer.lines)-(t.pwindow.Height()-t.activePreviewOpts.headerLines)) + t.previewer.offset = max(t.previewer.offset, len(t.previewer.lines)-(t.pwindow.Height()-t.activePreviewOpts.headerLines)) } else if result.offset >= 0 { t.previewer.offset = util.Constrain(result.offset, t.activePreviewOpts.headerLines, len(t.previewer.lines)-1) } @@ -6296,7 +6296,7 @@ func (t *Terminal) Loop() error { // Try to retain position if prevIndex != minItem.Index() { - t.cy = util.Max(0, t.merger.FindIndex(prevIndex)) + t.cy = max(0, t.merger.FindIndex(prevIndex)) t.offset = t.cy - prevPos } @@ -6392,7 +6392,7 @@ func (t *Terminal) Loop() error { linesToMove = maxItems / 2 } // Move at least one line even in a very short window - linesToMove = util.Max(1, linesToMove) + linesToMove = max(1, linesToMove) // Determine the direction of the movement direction := -1 @@ -6701,7 +6701,7 @@ func (t *Terminal) Loop() error { if pbarDragging { effectiveHeight := t.pwindow.Height() - headerLines numLines := len(t.previewer.lines) - headerLines - barLength, _ := getScrollbar(1, numLines, effectiveHeight, util.Min(numLines-effectiveHeight, t.previewer.offset-headerLines)) + barLength, _ := getScrollbar(1, numLines, effectiveHeight, min(numLines-effectiveHeight, t.previewer.offset-headerLines)) if barLength > 0 { y := my - t.pwindow.Top() - headerLines - barLength/2 y = util.Constrain(y, 0, effectiveHeight-barLength) @@ -7221,13 +7221,13 @@ func (t *Terminal) constrain() { numItems = numItemsFound } - t.cy = util.Constrain(t.cy, 0, util.Max(0, count-1)) - minOffset := util.Max(t.cy-numItems+1, 0) - maxOffset := util.Max(util.Min(count-numItems, t.cy), 0) + t.cy = util.Constrain(t.cy, 0, max(0, count-1)) + minOffset := max(t.cy-numItems+1, 0) + maxOffset := max(min(count-numItems, t.cy), 0) prevOffset := t.offset t.offset = util.Constrain(t.offset, minOffset, maxOffset) if t.scrollOff > 0 { - scrollOff := util.Min(maxLines/2, t.scrollOff) + scrollOff := min(maxLines/2, t.scrollOff) newOffset := t.offset // 2-phase adjustment to avoid infinite loop of alternating between moving up and down for phase := range 2 { @@ -7254,9 +7254,9 @@ func (t *Terminal) constrain() { } if phase == 0 && linesBefore < scrollOff { - newOffset = util.Max(minOffset, newOffset-1) + newOffset = max(minOffset, newOffset-1) } else if phase == 1 && linesAfter < scrollOff { - newOffset = util.Min(maxOffset, newOffset+1) + newOffset = min(maxOffset, newOffset+1) } if newOffset == prevOffset { break @@ -7313,8 +7313,8 @@ func (t *Terminal) promptLines() int { // Number of item lines in the list window func (t *Terminal) maxItems() int { - max := t.window.Height() - t.visibleHeaderLinesInList() - t.promptLines() - return util.Max(max, 0) + maximum := t.window.Height() - t.visibleHeaderLinesInList() - t.promptLines() + return max(maximum, 0) } func (t *Terminal) dumpItem(i *Item) StatusItem { @@ -7351,12 +7351,12 @@ func (t *Terminal) dumpStatus(params getParams) string { defer t.mutex.Unlock() selectedItems := t.sortSelected() - selected := make([]StatusItem, util.Max(0, util.Min(params.limit, len(selectedItems)-params.offset))) + selected := make([]StatusItem, max(0, min(params.limit, len(selectedItems)-params.offset))) for i := range selected { selected[i] = t.dumpItem(selectedItems[i+params.offset].item) } - matches := make([]StatusItem, util.Max(0, util.Min(params.limit, t.resultMerger.Length()-params.offset))) + matches := make([]StatusItem, max(0, min(params.limit, t.resultMerger.Length()-params.offset))) for i := range matches { matches[i] = t.dumpItem(t.resultMerger.Get(i + params.offset).item) } diff --git a/src/tokenizer.go b/src/tokenizer.go index 40208e24..25448f59 100644 --- a/src/tokenizer.go +++ b/src/tokenizer.go @@ -302,7 +302,7 @@ func Transform(tokens []Token, withNth []Range) []Token { end += numTokens + 1 } } - minIdx = util.Max(0, begin-1) + minIdx = max(0, begin-1) for idx := begin; idx <= end; idx++ { if idx >= 1 && idx <= numTokens { parts = append(parts, tokens[idx-1].text) diff --git a/src/tui/light.go b/src/tui/light.go index e971175b..133759fb 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -1033,8 +1033,8 @@ func (r *LightRenderer) MaxY() int { } func (r *LightRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window { - width = util.Max(0, width) - height = util.Max(0, height) + width = max(0, width) + height = max(0, height) w := &LightWindow{ renderer: r, colored: r.theme.Colored, diff --git a/src/tui/tcell.go b/src/tui/tcell.go index f7c6884f..b027cad9 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -729,8 +729,8 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) { } func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window { - width = util.Max(0, width) - height = util.Max(0, height) + width = max(0, width) + height = max(0, height) normal := ColBorder switch windowType { case WindowList: diff --git a/src/util/chars.go b/src/util/chars.go index 04d5a23e..1701c812 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -187,7 +187,7 @@ func (chars *Chars) TrailingWhitespaces() int { func (chars *Chars) TrimTrailingWhitespaces(maxIndex int) { whitespaces := chars.TrailingWhitespaces() end := len(chars.slice) - whitespaces - chars.slice = chars.slice[0:Max(end, maxIndex)] + chars.slice = chars.slice[0:max(end, maxIndex)] } func (chars *Chars) TrimSuffix(runes []rune) { diff --git a/src/util/util.go b/src/util/util.go index f11a0887..99506387 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -55,54 +55,14 @@ func Truncate(input string, limit int) ([]rune, int) { return runes, width } -// Max returns the largest integer -func Max(first int, second int) int { - if first >= second { - return first - } - return second -} - -// Max16 returns the largest integer -func Max16(first int16, second int16) int16 { - if first >= second { - return first - } - return second -} - -// Max32 returns the largest 32-bit integer -func Max32(first int32, second int32) int32 { - if first > second { - return first - } - return second -} - -// Min returns the smallest integer -func Min(first int, second int) int { - if first <= second { - return first - } - return second -} - -// Min32 returns the smallest 32-bit integer -func Min32(first int32, second int32) int32 { - if first <= second { - return first - } - return second -} - // Constrain32 limits the given 32-bit integer with the upper and lower bounds -func Constrain32(val int32, min int32, max int32) int32 { - return Max32(Min32(val, max), min) +func Constrain32(val int32, minimum int32, maximum int32) int32 { + return max(min(val, maximum), minimum) } // Constrain limits the given integer with the upper and lower bounds -func Constrain(val int, min int, max int) int { - return Max(Min(val, max), min) +func Constrain(val int, minimum int, maximum int) int { + return max(min(val, maximum), minimum) } func AsUint16(val int) uint16 { @@ -197,7 +157,7 @@ func CompareVersions(v1, v2 string) int { return n } - for i := 0; i < Max(len(parts1), len(parts2)); i++ { + for i := 0; i < max(len(parts1), len(parts2)); i++ { var p1, p2 int if i < len(parts1) { p1 = atoi(parts1[i]) diff --git a/src/util/util_test.go b/src/util/util_test.go index 36d71bde..e989dce8 100644 --- a/src/util/util_test.go +++ b/src/util/util_test.go @@ -7,69 +7,6 @@ import ( "time" ) -func TestMax(t *testing.T) { - if Max(10, 1) != 10 { - t.Error("Expected", 10) - } - if Max(-2, 5) != 5 { - t.Error("Expected", 5) - } -} - -func TestMax16(t *testing.T) { - if Max16(10, 1) != 10 { - t.Error("Expected", 10) - } - if Max16(-2, 5) != 5 { - t.Error("Expected", 5) - } - if Max16(math.MaxInt16, 0) != math.MaxInt16 { - t.Error("Expected", math.MaxInt16) - } - if Max16(0, math.MinInt16) != 0 { - t.Error("Expected", 0) - } -} - -func TestMax32(t *testing.T) { - if Max32(10, 1) != 10 { - t.Error("Expected", 10) - } - if Max32(-2, 5) != 5 { - t.Error("Expected", 5) - } - if Max32(math.MaxInt32, 0) != math.MaxInt32 { - t.Error("Expected", math.MaxInt32) - } - if Max32(0, math.MinInt32) != 0 { - t.Error("Expected", 0) - } -} - -func TestMin(t *testing.T) { - if Min(10, 1) != 1 { - t.Error("Expected", 1) - } - if Min(-2, 5) != -2 { - t.Error("Expected", -2) - } -} - -func TestMin32(t *testing.T) { - if Min32(10, 1) != 1 { - t.Error("Expected", 1) - } - if Min32(-2, 5) != -2 { - t.Error("Expected", -2) - } - if Min32(math.MaxInt32, 0) != 0 { - t.Error("Expected", 0) - } - if Min32(0, math.MinInt32) != math.MinInt32 { - t.Error("Expected", math.MinInt32) - } -} - func TestConstrain(t *testing.T) { if Constrain(-3, -1, 3) != -1 { t.Error("Expected", -1)