diff --git a/complete.go b/complete.go index 24ceee57..3480dd9e 100644 --- a/complete.go +++ b/complete.go @@ -113,6 +113,8 @@ var ( "autoquit", "noautoquit", "autoquit!", + "cursorfmt", + "cursorpreviewfmt", "dircache", "nodircache", "dircache!", diff --git a/doc.go b/doc.go index f0897102..cbb20d1e 100644 --- a/doc.go +++ b/doc.go @@ -111,57 +111,59 @@ The following command line commands are provided by lf: The following options can be used to customize the behavior of lf: - anchorfind bool (default on) - autoquit bool (default off) - cleaner string (default '') - dircache bool (default on) - dircounts bool (default off) - dirfirst bool (default on) - dironly bool (default off) - dirpreviews bool (default off) - drawbox bool (default off) - errorfmt string (default "\033[7;31;47m%s\033[0m") - filesep string (default "\n") - findlen int (default 1) - globsearch bool (default off) - hidden bool (default off) - hiddenfiles []string (default '.*') - history bool (default on) - icons bool (default off) - ifs string (default '') - ignorecase bool (default on) - ignoredia bool (default on) - incfilter bool (default off) - incsearch bool (default off) - info []string (default '') - infotimefmtnew string (default 'Jan _2 15:04') - infotimefmtold string (default 'Jan _2 2006') - mouse bool (default off) - number bool (default off) - period int (default 0) - preview bool (default on) - previewer string (default '') - promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m") - ratios []int (default '1:2:3') - relativenumber bool (default off) - reverse bool (default off) - scrolloff int (default 0) - selmode string (default 'all') - shell string (default 'sh' for Unix and 'cmd' for Windows) - shellflag string (default '-c' for Unix and '/c' for Windows) - shellopts []string (default '') - smartcase bool (default on) - smartdia bool (default off) - sortby string (default 'natural') - tabstop int (default 8) - tagfmt string (default "\033[31m%s\033[0m") - tempmarks string (default '') - timefmt string (default 'Mon Jan _2 15:04:05 2006') - truncatechar string (default '~') - waitmsg string (default 'Press any key to continue') - wrapscan bool (default on) - wrapscroll bool (default off) - user_{option} string (default none) + anchorfind bool (default on) + autoquit bool (default off) + cleaner string (default '') + cursorfmt string (default "\033[7m") + cursorpreviewfmt string (default "\033[4m") + dircache bool (default on) + dircounts bool (default off) + dirfirst bool (default on) + dironly bool (default off) + dirpreviews bool (default off) + drawbox bool (default off) + errorfmt string (default "\033[7;31;47m") + filesep string (default "\n") + findlen int (default 1) + globsearch bool (default off) + hidden bool (default off) + hiddenfiles []string (default '.*') + history bool (default on) + icons bool (default off) + ifs string (default '') + ignorecase bool (default on) + ignoredia bool (default on) + incfilter bool (default off) + incsearch bool (default off) + info []string (default '') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') + mouse bool (default off) + number bool (default off) + period int (default 0) + preview bool (default on) + previewer string (default '') + promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m") + ratios []int (default '1:2:3') + relativenumber bool (default off) + reverse bool (default off) + scrolloff int (default 0) + selmode string (default 'all') + shell string (default 'sh' for Unix and 'cmd' for Windows) + shellflag string (default '-c' for Unix and '/c' for Windows) + shellopts []string (default '') + smartcase bool (default on) + smartdia bool (default off) + sortby string (default 'natural') + tabstop int (default 8) + tagfmt string (default "\033[31m") + tempmarks string (default '') + timefmt string (default 'Mon Jan _2 15:04:05 2006') + truncatechar string (default '~') + waitmsg string (default 'Press any key to continue') + wrapscan bool (default on) + wrapscroll bool (default off) + user_{option} string (default none) The following environment variables are exported for shell commands: @@ -606,6 +608,19 @@ This file is called if previewing is enabled, the previewer is set, and the prev Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty. + cursorfmt string (default "\033[7m") + cursorpreviewfmt string (default "\033[4m") + +Format strings for highlighting the cursor. +`cursorpreviewfmt` applies in panes that preview directories, and `cursorfmt` applies in all other panes. + +The default is to make the normal cursor inverted and the preview cursor underlined. + +Some other possibilities to consider for the preview cursor: an empty string for no cursor, "\033[7;2m" for dimmed inverted text (visibility varies by terminal), "\033[7;90m" for inverted text with grey (aka "brightblack") background. + +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. +For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + dircache bool (default on) Cache directory contents. @@ -634,10 +649,13 @@ Show only directories. Draw boxes around panes with box drawing characters. - errorfmt string (default "\033[7;31;47m%s\033[0m") + errorfmt string (default "\033[7;31;47m") Format string of error messages shown in the bottom message line. +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. +For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + filesep string (default "\n") File separator used in environment variables 'fs' and 'fx'. @@ -812,10 +830,13 @@ Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', ' Number of space characters to show for horizontal tabulation (U+0009) character. - tagfmt string (default "\033[31m%s\033[0m") + tagfmt string (default "\033[31m") Format string of the tags. +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. +For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + tempmarks string (default '') Marks to be considered temporary (e.g. 'abc' refers to marks 'a', 'b', and 'c'). diff --git a/docstring.go b/docstring.go index 9d9fe9a9..17ef3f2c 100644 --- a/docstring.go +++ b/docstring.go @@ -114,57 +114,59 @@ The following command line commands are provided by lf: The following options can be used to customize the behavior of lf: - anchorfind bool (default on) - autoquit bool (default off) - cleaner string (default '') - dircache bool (default on) - dircounts bool (default off) - dirfirst bool (default on) - dironly bool (default off) - dirpreviews bool (default off) - drawbox bool (default off) - errorfmt string (default "\033[7;31;47m%s\033[0m") - filesep string (default "\n") - findlen int (default 1) - globsearch bool (default off) - hidden bool (default off) - hiddenfiles []string (default '.*') - history bool (default on) - icons bool (default off) - ifs string (default '') - ignorecase bool (default on) - ignoredia bool (default on) - incfilter bool (default off) - incsearch bool (default off) - info []string (default '') - infotimefmtnew string (default 'Jan _2 15:04') - infotimefmtold string (default 'Jan _2 2006') - mouse bool (default off) - number bool (default off) - period int (default 0) - preview bool (default on) - previewer string (default '') - promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m") - ratios []int (default '1:2:3') - relativenumber bool (default off) - reverse bool (default off) - scrolloff int (default 0) - selmode string (default 'all') - shell string (default 'sh' for Unix and 'cmd' for Windows) - shellflag string (default '-c' for Unix and '/c' for Windows) - shellopts []string (default '') - smartcase bool (default on) - smartdia bool (default off) - sortby string (default 'natural') - tabstop int (default 8) - tagfmt string (default "\033[31m%s\033[0m") - tempmarks string (default '') - timefmt string (default 'Mon Jan _2 15:04:05 2006') - truncatechar string (default '~') - waitmsg string (default 'Press any key to continue') - wrapscan bool (default on) - wrapscroll bool (default off) - user_{option} string (default none) + anchorfind bool (default on) + autoquit bool (default off) + cleaner string (default '') + cursorfmt string (default "\033[7m") + cursorpreviewfmt string (default "\033[4m") + dircache bool (default on) + dircounts bool (default off) + dirfirst bool (default on) + dironly bool (default off) + dirpreviews bool (default off) + drawbox bool (default off) + errorfmt string (default "\033[7;31;47m") + filesep string (default "\n") + findlen int (default 1) + globsearch bool (default off) + hidden bool (default off) + hiddenfiles []string (default '.*') + history bool (default on) + icons bool (default off) + ifs string (default '') + ignorecase bool (default on) + ignoredia bool (default on) + incfilter bool (default off) + incsearch bool (default off) + info []string (default '') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') + mouse bool (default off) + number bool (default off) + period int (default 0) + preview bool (default on) + previewer string (default '') + promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m") + ratios []int (default '1:2:3') + relativenumber bool (default off) + reverse bool (default off) + scrolloff int (default 0) + selmode string (default 'all') + shell string (default 'sh' for Unix and 'cmd' for Windows) + shellflag string (default '-c' for Unix and '/c' for Windows) + shellopts []string (default '') + smartcase bool (default on) + smartdia bool (default off) + sortby string (default 'natural') + tabstop int (default 8) + tagfmt string (default "\033[31m") + tempmarks string (default '') + timefmt string (default 'Mon Jan _2 15:04:05 2006') + truncatechar string (default '~') + waitmsg string (default 'Press any key to continue') + wrapscan bool (default on) + wrapscroll bool (default off) + user_{option} string (default none) The following environment variables are exported for shell commands: @@ -632,6 +634,23 @@ file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty. + cursorfmt string (default "\033[7m") + cursorpreviewfmt string (default "\033[4m") + +Format strings for highlighting the cursor. 'cursorpreviewfmt' applies in panes +that preview directories, and 'cursorfmt' applies in all other panes. + +The default is to make the normal cursor inverted and the preview cursor +underlined. + +Some other possibilities to consider for the preview cursor: an empty string for +no cursor, "\033[7;2m" for dimmed inverted text (visibility varies by terminal), +"\033[7;90m" for inverted text with grey (aka "brightblack") background. + +If the format string contains the characters '%s', it is interpreted as a format +string for 'fmt.Sprintf'. Such a string should end with the terminal reset +sequence. For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + dircache bool (default on) Cache directory contents. @@ -664,10 +683,14 @@ Show only directories. Draw boxes around panes with box drawing characters. - errorfmt string (default "\033[7;31;47m%s\033[0m") + errorfmt string (default "\033[7;31;47m") Format string of error messages shown in the bottom message line. +If the format string contains the characters '%s', it is interpreted as a format +string for 'fmt.Sprintf'. Such a string should end with the terminal reset +sequence. For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + filesep string (default "\n") File separator used in environment variables 'fs' and 'fx'. @@ -858,10 +881,14 @@ Sort type for directories. Currently supported sort types are 'natural', 'name', Number of space characters to show for horizontal tabulation (U+0009) character. - tagfmt string (default "\033[31m%s\033[0m") + tagfmt string (default "\033[31m") Format string of the tags. +If the format string contains the characters '%s', it is interpreted as a format +string for 'fmt.Sprintf'. Such a string should end with the terminal reset +sequence. For example, "\033[4m%s\033[0m" has the same effect as "\033[4m". + tempmarks string (default '') Marks to be considered temporary (e.g. 'abc' refers to marks 'a', 'b', diff --git a/etc/lfrc.example b/etc/lfrc.example index 04fb6c1f..18bf621c 100644 --- a/etc/lfrc.example +++ b/etc/lfrc.example @@ -20,6 +20,9 @@ set ifs "\n" # leave some space at the top and the bottom of the screen set scrolloff 10 +# Use the `dim` attribute instead of underline for the cursor in the preview pane +set cursorpreviewfmt "\033[7;2m" + # use enter for shell commands map shell diff --git a/eval.go b/eval.go index a0863419..87c6127c 100644 --- a/eval.go +++ b/eval.go @@ -26,6 +26,10 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.autoquit = true case "noautoquit": gOpts.autoquit = false + case "cursorfmt": + gOpts.cursorfmt = e.val + case "cursorpreviewfmt": + gOpts.cursorpreviewfmt = e.val case "autoquit!": gOpts.autoquit = !gOpts.autoquit case "dircache": diff --git a/lf.1 b/lf.1 index d8206969..3b3eed6f 100644 --- a/lf.1 +++ b/lf.1 @@ -130,57 +130,59 @@ The following command line commands are provided by lf: The following options can be used to customize the behavior of lf: .PP .EX - anchorfind bool (default on) - autoquit bool (default off) - cleaner string (default '') - dircache bool (default on) - dircounts bool (default off) - dirfirst bool (default on) - dironly bool (default off) - dirpreviews bool (default off) - drawbox bool (default off) - errorfmt string (default "\e033[7;31;47m%s\e033[0m") - filesep string (default "\en") - findlen int (default 1) - globsearch bool (default off) - hidden bool (default off) - hiddenfiles []string (default '.*') - history bool (default on) - icons bool (default off) - ifs string (default '') - ignorecase bool (default on) - ignoredia bool (default on) - incfilter bool (default off) - incsearch bool (default off) - info []string (default '') - infotimefmtnew string (default 'Jan _2 15:04') - infotimefmtold string (default 'Jan _2 2006') - mouse bool (default off) - number bool (default off) - period int (default 0) - preview bool (default on) - previewer string (default '') - promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%d\e033[0m\e033[1m%f\e033[0m") - ratios []int (default '1:2:3') - relativenumber bool (default off) - reverse bool (default off) - scrolloff int (default 0) - selmode string (default 'all') - shell string (default 'sh' for Unix and 'cmd' for Windows) - shellflag string (default '-c' for Unix and '/c' for Windows) - shellopts []string (default '') - smartcase bool (default on) - smartdia bool (default off) - sortby string (default 'natural') - tabstop int (default 8) - tagfmt string (default "\e033[31m%s\e033[0m") - tempmarks string (default '') - timefmt string (default 'Mon Jan _2 15:04:05 2006') - truncatechar string (default '~') - waitmsg string (default 'Press any key to continue') - wrapscan bool (default on) - wrapscroll bool (default off) - user_{option} string (default none) + anchorfind bool (default on) + autoquit bool (default off) + cleaner string (default '') + cursorfmt string (default "\e033[7m") + cursorpreviewfmt string (default "\e033[4m") + dircache bool (default on) + dircounts bool (default off) + dirfirst bool (default on) + dironly bool (default off) + dirpreviews bool (default off) + drawbox bool (default off) + errorfmt string (default "\e033[7;31;47m") + filesep string (default "\en") + findlen int (default 1) + globsearch bool (default off) + hidden bool (default off) + hiddenfiles []string (default '.*') + history bool (default on) + icons bool (default off) + ifs string (default '') + ignorecase bool (default on) + ignoredia bool (default on) + incfilter bool (default off) + incsearch bool (default off) + info []string (default '') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') + mouse bool (default off) + number bool (default off) + period int (default 0) + preview bool (default on) + previewer string (default '') + promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%d\e033[0m\e033[1m%f\e033[0m") + ratios []int (default '1:2:3') + relativenumber bool (default off) + reverse bool (default off) + scrolloff int (default 0) + selmode string (default 'all') + shell string (default 'sh' for Unix and 'cmd' for Windows) + shellflag string (default '-c' for Unix and '/c' for Windows) + shellopts []string (default '') + smartcase bool (default on) + smartdia bool (default off) + sortby string (default 'natural') + tabstop int (default 8) + tagfmt string (default "\e033[31m") + tempmarks string (default '') + timefmt string (default 'Mon Jan _2 15:04:05 2006') + truncatechar string (default '~') + waitmsg string (default 'Press any key to continue') + wrapscan bool (default on) + wrapscroll bool (default off) + user_{option} string (default none) .EE .PP The following environment variables are exported for shell commands: @@ -747,6 +749,19 @@ Automatically quit server when there are no clients left connected. .PP Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty. .PP +.EX + cursorfmt string (default "\e033[7m") + cursorpreviewfmt string (default "\e033[4m") +.EE +.PP +Format strings for highlighting the cursor. `cursorpreviewfmt` applies in panes that preview directories, and `cursorfmt` applies in all other panes. +.PP +The default is to make the normal cursor inverted and the preview cursor underlined. +.PP +Some other possibilities to consider for the preview cursor: an empty string for no cursor, "\e033[7;2m" for dimmed inverted text (visibility varies by terminal), "\e033[7;90m" for inverted text with grey (aka "brightblack") background. +.PP +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. For example, "\e033[4m%s\e033[0m" has the same effect as "\e033[4m". +.PP .EX dircache bool (default on) .EE @@ -784,11 +799,13 @@ Show only directories. Draw boxes around panes with box drawing characters. .PP .EX - errorfmt string (default "\e033[7;31;47m%s\e033[0m") + errorfmt string (default "\e033[7;31;47m") .EE .PP Format string of error messages shown in the bottom message line. .PP +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. For example, "\e033[4m%s\e033[0m" has the same effect as "\e033[4m". +.PP .EX filesep string (default "\en") .EE @@ -988,11 +1005,13 @@ Sort type for directories. Currently supported sort types are 'natural', 'name', Number of space characters to show for horizontal tabulation (U+0009) character. .PP .EX - tagfmt string (default "\e033[31m%s\e033[0m") + tagfmt string (default "\e033[31m") .EE .PP Format string of the tags. .PP +If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence. For example, "\e033[4m%s\e033[0m" has the same effect as "\e033[4m". +.PP .EX tempmarks string (default '') .EE diff --git a/opts.go b/opts.go index 18a11df6..dd33594c 100644 --- a/opts.go +++ b/opts.go @@ -28,57 +28,59 @@ type sortType struct { } var gOpts struct { - anchorfind bool - autoquit bool - dircache bool - dircounts bool - dironly bool - dirpreviews bool - drawbox bool - globsearch bool - icons bool - ignorecase bool - ignoredia bool - incfilter bool - incsearch bool - mouse bool - number bool - preview bool - relativenumber bool - smartcase bool - smartdia bool - waitmsg string - wrapscan bool - wrapscroll bool - findlen int - period int - scrolloff int - tabstop int - errorfmt string - filesep string - ifs string - previewer string - cleaner string - promptfmt string - selmode string - shell string - shellflag string - timefmt string - infotimefmtnew string - infotimefmtold string - truncatechar string - ratios []int - hiddenfiles []string - history bool - info []string - shellopts []string - keys map[string]expr - cmdkeys map[string]expr - cmds map[string]expr - user map[string]string - sortType sortType - tempmarks string - tagfmt string + anchorfind bool + autoquit bool + cursorfmt string + cursorpreviewfmt string + dircache bool + dircounts bool + dironly bool + dirpreviews bool + drawbox bool + globsearch bool + icons bool + ignorecase bool + ignoredia bool + incfilter bool + incsearch bool + mouse bool + number bool + preview bool + relativenumber bool + smartcase bool + smartdia bool + waitmsg string + wrapscan bool + wrapscroll bool + findlen int + period int + scrolloff int + tabstop int + errorfmt string + filesep string + ifs string + previewer string + cleaner string + promptfmt string + selmode string + shell string + shellflag string + timefmt string + infotimefmtnew string + infotimefmtold string + truncatechar string + ratios []int + hiddenfiles []string + history bool + info []string + shellopts []string + keys map[string]expr + cmdkeys map[string]expr + cmds map[string]expr + user map[string]string + sortType sortType + tempmarks string + tagfmt string } func init() { @@ -89,6 +91,8 @@ func init() { gOpts.dironly = false gOpts.dirpreviews = false gOpts.drawbox = false + gOpts.cursorfmt = "\033[7m" + gOpts.cursorpreviewfmt = "\033[4m" gOpts.globsearch = false gOpts.icons = false gOpts.ignorecase = true @@ -108,7 +112,7 @@ func init() { gOpts.period = 0 gOpts.scrolloff = 0 gOpts.tabstop = 8 - gOpts.errorfmt = "\033[7;31;47m%s\033[0m" + gOpts.errorfmt = "\033[7;31;47m" gOpts.filesep = "\n" gOpts.ifs = "" gOpts.previewer = "" @@ -128,7 +132,7 @@ func init() { gOpts.shellopts = nil gOpts.sortType = sortType{naturalSort, dirfirstSort} gOpts.tempmarks = "'" - gOpts.tagfmt = "\033[31m%s\033[0m" + gOpts.tagfmt = "\033[31m" gOpts.keys = make(map[string]expr) diff --git a/ui.go b/ui.go index 2ed56c81..440e1a9f 100644 --- a/ui.go +++ b/ui.go @@ -432,10 +432,6 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir } } - if i == dir.pos { - st = st.Reverse(true) - } - var s []rune s = append(s, ' ') @@ -477,16 +473,26 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir } } - s = append(s, ' ') + ce := "" + if i == dir.pos { + if dirStyle.previewing { + ce = gOpts.cursorpreviewfmt + } else { + ce = gOpts.cursorfmt + } + } + cursorescapefmt := optionToFmtstr(ce) - win.print(screen, lnwidth+1, i, st, string(s)) + s = append(s, ' ') + styledFilename := fmt.Sprintf(cursorescapefmt, string(s)) + win.print(screen, lnwidth+1, i, st, styledFilename) tag, ok := context.tags[path] if ok { if i == dir.pos { - win.print(screen, lnwidth+1, i, st, tag) + win.print(screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag)) } else { - win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(gOpts.tagfmt, tag)) + win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag)) } } } @@ -652,8 +658,16 @@ func (ui *ui) echomsg(msg string) { log.Print(msg) } +func optionToFmtstr(optstr string) string { + if !strings.Contains(optstr, "%s") { + return optstr + "%s\033[0m" + } else { + return optstr + } +} + func (ui *ui) echoerr(msg string) { - ui.msg = fmt.Sprintf(gOpts.errorfmt, msg) + ui.msg = fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg) log.Printf("error: %s", msg) }