Skip to content

Commit

Permalink
Merge pull request #45 from jesseduffield/slim-scrollbars
Browse files Browse the repository at this point in the history
Use slimmer scrollbars
  • Loading branch information
jesseduffield authored Jan 29, 2024
2 parents 2d41754 + adf671f commit 26fc866
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Continuous Integration

env:
GO_VERSION: 1.20

on:
push:
branches:
- master
pull_request:

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Test code
run: |
go test ./...
- name: Check go.mod file
# ensure our go.mod file is clean
run: |
go mod tidy && git diff --exit-code || (echo "go.mod file is not clean. Run 'go mod tidy' locally and commit the changes" && exit 1)
19 changes: 6 additions & 13 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
}
}
if v.x1 > -1 && v.x1 < g.maxX {
runeToPrint := calcScrollbarRune(showScrollbar, realScrollbarStart, realScrollbarEnd, v.y0+1, v.y1-1, y, runeV)
runeToPrint := calcScrollbarRune(showScrollbar, realScrollbarStart, realScrollbarEnd, y, runeV)

if err := g.SetRune(v.x1, y, runeToPrint, fgColor, bgColor); err != nil {
return err
Expand All @@ -870,18 +870,11 @@ func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
return nil
}

func calcScrollbarRune(showScrollbar bool, scrollbarStart int, scrollbarEnd int, rangeStart int, rangeEnd int, position int, runeV rune) rune {
if !showScrollbar {
return runeV
} else if position == rangeStart {
return '▲'
} else if position == rangeEnd {
return '▼'
} else if position > scrollbarStart && position < scrollbarEnd {
return '█'
} else if position > rangeStart && position < rangeEnd {
// keeping this as a separate branch in case we later want to render something different here.
return runeV
func calcScrollbarRune(
showScrollbar bool, scrollbarStart int, scrollbarEnd int, position int, runeV rune,
) rune {
if showScrollbar && (position >= scrollbarStart && position <= scrollbarEnd) {
return '▐'
} else {
return runeV
}
Expand Down
7 changes: 1 addition & 6 deletions scrollbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ func calcScrollbarHeight(listSize int, pageSize int, scrollAreaSize int) int {
if pageSize >= listSize {
return scrollAreaSize
}
height := int((float64(pageSize) / float64(listSize)) * float64(scrollAreaSize))
minHeight := 2
if height < minHeight {
return minHeight
}

return height
return int((float64(pageSize) / float64(listSize)) * float64(scrollAreaSize))
}

0 comments on commit 26fc866

Please sign in to comment.