add 'color256' option to control color mode

Related #104
This commit is contained in:
Gokcehan 2019-01-08 22:47:41 +03:00
parent c5297d6b6b
commit d8b9bab3ea
8 changed files with 61 additions and 1 deletions

View File

@ -29,7 +29,7 @@ func run() {
}
defer termbox.Close()
termbox.SetOutputMode(termbox.Output256)
setColorMode()
app := newApp()

View File

@ -64,6 +64,9 @@ var (
"anchorfind",
"noanchorfind",
"anchorfind!",
"color256",
"nocolor256",
"color256!",
"dircounts",
"nodircounts",
"dircounts!",

13
doc.go
View File

@ -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

View File

@ -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.
`

15
eval.go
View File

@ -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":

5
lf.1
View File

@ -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.

View File

@ -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

8
ui.go
View File

@ -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()
}