Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: teach drawbox additional options #1439

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ The following options can be used to customize the behavior of lf:
dirfirst bool (default true)
dironly bool (default false)
dirpreviews bool (default false)
drawbox bool (default false)
drawbox string (default "none")
dupfilefmt string (default '%f.~%n~')
errorfmt string (default "\033[7;31;47m")
filesep string (default "\n")
@@ -718,9 +718,9 @@ Show only directories.

If enabled, directories will also be passed to the previewer script. This allows custom previews for directories.

drawbox bool (default false)
drawbox string (default "none")

Draw boxes around panes with box drawing characters.
Draw boxes around panes with box drawing characters. "outline" draws a box around all panes. "separators" draws vertical lines between all panes. "both" or "true" draws both outline and separators. "none" or "false" draws neither outline nor separators.

dupfilefmt string (default '%f.~%n~')

9 changes: 6 additions & 3 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions eval.go
Original file line number Diff line number Diff line change
@@ -192,12 +192,16 @@ func (e *setExpr) eval(app *app, args []string) {
}
gOpts.dirpreviews = !gOpts.dirpreviews
case "drawbox":
if e.val == "" || e.val == "true" {
gOpts.drawbox = true
} else if e.val == "false" {
gOpts.drawbox = false
if e.val == "" || e.val == "true" || e.val == "both" {
gOpts.drawbox = "both"
} else if e.val == "false" || e.val == "none" {
gOpts.drawbox = "none"
} else if e.val == "outline" {
gOpts.drawbox = "outline"
} else if e.val == "separators" {
gOpts.drawbox = "separators"
} else {
app.ui.echoerr("drawbox: value should be empty, 'true', or 'false'")
app.ui.echoerr("drawbox: value should be empty, 'true', 'false', 'both', 'none', 'outline', or 'separators'")
return
}
app.ui.renew()
@@ -211,7 +215,7 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.echoerrf("nodrawbox: unexpected value: %s", e.val)
return
}
gOpts.drawbox = false
gOpts.drawbox = "none"
app.ui.renew()
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
@@ -223,7 +227,11 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.echoerrf("drawbox!: unexpected value: %s", e.val)
return
}
gOpts.drawbox = !gOpts.drawbox
if gOpts.drawbox == "none" {
gOpts.drawbox = "both"
} else {
gOpts.drawbox = "none"
}
app.ui.renew()
if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
6 changes: 3 additions & 3 deletions lf.1
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ The following options can be used to customize the behavior of lf:
dirfirst bool (default true)
dironly bool (default false)
dirpreviews bool (default false)
drawbox bool (default false)
drawbox string (default "none")
dupfilefmt string (default '%f.~%n~')
errorfmt string (default "\e033[7;31;47m")
filesep string (default "\en")
@@ -874,10 +874,10 @@ Show only directories.
If enabled, directories will also be passed to the previewer script. This allows custom previews for directories.
.PP
.EX
drawbox bool (default false)
drawbox string (default "none")
.EE
.PP
Draw boxes around panes with box drawing characters.
Draw boxes around panes with box drawing characters. "outline" draws a box around all panes. "separators" draws vertical lines between all panes. "both" or "true" draws both outline and separators. "none" or "false" draws neither outline nor separators.
.PP
.EX
dupfilefmt string (default '%f.~%n~')
4 changes: 2 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ var gOpts struct {
dircounts bool
dironly bool
dirpreviews bool
drawbox bool
drawbox string
dupfilefmt string
globsearch bool
icons bool
@@ -188,7 +188,7 @@ func init() {
gOpts.dircounts = false
gOpts.dironly = false
gOpts.dirpreviews = false
gOpts.drawbox = false
gOpts.drawbox = "none"
gOpts.dupfilefmt = "%f.~%n~"
gOpts.borderfmt = "\033[0m"
gOpts.cursoractivefmt = "\033[7m"
63 changes: 39 additions & 24 deletions ui.go
Original file line number Diff line number Diff line change
@@ -445,8 +445,8 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir

// make space for select marker, and leave another space at the end
maxWidth := win.w - lnwidth - 2
// make extra space to separate windows if drawbox is not enabled
if !gOpts.drawbox {
// make extra space to separate windows if drawbox separators are not enabled
if gOpts.drawbox == "none" || gOpts.drawbox == "outline" {
maxWidth -= 1
}

@@ -522,7 +522,7 @@ func getWidths(wtot int) []int {
wlen := len(gOpts.ratios)
widths := make([]int, wlen)

if gOpts.drawbox {
if gOpts.drawbox == "both" || gOpts.drawbox == "separators" {
wtot -= (wlen + 1)
}

@@ -546,9 +546,14 @@ func getWins(screen tcell.Screen) []*win {
wacc := 0
wlen := len(widths)
for i := 0; i < wlen; i++ {
if gOpts.drawbox {
if gOpts.drawbox == "both" {
wacc++
wins = append(wins, newWin(widths[i], htot-4, wacc, 2))
} else if gOpts.drawbox == "separators" {
wacc++
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
} else if gOpts.drawbox == "outline" {
wins = append(wins, newWin(widths[i], htot-4, wacc, 2))
} else {
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
}
@@ -966,29 +971,39 @@ func (ui *ui) drawBox() {

w, h := ui.screen.Size()

for i := 1; i < w-1; i++ {
ui.screen.SetContent(i, 1, tcell.RuneHLine, nil, st)
ui.screen.SetContent(i, h-2, tcell.RuneHLine, nil, st)
}
if gOpts.drawbox == "both" || gOpts.drawbox == "outline" {
for i := 1; i < w-1; i++ {
ui.screen.SetContent(i, 1, tcell.RuneHLine, nil, st)
ui.screen.SetContent(i, h-2, tcell.RuneHLine, nil, st)
}

for i := 2; i < h-2; i++ {
ui.screen.SetContent(0, i, tcell.RuneVLine, nil, st)
ui.screen.SetContent(w-1, i, tcell.RuneVLine, nil, st)
}
for i := 2; i < h-2; i++ {
ui.screen.SetContent(0, i, tcell.RuneVLine, nil, st)
ui.screen.SetContent(w-1, i, tcell.RuneVLine, nil, st)
}

ui.screen.SetContent(0, 1, tcell.RuneULCorner, nil, st)
ui.screen.SetContent(w-1, 1, tcell.RuneURCorner, nil, st)
ui.screen.SetContent(0, h-2, tcell.RuneLLCorner, nil, st)
ui.screen.SetContent(w-1, h-2, tcell.RuneLRCorner, nil, st)
ui.screen.SetContent(0, 1, tcell.RuneULCorner, nil, st)
ui.screen.SetContent(w-1, 1, tcell.RuneURCorner, nil, st)
ui.screen.SetContent(0, h-2, tcell.RuneLLCorner, nil, st)
ui.screen.SetContent(w-1, h-2, tcell.RuneLRCorner, nil, st)
}

wacc := 0
for wind := 0; wind < len(ui.wins)-1; wind++ {
wacc += ui.wins[wind].w + 1
ui.screen.SetContent(wacc, 1, tcell.RuneTTee, nil, st)
for i := 2; i < h-2; i++ {
ui.screen.SetContent(wacc, i, tcell.RuneVLine, nil, st)
top := tcell.RuneTTee
bottom := tcell.RuneBTee
if gOpts.drawbox == "separators" {
top = tcell.RuneVLine
bottom = tcell.RuneVLine
}
if gOpts.drawbox == "both" || gOpts.drawbox == "separators" {
for wind := 0; wind < len(ui.wins)-1; wind++ {
wacc += ui.wins[wind].w + 1
ui.screen.SetContent(wacc, 1, top, nil, st)
for i := 2; i < h-2; i++ {
ui.screen.SetContent(wacc, i, tcell.RuneVLine, nil, st)
}
ui.screen.SetContent(wacc, h-2, bottom, nil, st)
}
ui.screen.SetContent(wacc, h-2, tcell.RuneBTee, nil, st)
}
}

@@ -1069,7 +1084,7 @@ func (ui *ui) draw(nav *nav) {
}
}

if gOpts.drawbox {
if gOpts.drawbox != "none" {
ui.drawBox()
}

@@ -1081,7 +1096,7 @@ func (ui *ui) draw(nav *nav) {
ui.menuWin.h = len(lines) - 1
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h

if gOpts.drawbox {
if gOpts.drawbox == "outline" || gOpts.drawbox == "both" {
ui.menuWin.y += 2
}