From d8b9bab3eaff41c19825a1995bb4949b1a6b1752 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Tue, 8 Jan 2019 22:47:41 +0300 Subject: [PATCH] add 'color256' option to control color mode Related #104 --- client.go | 2 +- complete.go | 3 +++ doc.go | 13 +++++++++++++ docstring.go | 14 ++++++++++++++ eval.go | 15 +++++++++++++++ lf.1 | 5 +++++ opts.go | 2 ++ ui.go | 8 ++++++++ 8 files changed, 61 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 3f20469..28c9489 100644 --- a/client.go +++ b/client.go @@ -29,7 +29,7 @@ func run() { } defer termbox.Close() - termbox.SetOutputMode(termbox.Output256) + setColorMode() app := newApp() diff --git a/complete.go b/complete.go index 6fe78fc..f192a27 100644 --- a/complete.go +++ b/complete.go @@ -64,6 +64,9 @@ var ( "anchorfind", "noanchorfind", "anchorfind!", + "color256", + "nocolor256", + "color256!", "dircounts", "nodircounts", "dircounts!", diff --git a/doc.go b/doc.go index 5c447e3..b3906eb 100644 --- a/doc.go +++ b/doc.go @@ -95,6 +95,7 @@ keybindings: The following options can be used to customize the behavior of lf: anchorfind boolean (default on) + color256 boolean (default off) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) @@ -638,6 +639,13 @@ If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute. +You should also note that lf uses 8 color mode by default which uses sgr 3-bit +color escapes (e.g. '\033[34m'). If you want to use 256 colors, you need to +enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. +'\033[38;5;4m'). This option is intended to eliminate differences between +default colors used by ls and lf since terminals may render 3-bit and 8-bit +escapes differently even for the same color. + Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you @@ -650,5 +658,10 @@ fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results. + +Lastly, you may also want to configure the colors of the prompt line to match +the rest of the colors. Colors of the prompt line can be configured using the +'promptfmt' option which can include hardcoded colors as ansi escapes. See the +default value of this option to have an idea about how to color this line. */ package main diff --git a/docstring.go b/docstring.go index 511a837..5b8d7c7 100644 --- a/docstring.go +++ b/docstring.go @@ -98,6 +98,7 @@ keybindings: The following options can be used to customize the behavior of lf: anchorfind boolean (default on) + color256 boolean (default off) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) @@ -668,6 +669,13 @@ If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute. +You should also note that lf uses 8 color mode by default which uses sgr +3-bit color escapes (e.g. '\033[34m'). If you want to use 256 colors, you +need to enable 'color256' option which then makes lf use sgr 8-bit color +escapes (e.g. '\033[38;5;4m'). This option is intended to eliminate +differences between default colors used by ls and lf since terminals may +render 3-bit and 8-bit escapes differently even for the same color. + Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you @@ -681,4 +689,10 @@ different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results. + +Lastly, you may also want to configure the colors of the prompt line to +match the rest of the colors. Colors of the prompt line can be configured +using the 'promptfmt' option which can include hardcoded colors as ansi +escapes. See the default value of this option to have an idea about how to +color this line. ` diff --git a/eval.go b/eval.go index 0b332c9..d8cf436 100644 --- a/eval.go +++ b/eval.go @@ -20,6 +20,21 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.anchorfind = false case "anchorfind!": gOpts.anchorfind = !gOpts.anchorfind + case "color256": + gOpts.color256 = true + setColorMode() + app.ui.pause() + app.ui.resume() + case "nocolor256": + gOpts.color256 = false + setColorMode() + app.ui.pause() + app.ui.resume() + case "color256!": + gOpts.color256 = !gOpts.color256 + setColorMode() + app.ui.pause() + app.ui.resume() case "dircounts": gOpts.dircounts = true case "nodircounts": diff --git a/lf.1 b/lf.1 index 4efb79c..fa06321 100644 --- a/lf.1 +++ b/lf.1 @@ -110,6 +110,7 @@ The following options can be used to customize the behavior of lf: .PP .EX anchorfind boolean (default on) + color256 boolean (default off) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) @@ -613,6 +614,10 @@ If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead. Th .PP If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute. .PP +You should also note that lf uses 8 color mode by default which uses sgr 3-bit color escapes (e.g. '\e033[34m'). If you want to use 256 colors, you need to enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. '\e033[38;5;4m'). This option is intended to eliminate differences between default colors used by ls and lf since terminals may render 3-bit and 8-bit escapes differently even for the same color. +.PP Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other. .PP Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results. +.PP +Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors. Colors of the prompt line can be configured using the 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line. diff --git a/opts.go b/opts.go index 33accd1..1a56d89 100644 --- a/opts.go +++ b/opts.go @@ -26,6 +26,7 @@ type sortType struct { var gOpts struct { anchorfind bool + color256 bool dircounts bool drawbox bool globsearch bool @@ -57,6 +58,7 @@ var gOpts struct { func init() { gOpts.anchorfind = true + gOpts.color256 = false gOpts.dircounts = false gOpts.drawbox = false gOpts.globsearch = false diff --git a/ui.go b/ui.go index bfe8db3..2a1e029 100644 --- a/ui.go +++ b/ui.go @@ -892,6 +892,14 @@ func (ui *ui) readExpr() <-chan expr { return ch } +func setColorMode() { + if gOpts.color256 { + termbox.SetOutputMode(termbox.Output256) + } else { + termbox.SetOutputMode(termbox.OutputNormal) + } +} + func (ui *ui) pause() { termbox.Close() }