Add support for displaying lf options in the ruler (#1257)
* Add support for displaying lf options in the ruler * Print escape character as plain text * Document user defined options * Change escape rules * Use reflect instead of environment table * Factor out common option map logic * Improve error message slightly * Display blank option values
This commit is contained in:
1 parent
0ac1491bfb
commit
e08eebb115
6 files changed
+54
-28
No files matched your search
@@ -845,13 +845,15 @@ Reverse the direction of sort.
|
||||
ruler []string (default 'acc:progress:selection:filter:ind')
|
||||
|
||||
List of information shown in status line ruler.
|
||||
Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'.
|
||||
Currently supported information types are 'acc', 'progress', 'selection', 'filter', 'ind', 'df' and names starting with 'lf_'.
|
||||
`acc` shows the pressed keys (e.g. for bindings with multiple key presses or counts given to bindings).
|
||||
`progress` shows the progress of file operations (e.g. copying a large directory).
|
||||
`selection` shows the number of files that are selected, or designated for being cut/copied.
|
||||
`filter` shows 'F' if a filter is currently being applied.
|
||||
`ind` shows the current position of the cursor as well as the number of files in the current directory.
|
||||
`df` shows the amount of free disk space remaining.
|
||||
Names starting with `lf_` show the value of environment variables exported by lf. This is useful for displaying the current settings (e.g. `lf_selmode` displays the current setting for the `selmode` option).
|
||||
User defined options starting with `lf_user_` are also supported, so it is possible to display information set from external sources.
|
||||
|
||||
selmode string (default 'all')
|
||||
|
||||
|
||||
+13
-8
@@ -903,14 +903,19 @@ Reverse the direction of sort.
|
||||
ruler []string (default 'acc:progress:selection:filter:ind')
|
||||
|
||||
List of information shown in status line ruler. Currently supported information
|
||||
types are 'acc', 'progress', 'selection', 'ind' and 'df'. 'acc' shows the
|
||||
pressed keys (e.g. for bindings with multiple key presses or counts given to
|
||||
bindings). 'progress' shows the progress of file operations (e.g. copying a
|
||||
large directory). 'selection' shows the number of files that are selected,
|
||||
or designated for being cut/copied. 'filter' shows 'F' if a filter is currently
|
||||
being applied. 'ind' shows the current position of the cursor as well as the
|
||||
number of files in the current directory. 'df' shows the amount of free disk
|
||||
space remaining.
|
||||
types are 'acc', 'progress', 'selection', 'filter', 'ind', 'df' and names
|
||||
starting with 'lf_'. 'acc' shows the pressed keys (e.g. for bindings with
|
||||
multiple key presses or counts given to bindings). 'progress' shows the progress
|
||||
of file operations (e.g. copying a large directory). 'selection' shows the
|
||||
number of files that are selected, or designated for being cut/copied. 'filter'
|
||||
shows 'F' if a filter is currently being applied. 'ind' shows the current
|
||||
position of the cursor as well as the number of files in the current directory.
|
||||
'df' shows the amount of free disk space remaining. Names starting with 'lf_'
|
||||
show the value of environment variables exported by lf. This is useful for
|
||||
displaying the current settings (e.g. 'lf_selmode' displays the current setting
|
||||
for the 'selmode' option). User defined options starting with 'lf_user_' are
|
||||
also supported, so it is possible to display information set from external
|
||||
sources.
|
||||
|
||||
selmode string (default 'all')
|
||||
|
||||
|
||||
@@ -494,8 +494,10 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
switch s {
|
||||
case "df", "acc", "progress", "selection", "filter", "ind":
|
||||
default:
|
||||
app.ui.echoerr("ruler: should consist of 'df', 'acc', 'progress', 'selection', 'filter' or 'ind' separated with colon")
|
||||
return
|
||||
if !strings.HasPrefix(s, "lf_") {
|
||||
app.ui.echoerr("ruler: should consist of 'df', 'acc', 'progress', 'selection', 'filter', 'ind' or 'lf_<option_name>' separated with colon")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
gOpts.ruler = toks
|
||||
|
||||
@@ -1014,7 +1014,7 @@ Reverse the direction of sort.
|
||||
ruler []string (default 'acc:progress:selection:filter:ind')
|
||||
.EE
|
||||
.PP
|
||||
List of information shown in status line ruler. Currently supported information types are 'acc', 'progress', 'selection', 'ind' and 'df'. `acc` shows the pressed keys (e.g. for bindings with multiple key presses or counts given to bindings). `progress` shows the progress of file operations (e.g. copying a large directory). `selection` shows the number of files that are selected, or designated for being cut/copied. `filter` shows 'F' if a filter is currently being applied. `ind` shows the current position of the cursor as well as the number of files in the current directory. `df` shows the amount of free disk space remaining.
|
||||
List of information shown in status line ruler. Currently supported information types are 'acc', 'progress', 'selection', 'filter', 'ind', 'df' and names starting with 'lf_'. `acc` shows the pressed keys (e.g. for bindings with multiple key presses or counts given to bindings). `progress` shows the progress of file operations (e.g. copying a large directory). `selection` shows the number of files that are selected, or designated for being cut/copied. `filter` shows 'F' if a filter is currently being applied. `ind` shows the current position of the cursor as well as the number of files in the current directory. `df` shows the amount of free disk space remaining. Names starting with `lf_` show the value of environment variables exported by lf. This is useful for displaying the current settings (e.g. `lf_selmode` displays the current setting for the `selmode` option). User defined options starting with `lf_user_` are also supported, so it is possible to display information set from external sources.
|
||||
.PP
|
||||
.EX
|
||||
selmode string (default 'all')
|
||||
|
||||
@@ -115,7 +115,8 @@ func fieldToString(field reflect.Value) string {
|
||||
return value
|
||||
}
|
||||
|
||||
func exportOpts() {
|
||||
func getOptsMap() map[string]string {
|
||||
opts := make(map[string]string)
|
||||
v := reflect.ValueOf(gOpts)
|
||||
t := v.Type()
|
||||
|
||||
@@ -149,27 +150,27 @@ func exportOpts() {
|
||||
sortby = "ext"
|
||||
}
|
||||
|
||||
os.Setenv("lf_sortby", sortby)
|
||||
|
||||
reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
|
||||
os.Setenv("lf_reverse", reverse)
|
||||
|
||||
hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
|
||||
os.Setenv("lf_hidden", hidden)
|
||||
|
||||
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
|
||||
os.Setenv("lf_dirfirst", dirfirst)
|
||||
opts["lf_sortby"] = sortby
|
||||
opts["lf_reverse"] = strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
|
||||
opts["lf_hidden"] = strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
|
||||
opts["lf_dirfirst"] = strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
|
||||
} else if name == "lf_user" {
|
||||
// set each user option
|
||||
for key, value := range gOpts.user {
|
||||
os.Setenv(name+"_"+key, value)
|
||||
opts[name+"_"+key] = value
|
||||
}
|
||||
} else {
|
||||
field := v.Field(i)
|
||||
value := fieldToString(field)
|
||||
os.Setenv(name, value)
|
||||
opts[name] = fieldToString(v.Field(i))
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func exportOpts() {
|
||||
for key, value := range getOptsMap() {
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
|
||||
@@ -804,6 +804,18 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
||||
ui.promptWin.print(ui.screen, 0, 0, st, prompt)
|
||||
}
|
||||
|
||||
func formatRulerOpt(name string, val string) string {
|
||||
// handle escape character so it doesn't mess up the ruler
|
||||
val = strings.ReplaceAll(val, "\033", "\033[7m\\033\033[0m")
|
||||
|
||||
// display name of builtin options for clarity
|
||||
if !strings.HasPrefix(name, "lf_user_") {
|
||||
val = fmt.Sprintf("%s=%s", strings.TrimPrefix(name, "lf_"), val)
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func (ui *ui) drawStatLine(nav *nav) {
|
||||
st := tcell.StyleDefault
|
||||
|
||||
@@ -855,6 +867,7 @@ func (ui *ui) drawStatLine(nav *nav) {
|
||||
progress = append(progress, fmt.Sprintf("[%d/%d]", nav.deleteCount, nav.deleteTotal))
|
||||
}
|
||||
|
||||
opts := getOptsMap()
|
||||
ruler := []string{}
|
||||
for _, s := range gOpts.ruler {
|
||||
switch s {
|
||||
@@ -875,8 +888,11 @@ func (ui *ui) drawStatLine(nav *nav) {
|
||||
}
|
||||
case "ind":
|
||||
ruler = append(ruler, fmt.Sprintf("%d/%d", ind, tot))
|
||||
default:
|
||||
if val, ok := opts[s]; ok {
|
||||
ruler = append(ruler, formatRulerOpt(s, val))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ui.msgWin.printRight(ui.screen, 0, st, strings.Join(ruler, " "))
|
||||
|
||||
Reference in new issue
Block a user