From 791b704257d19259e39ba6b6e1d55cc5497b2187 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Wed, 27 Mar 2019 22:07:41 +0300 Subject: [PATCH] add 'errorfmt' option to format error messages Related #154 --- complete.go | 1 + doc.go | 1 + docstring.go | 1 + eval.go | 2 ++ lf.1 | 1 + opts.go | 2 ++ ui.go | 2 +- 7 files changed, 9 insertions(+), 1 deletion(-) diff --git a/complete.go b/complete.go index 279cd48..ad20780 100644 --- a/complete.go +++ b/complete.go @@ -118,6 +118,7 @@ var ( "period", "scrolloff", "tabstop", + "errorfmt", "filesep", "ifs", "previewer", diff --git a/doc.go b/doc.go index d8bb009..f394e58 100644 --- a/doc.go +++ b/doc.go @@ -117,6 +117,7 @@ The following options can be used to customize the behavior of lf: period integer (default 0) (zero to disable periodic loading) scrolloff integer (default 0) tabstop integer (default 8) + errorfmt string (default "\033[7;31;47m%s\033[0m") filesep string (default "\n") ifs string (default '') (not exported if empty) previewer string (default '') (not filtered if empty) diff --git a/docstring.go b/docstring.go index 5e7e24c..23ff8d8 100644 --- a/docstring.go +++ b/docstring.go @@ -120,6 +120,7 @@ The following options can be used to customize the behavior of lf: period integer (default 0) (zero to disable periodic loading) scrolloff integer (default 0) tabstop integer (default 8) + errorfmt string (default "\033[7;31;47m%s\033[0m") filesep string (default "\n") ifs string (default ”) (not exported if empty) previewer string (default ”) (not filtered if empty) diff --git a/eval.go b/eval.go index eff0678..33415d1 100644 --- a/eval.go +++ b/eval.go @@ -205,6 +205,8 @@ func (e *setExpr) eval(app *app, args []string) { return } gOpts.tabstop = n + case "errorfmt": + gOpts.errorfmt = e.val case "filesep": gOpts.filesep = e.val case "ifs": diff --git a/lf.1 b/lf.1 index 2d5a04f..d51661e 100644 --- a/lf.1 +++ b/lf.1 @@ -132,6 +132,7 @@ The following options can be used to customize the behavior of lf: period integer (default 0) (zero to disable periodic loading) scrolloff integer (default 0) tabstop integer (default 8) + errorfmt string (default "\e033[7;31;47m%s\e033[0m") filesep string (default "\en") ifs string (default ”) (not exported if empty) previewer string (default ”) (not filtered if empty) diff --git a/opts.go b/opts.go index e1ac65d..cbc08c6 100644 --- a/opts.go +++ b/opts.go @@ -43,6 +43,7 @@ var gOpts struct { period int scrolloff int tabstop int + errorfmt string filesep string ifs string previewer string @@ -75,6 +76,7 @@ func init() { gOpts.period = 0 gOpts.scrolloff = 0 gOpts.tabstop = 8 + gOpts.errorfmt = "\033[7;31;47m%s\033[0m" gOpts.filesep = "\n" gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m" gOpts.shell = gDefaultShell diff --git a/ui.go b/ui.go index 5a2e5b7..7b3b981 100644 --- a/ui.go +++ b/ui.go @@ -499,7 +499,7 @@ func (ui *ui) echomsgf(format string, a ...interface{}) { } func (ui *ui) echoerr(msg string) { - ui.msg = fmt.Sprintf("\033[7;31;47m%s\033[0m", msg) + ui.msg = fmt.Sprintf(gOpts.errorfmt, msg) log.Printf("error: %s", msg) }