Skip to content
Myr

Add new border style: 'block'

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 5a39102 · Browse files · 5 files+69 added−33 removed
This commit

State

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

Diff stats

5 files+69 added−33 removed

  • other:+69 added−33 removed

5 files+69 added−33 removed

modified:src/tui/light.go+12 added-12 removed
743 unmodified lines
744}745746func (w *LightWindow) drawBorder(onlyHorizontal bool) {747 switch w.border.shape {748 case BorderRounded, BorderSharp, BorderBold, BorderDouble:748 case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderDouble:749 w.drawBorderAround(onlyHorizontal)750 case BorderHorizontal:751 w.drawBorderHorizontal(true, true)752 case BorderVertical:
22 unmodified lines
775 color := ColBorder776 if w.preview {777 color = ColPreviewBorder778 }779 hw := runewidth.RuneWidth(w.border.horizontal)779 hw := runewidth.RuneWidth(w.border.top)780 if top {781 w.Move(0, 0)782 w.CPrint(color, repeat(w.border.horizontal, w.width/hw))782 w.CPrint(color, repeat(w.border.top, w.width/hw))783 }784 if bottom {785 w.Move(w.height-1, 0)786 w.CPrint(color, repeat(w.border.horizontal, w.width/hw))786 w.CPrint(color, repeat(w.border.bottom, w.width/hw))787 }788}789790func (w *LightWindow) drawBorderVertical(left, right bool) {
7 unmodified lines
798 }799 for y := 0; y < w.height; y++ {800 w.Move(y, 0)801 if left {802 w.CPrint(color, string(w.border.vertical))802 w.CPrint(color, string(w.border.left))803 }804 w.CPrint(color, repeat(' ', width))805 if right {806 w.CPrint(color, string(w.border.vertical))806 w.CPrint(color, string(w.border.right))807 }808 }809}810
2 unmodified lines
813 color := ColBorder814 if w.preview {815 color = ColPreviewBorder816 }817 hw := runewidth.RuneWidth(w.border.horizontal)817 hw := runewidth.RuneWidth(w.border.top)818 tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight)819 bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight)820 rem := (w.width - tcw) % hw821 w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))821 w.CPrint(color, string(w.border.topLeft)+repeat(w.border.top, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))822 if !onlyHorizontal {823 vw := runewidth.RuneWidth(w.border.vertical)823 vw := runewidth.RuneWidth(w.border.left)824 for y := 1; y < w.height-1; y++ {825 w.Move(y, 0)826 w.CPrint(color, string(w.border.vertical))826 w.CPrint(color, string(w.border.left))827 w.CPrint(color, repeat(' ', w.width-vw*2))828 w.CPrint(color, string(w.border.vertical))828 w.CPrint(color, string(w.border.right))829 }830 }831 w.Move(w.height-1, 0)832 rem = (w.width - bcw) % hw833 w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.horizontal, (w.width-bcw)/hw)+repeat(' ', rem)+string(w.border.bottomRight))833 w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.bottom, (w.width-bcw)/hw)+repeat(' ', rem)+string(w.border.bottomRight))834}835836func (w *LightWindow) csi(code string) string {837 return w.renderer.csi(code)
247 unmodified lines
modified:src/tui/tui.go+44 added-14 removed
310 unmodified lines
311 BorderNone BorderShape = iota312 BorderRounded313 BorderSharp314 BorderBold315 BorderBlock316 BorderDouble317 BorderHorizontal318 BorderVertical319 BorderTop
19 unmodified lines
339}340341type BorderStyle struct {342 shape BorderShape342 horizontal rune343 vertical rune343 top rune344 bottom rune345 left rune346 right rune347 topLeft rune348 topRight rune349 bottomLeft rune350 bottomRight rune
4 unmodified lines
355func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {356 if !unicode {357 return BorderStyle{358 shape: shape,356 horizontal: '-',357 vertical: '|',359 top: '-',360 bottom: '-',361 left: '|',362 right: '|',363 topLeft: '+',364 topRight: '+',365 bottomLeft: '+',366 bottomRight: '+',
2 unmodified lines
369 switch shape {370 case BorderSharp:371 return BorderStyle{372 shape: shape,368 horizontal: '─',369 vertical: '│',373 top: '─',374 bottom: '─',375 left: '│',376 right: '│',377 topLeft: '┌',378 topRight: '┐',379 bottomLeft: '└',380 bottomRight: '┘',381 }382 case BorderBold:383 return BorderStyle{384 shape: shape,378 horizontal: '━',379 vertical: '┃',385 top: '━',386 bottom: '━',387 left: '┃',388 right: '┃',389 topLeft: '┏',390 topRight: '┓',391 bottomLeft: '┗',392 bottomRight: '┛',393 }394 case BorderBlock:395 // ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜396 // ▌ ▐397 // ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟398 return BorderStyle{399 shape: shape,400 top: '▀',401 bottom: '▄',402 left: '▌',403 right: '▐',404 topLeft: '▛',405 topRight: '▜',406 bottomLeft: '▙',407 bottomRight: '▟',408 }409 case BorderDouble:410 return BorderStyle{411 shape: shape,388 horizontal: '═',389 vertical: '║',412 top: '═',413 bottom: '═',414 left: '║',415 right: '║',416 topLeft: '╔',417 topRight: '╗',418 bottomLeft: '╚',419 bottomRight: '╝',420 }421 }422 return BorderStyle{423 shape: shape,398 horizontal: '─',399 vertical: '│',424 top: '─',425 bottom: '─',426 left: '│',427 right: '│',428 topLeft: '╭',429 topRight: '╮',430 bottomLeft: '╰',431 bottomRight: '╯',
2 unmodified lines
434435func MakeTransparentBorder() BorderStyle {436 return BorderStyle{437 shape: BorderRounded,410 horizontal: ' ',411 vertical: ' ',438 top: ' ',439 bottom: ' ',440 left: ' ',441 right: ' ',442 topLeft: ' ',443 topRight: ' ',444 bottomLeft: ' ',445 bottomRight: ' '}
325 unmodified lines
modified:src/options.go+6 added-2 removed
61 unmodified lines
62 --min-height=HEIGHT Minimum height when --height is given in percent63 (default: 10)64 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]65 --border[=STYLE] Draw border around the finder66 [rounded|sharp|horizontal|vertical|66 [rounded|sharp|bold|block|double|horizontal|vertical|67 top|bottom|left|right|none] (default: rounded)68 --border-label=LABEL Label to print on the border69 --border-label-pos=COL Position of the border label70 [POSITIVE_INTEGER: columns from left|
472 unmodified lines
543 case "sharp":544 return tui.BorderSharp545 case "bold":546 return tui.BorderBold547 case "block":548 return tui.BorderBlock549 case "double":550 return tui.BorderDouble551 case "horizontal":552 return tui.BorderHorizontal
12 unmodified lines
565 default:566 if optional && str == "" {567 return tui.DefaultBorderShape568 }567 errorExit("invalid border style (expected: rounded|sharp|bold|double|horizontal|vertical|top|bottom|left|right|none)")569 errorExit("invalid border style (expected: rounded|sharp|bold|block|double|horizontal|vertical|top|bottom|left|right|none)")570 }571 return tui.BorderNone572}573
857 unmodified lines
1431 case "sharp", "border-sharp":1432 opts.border = tui.BorderSharp1433 case "border-bold":1434 opts.border = tui.BorderBold1435 case "border-block":1436 opts.border = tui.BorderBlock1437 case "border-double":1438 opts.border = tui.BorderDouble1439 case "noborder", "border-none":1440 opts.border = tui.BorderNone
649 unmodified lines
modified:src/terminal.go+5 added-5 removed
715 unmodified lines
716}717718func borderLines(shape tui.BorderShape) int {719 switch shape {720 case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble:720 case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:721 return 2722 case tui.BorderTop, tui.BorderBottom:723 return 1724 }
347 unmodified lines
1072 case tui.BorderLeft:1073 if idx == 3 {1074 extraMargin[idx] += 1 + bw1075 }1076 case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble:1076 case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:1077 extraMargin[idx] += 1 + bw*(idx%2)1078 }1079 marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx]1080 }
84 unmodified lines
1165 case tui.BorderRight:1166 t.border = t.tui.NewWindow(1167 marginInt[0], marginInt[3], width+(1+bw), height,1168 false, tui.MakeBorderStyle(tui.BorderRight, t.unicode))1169 case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble:1169 case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:1170 t.border = t.tui.NewWindow(1171 marginInt[0]-1, marginInt[3]-(1+bw), width+(1+bw)*2, height+2,1172 false, tui.MakeBorderStyle(t.borderShape, t.unicode))1173 }
25 unmodified lines
1199 previewBorder = tui.MakeBorderStyle(previewOpts.border, t.unicode)1200 }1201 t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)1202 switch previewOpts.border {1203 case tui.BorderSharp, tui.BorderRounded, tui.BorderBold, tui.BorderDouble:1203 case tui.BorderSharp, tui.BorderRounded, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:1204 pwidth -= (1 + bw) * 21205 pheight -= 21206 x += 1 + bw1207 y += 1
133 unmodified lines
1341 return1342 }13431344 switch borderShape {1345 case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble:1345 case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:1346 if redrawBorder {1347 window.DrawHBorder()1348 }1349 if render == nil {
2351 unmodified lines
modified:CHANGELOG.md+2 added
1 unmodified line
2=========340.41.05------6- Added color name `preview-border` and `preview-scrollbar`7- Added new border style `block` which uses [block elements](https://en.wikipedia.org/wiki/Block_Elements)8- Bug fixes and improvements9100.40.011------
1627 unmodified lines