Skip to content

Commit

Permalink
improve editor width calculation to fit to wide terminal environment
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 25, 2023
1 parent c0b31fd commit e328be7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tui/tui_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (ui *tuiWindow) drawHeader(s *state.WindowState, offsetStyleWidth int) {
d.addLeft(1).setByte('|', style)
for i := 0; i < s.Width; i++ {
d.addLeft(1).setByte(' ', style)
d.addLeft(1).setByte(" 1"[i>>4], style.Bold(cursor == i))
d.addLeft(1).setByte(" 123456789abcdef"[i>>4], style.Bold(cursor == i))
d.addLeft(1).setByte(hex[i&0x0f], style.Bold(cursor == i))
}
d.addLeft(1).setByte(' ', style)
Expand Down
15 changes: 3 additions & 12 deletions window/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"math/bits"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -518,18 +519,8 @@ func (m *Manager) State() (map[int]*state.WindowState, layout.Layout, int, error
}

func hexWindowWidth(width int) int {
if width > 146 {
return 32
} else if width > 114 {
return 24
} else if width > 82 {
return 16
} else if width > 64 {
return 12
} else if width > 50 {
return 8
}
return 4
width = mathutil.MinInt(mathutil.MaxInt((width-18)/4, 4), 256)
return width & (0b11 << (bits.Len(uint(width)) - 2))
}

func (m *Manager) writeFile(r *event.Range, name string) (string, int64, error) {
Expand Down

0 comments on commit e328be7

Please sign in to comment.