From 0a2c514f7e9ca2e8efd97bdb8268e432a017b0d3 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 18 Jan 2023 20:48:57 -0800 Subject: [PATCH] Cursorfmt & crusorpreviewfmt options to style cursor in normal/preview panes This allows using a different style for the normal and preview cursor. See linked issues and PRs for the context. The default behavior is an underline, same as in https://github.com/gokcehan/lf/pull/1072, since it should not cause severe problems and be visible on all terminals. It can now be easily changed. Fixes https://github.com/gokcehan/lf/issues/1038 Follows up on: https://github.com/gokcehan/lf/pull/1072 https://github.com/gokcehan/lf/pull/924 https://github.com/gokcehan/lf/commit/b47cf6d5a5 --- complete.go | 2 + doc.go | 114 +++++++++++++++++++++++++++---------------------- docstring.go | 117 +++++++++++++++++++++++++++++---------------------- eval.go | 4 ++ lf.1 | 115 ++++++++++++++++++++++++++++---------------------- opts.go | 106 ++++++++++++++++++++++++---------------------- ui.go | 20 ++++++--- 7 files changed, 267 insertions(+), 211 deletions(-) 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..c9341e93 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%s\033[0m") + cursorpreviewfmt string (default "\033[4m%s\033[0m") + 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) The following environment variables are exported for shell commands: @@ -606,6 +608,16 @@ 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%s\033[0m") + cursorpreviewfmt string (default "\033[4m%s\033[0m") + +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: "%s" for no cursor, "\033[7,2m%s\044[0m" for dimmed inverted text (visibility varies by terminal), "\033[7;90m%s\044[0m" for inverted text with grey background. + dircache bool (default on) Cache directory contents. diff --git a/docstring.go b/docstring.go index 9d9fe9a9..9be4d216 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%s\033[0m") + cursorpreviewfmt string (default "\033[4m%s\033[0m") + 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) The following environment variables are exported for shell commands: @@ -632,6 +634,19 @@ 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%s\033[0m") + cursorpreviewfmt string (default "\033[4m%s\033[0m") + +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: "%s" for no cursor, +"\033[7,2m%s\044[0m" for dimmed inverted text (visibility varies by terminal), +"\033[7;90m%s\044[0m" for inverted text with grey background. + dircache bool (default on) Cache directory contents. 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..e15dc0de 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%s\e033[0m") + cursorpreviewfmt string (default "\e033[4m%s\e033[0m") + 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) .EE .PP The following environment variables are exported for shell commands: @@ -747,6 +749,17 @@ 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%s\e033[0m") + cursorpreviewfmt string (default "\e033[4m%s\e033[0m") +.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: "%s" for no cursor, "\e033[7,2m%s\e044[0m" for dimmed inverted text (visibility varies by terminal), "\e033[7;90m%s\e044[0m" for inverted text with grey background. +.PP .EX dircache bool (default on) .EE diff --git a/opts.go b/opts.go index 18a11df6..b661ee76 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%s\033[0m" + gOpts.cursorpreviewfmt = "\033[4m%s\033[0m" gOpts.globsearch = false gOpts.icons = false gOpts.ignorecase = true diff --git a/ui.go b/ui.go index 2ed56c81..9479acf7 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,14 +473,24 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir } } - s = append(s, ' ') + cursorescapefmt := "%s" + if i == dir.pos { + if dirStyle.previewing { + cursorescapefmt = gOpts.cursorpreviewfmt - win.print(screen, lnwidth+1, i, st, string(s)) + } else { + cursorescapefmt = gOpts.cursorfmt + } + } + + 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)) }