Remove experimental locale feature (#2111)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-08-26 01:41:01 +10:00
1 parent 06955cbacc
commit e60c055be3
10 files changed
+31 -229

No files matched your search

+1 -8
View File
@@ -177,7 +177,6 @@ The following options can be used to customize the behavior of lf:
info []string (default '') info []string (default '')
infotimefmtnew string (default 'Jan _2 15:04') infotimefmtnew string (default 'Jan _2 15:04')
infotimefmtold string (default 'Jan _2 2006') infotimefmtold string (default 'Jan _2 2006')
locale string (default '')
mouse bool (default false) mouse bool (default false)
number bool (default false) number bool (default false)
numberfmt string (default "\033[33m") numberfmt string (default "\033[33m")
@@ -866,12 +865,6 @@ Format string of the file time shown in the info column when it matches this yea
Format string of the file time shown in the info column when it doesn't match this year. Format string of the file time shown in the info column when it doesn't match this year.
## locale (string) (default ``)
An IETF BCP 47 language tag (e.g. `zh-CN`) for specifying the locale used when using sort type `natural` and `name`.
An empty string means disable locale ordering, and the special value `*` is used to indicate reading the locale setting from the system environment.
This feature is currently experimental.
## mouse (bool) (default false) ## mouse (bool) (default false)
Send mouse events as input. Send mouse events as input.
@@ -1272,7 +1265,7 @@ Command `set` is used to set an option which can be a boolean, integer, or strin
set sortby "time" # string value with double quotes (backslash escapes) set sortby "time" # string value with double quotes (backslash escapes)
Command `setlocal` is used to set a local option for a directory which can be a boolean or string. Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `locale`, `reverse` and `sortby`. Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`.
Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories: Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden # boolean enable
+3 -12
View File
@@ -167,7 +167,6 @@ The following options can be used to customize the behavior of lf:
info []string (default '') info []string (default '')
infotimefmtnew string (default 'Jan _2 15:04') infotimefmtnew string (default 'Jan _2 15:04')
infotimefmtold string (default 'Jan _2 2006') infotimefmtold string (default 'Jan _2 2006')
locale string (default '')
mouse bool (default false) mouse bool (default false)
number bool (default false) number bool (default false)
numberfmt string (default "\033[33m") numberfmt string (default "\033[33m")
@@ -922,14 +921,6 @@ infotimefmtold (string) (default Jan _2 2006)
Format string of the file time shown in the info column when it doesn't Format string of the file time shown in the info column when it doesn't
match this year. match this year.
locale (string) (default ``)
An IETF BCP 47 language tag (e.g. zh-CN) for specifying the locale used
when using sort type natural and name. An empty string means disable
locale ordering, and the special value * is used to indicate reading the
locale setting from the system environment. This feature is currently
experimental.
mouse (bool) (default false) mouse (bool) (default false)
Send mouse events as input. Send mouse events as input.
@@ -1403,9 +1394,9 @@ string:
Command setlocal is used to set a local option for a directory which can Command setlocal is used to set a local option for a directory which can
be a boolean or string. Currently supported local options are dircounts, be a boolean or string. Currently supported local options are dircounts,
dirfirst, dironly, hidden, info, locale, reverse and sortby. Adding a dirfirst, dironly, hidden, info, reverse and sortby. Adding a trailing
trailing path separator (i.e. / for Unix and \ for Windows) sets the path separator (i.e. / for Unix and \ for Windows) sets the option for
option for the given directory along with its subdirectories: the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden # boolean enable
setlocal /foo/bar hidden true # boolean enable setlocal /foo/bar hidden true # boolean enable
-22
View File
@@ -276,17 +276,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.infotimefmtnew = e.val gOpts.infotimefmtnew = e.val
case "infotimefmtold": case "infotimefmtold":
gOpts.infotimefmtold = e.val gOpts.infotimefmtold = e.val
case "locale":
localeStr := e.val
if localeStr != localeStrDisable {
if _, err = getLocaleTag(localeStr); err != nil {
app.ui.echoerrf("locale: %s", err.Error())
return
}
}
gOpts.locale = localeStr
app.nav.sort()
app.ui.sort()
case "numberfmt": case "numberfmt":
gOpts.numberfmt = e.val gOpts.numberfmt = e.val
case "period": case "period":
@@ -523,17 +512,6 @@ func (e *setLocalExpr) eval(app *app, args []string) {
gLocalOpts.sortby[e.path] = method gLocalOpts.sortby[e.path] = method
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "locale":
localeStr := e.val
if localeStr != localeStrDisable {
if _, err = getLocaleTag(localeStr); err != nil {
app.ui.echoerrf("locale: %s", err.Error())
return
}
}
gLocalOpts.locale[e.path] = localeStr
app.nav.sort()
app.ui.sort()
default: default:
err = fmt.Errorf("unknown option: %s", e.opt) err = fmt.Errorf("unknown option: %s", e.opt)
} }
+1 -2
View File
@@ -3,18 +3,17 @@ module github.com/gokcehan/lf
go 1.23.0 go 1.23.0
require ( require (
github.com/Xuanwo/go-locale v1.1.3
github.com/djherbis/times v1.6.0 github.com/djherbis/times v1.6.0
github.com/fsnotify/fsnotify v1.9.0 github.com/fsnotify/fsnotify v1.9.0
github.com/gdamore/tcell/v2 v2.9.0 github.com/gdamore/tcell/v2 v2.9.0
github.com/mattn/go-runewidth v0.0.16 github.com/mattn/go-runewidth v0.0.16
golang.org/x/sys v0.35.0 golang.org/x/sys v0.35.0
golang.org/x/term v0.34.0 golang.org/x/term v0.34.0
golang.org/x/text v0.28.0
) )
require ( require (
github.com/gdamore/encoding v1.0.1 // indirect github.com/gdamore/encoding v1.0.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/text v0.28.0 // indirect
) )
-2
View File
@@ -1,5 +1,3 @@
github.com/Xuanwo/go-locale v1.1.3 h1:EWZZJJt5rqPHHbqPRH1zFCn5D7xHjjebODctA4aUO3A=
github.com/Xuanwo/go-locale v1.1.3/go.mod h1:REn+F/c+AtGSWYACBSYZgl23AP+0lfQC+SEFPN+hj30=
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c= github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0= github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
+2 -12
View File
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.7.0.2 .\" Automatically generated by Pandoc 3.7.0.2
.\" .\"
.TH "LF" "1" "2025\-08\-25" "r37" "DOCUMENTATION" .TH "LF" "1" "2025\-08\-26" "r37" "DOCUMENTATION"
.SH NAME .SH NAME
lf \- terminal file manager lf \- terminal file manager
.SH SYNOPSIS .SH SYNOPSIS
@@ -182,7 +182,6 @@ incsearch bool (default false)
info []string (default \(aq\(aq) info []string (default \(aq\(aq)
infotimefmtnew string (default \(aqJan _2 15:04\(aq) infotimefmtnew string (default \(aqJan _2 15:04\(aq)
infotimefmtold string (default \(aqJan _2 2006\(aq) infotimefmtold string (default \(aqJan _2 2006\(aq)
locale string (default \(aq\(aq)
mouse bool (default false) mouse bool (default false)
number bool (default false) number bool (default false)
numberfmt string (default \(dq\(rs033[33m\(dq) numberfmt string (default \(dq\(rs033[33m\(dq)
@@ -806,14 +805,6 @@ this year.
.SS infotimefmtold (string) (default \f[CR]Jan _2 2006\f[R]) .SS infotimefmtold (string) (default \f[CR]Jan _2 2006\f[R])
Format string of the file time shown in the info column when it Format string of the file time shown in the info column when it
doesn\(aqt match this year. doesn\(aqt match this year.
.SS locale (string) (default \(ga\(ga)
An IETF BCP 47 language tag (e.g.
\f[CR]zh\-CN\f[R]) for specifying the locale used when using sort type
\f[CR]natural\f[R] and \f[CR]name\f[R].
An empty string means disable locale ordering, and the special value
\f[CR]*\f[R] is used to indicate reading the locale setting from the
system environment.
This feature is currently experimental.
.SS mouse (bool) (default false) .SS mouse (bool) (default false)
Send mouse events as input. Send mouse events as input.
.SS number (bool) (default false) .SS number (bool) (default false)
@@ -1209,8 +1200,7 @@ Command \f[CR]setlocal\f[R] is used to set a local option for a
directory which can be a boolean or string. directory which can be a boolean or string.
Currently supported local options are \f[CR]dircounts\f[R], Currently supported local options are \f[CR]dircounts\f[R],
\f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R], \f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R],
\f[CR]info\f[R], \f[CR]locale\f[R], \f[CR]reverse\f[R] and \f[CR]info\f[R], \f[CR]reverse\f[R] and \f[CR]sortby\f[R].
\f[CR]sortby\f[R].
Adding a trailing path separator (i.e. Adding a trailing path separator (i.e.
\f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option \f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option
for the given directory along with its subdirectories: for the given directory along with its subdirectories:
-42
View File
@@ -13,15 +13,7 @@ import (
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
"github.com/Xuanwo/go-locale"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
const (
localeStrDisable = "" // disable locale ordering for this locale value
localeStrSys = "*" // replace this locale value with locale value read from environment
) )
func isRoot(name string) bool { return filepath.Dir(name) == name } func isRoot(name string) bool { return filepath.Dir(name) == name }
@@ -344,40 +336,6 @@ var (
reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`) reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
) )
// This function parses given locale string into language tag value. Passing empty
// string as locale means reading locale value from environment.
func getLocaleTag(localeStr string) (language.Tag, error) {
if localeStr == localeStrSys {
// read environment locale
return locale.Detect()
}
localeTag, err := language.Parse(localeStr)
if err != nil {
return localeTag, fmt.Errorf("invalid locale %q: %s", localeStr, err)
}
return localeTag, nil
}
// This function creates new collator for given locale. Passing empty string as
// as locale means reading locale value from environment.
//
// *Note*: this function returns error when given `localeStr` has value `localeStrDisable`
// or is an invalid locale tag.
func makeCollator(localeStr string, opts ...collate.Option) (*collate.Collator, error) {
if localeStr == localeStrDisable {
return nil, fmt.Errorf("locale is disabled")
}
localeTag, err := getLocaleTag(localeStr)
if err != nil {
return nil, err
}
return collate.New(localeTag, opts...), nil
}
// This function deletes entries from a map if the key is either the given path // This function deletes entries from a map if the key is either the given path
// or a subpath of it. // or a subpath of it.
// This is useful for clearing cached data when a directory is moved or deleted. // This is useful for clearing cached data when a directory is moved or deleted.
-51
View File
@@ -7,8 +7,6 @@ import (
"strings" "strings"
"testing" "testing"
"time" "time"
"golang.org/x/text/collate"
) )
func TestIsRoot(t *testing.T) { func TestIsRoot(t *testing.T) {
@@ -363,55 +361,6 @@ func TestGetFileExtension(t *testing.T) {
} }
} }
func TestLocaleNaturalLess(t *testing.T) {
tests := []struct {
s1 string
s2 string
exp bool
}{
// preserving behavior of `naturalLess`
{"foo", "bar", false},
{"bar", "baz", true},
{"foo", "123", false},
{"foo1", "foobar", true},
{"foo1", "foo10", true},
{"foo2", "foo10", true},
{"foo1", "foo10bar", true},
{"foo2", "foo10bar", true},
{"foo1bar", "foo10bar", true},
{"foo2bar", "foo10bar", true},
{"foo1bar", "foo10", true},
{"foo2bar", "foo10", true},
// locale sort
{"你好", "他好", true}, // \u4F60\u597D, \u4ED6\u597D
{"到这", "到那", false}, // \u5230\u8FD9, \u5230\u90A3
{"你说", "什么", true}, // \u4f60\u8bf4, \u4ec0\u4e48
{"你好", "World", false}, // \u4F60\u597D, \u57\u6f\u72\u6c\u64
{"甲1", "甲乙", true},
{"甲1", "甲10", true},
{"甲2", "甲10", true},
{"甲1", "甲10乙", true},
{"甲2", "甲10乙", true},
{"甲1乙", "甲10乙", true},
{"甲2乙", "甲10乙", true},
{"甲1乙", "甲10", true},
{"甲2乙", "甲10", true},
}
localeStr := "zh-CN"
collator, err := makeCollator(localeStr, collate.Numeric)
if err != nil {
t.Fatalf("failed to create collator for %q: %s", localeStr, err)
}
for _, test := range tests {
if got := collator.CompareString(test.s1, test.s2) < 0; got != test.exp {
t.Errorf("at input '%s' and '%s' expected '%t' but got '%t'", test.s1, test.s2, test.exp, got)
}
}
}
func TestStripAnsi(t *testing.T) { func TestStripAnsi(t *testing.T) {
tests := []struct { tests := []struct {
s string s string
+24 -65
View File
@@ -18,7 +18,6 @@ import (
"time" "time"
"github.com/djherbis/times" "github.com/djherbis/times"
"golang.org/x/text/collate"
) )
type linkState byte type linkState byte
@@ -188,7 +187,6 @@ type dir struct {
filter []string // last filter for this directory filter []string // last filter for this directory
ignorecase bool // ignorecase value from last sort ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort ignoredia bool // ignoredia value from last sort
locale string // locale value from last sort
noPerm bool // whether lf has no permission to open the directory noPerm bool // whether lf has no permission to open the directory
} }
@@ -227,7 +225,6 @@ func (dir *dir) sort() {
dir.dironly = getDirOnly(dir.path) dir.dironly = getDirOnly(dir.path)
dir.hidden = getHidden(dir.path) dir.hidden = getHidden(dir.path)
dir.reverse = getReverse(dir.path) dir.reverse = getReverse(dir.path)
dir.locale = getLocale(dir.path)
dir.hiddenfiles = gOpts.hiddenfiles dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia dir.ignoredia = gOpts.ignoredia
@@ -238,68 +235,32 @@ func (dir *dir) sort() {
// of equivalent elements will be reversed // of equivalent elements will be reversed
switch dir.sortby { switch dir.sortby {
case naturalSort: case naturalSort:
if collator, err := makeCollator(dir.locale, collate.Numeric); err == nil { sort.SliceStable(dir.files, func(i, j int) bool {
sort.SliceStable(dir.files, func(i, j int) bool { s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) if !dir.reverse {
result := collator.CompareString(s1, s2) return naturalLess(s1, s2)
if !dir.reverse { } else {
return result < 0 return naturalLess(s2, s1)
} else { }
return result > 0 })
}
})
} else {
sort.SliceStable(dir.files, func(i, j int) bool {
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
if !dir.reverse {
return naturalLess(s1, s2)
} else {
return naturalLess(s2, s1)
}
})
}
case customSort: case customSort:
if collator, err := makeCollator(dir.locale, collate.Numeric); err == nil { sort.SliceStable(dir.files, func(i, j int) bool {
sort.SliceStable(dir.files, func(i, j int) bool { s1, s2 := normalize(stripAnsi(dir.files[i].customInfo), stripAnsi(dir.files[j].customInfo), dir.ignorecase, dir.ignoredia)
s1, s2 := normalize(stripAnsi(dir.files[i].customInfo), stripAnsi(dir.files[j].customInfo), dir.ignorecase, dir.ignoredia) if !dir.reverse {
result := collator.CompareString(s1, s2) return naturalLess(s1, s2)
if !dir.reverse { } else {
return result < 0 return naturalLess(s2, s1)
} else { }
return result > 0 })
}
})
} else {
sort.SliceStable(dir.files, func(i, j int) bool {
s1, s2 := normalize(stripAnsi(dir.files[i].customInfo), stripAnsi(dir.files[j].customInfo), dir.ignorecase, dir.ignoredia)
if !dir.reverse {
return naturalLess(s1, s2)
} else {
return naturalLess(s2, s1)
}
})
}
case nameSort: case nameSort:
if collator, err := makeCollator(dir.locale); err == nil { sort.SliceStable(dir.files, func(i, j int) bool {
sort.SliceStable(dir.files, func(i, j int) bool { s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) if !dir.reverse {
result := collator.CompareString(s1, s2) return s1 < s2
if !dir.reverse { } else {
return result < 0 return s2 < s1
} else { }
return result > 0 })
}
})
} else {
sort.SliceStable(dir.files, func(i, j int) bool {
s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia)
if !dir.reverse {
return s1 < s2
} else {
return s2 < s1
}
})
}
case sizeSort: case sizeSort:
sizeVal := func(f *file) int64 { sizeVal := func(f *file) int64 {
if f.IsDir() && dir.dircounts { if f.IsDir() && dir.dircounts {
@@ -589,7 +550,6 @@ func (nav *nav) loadDir(path string) *dir {
dironly: getDirOnly(path), dironly: getDirOnly(path),
hidden: getHidden(path), hidden: getHidden(path),
reverse: getReverse(path), reverse: getReverse(path),
locale: getLocale(path),
visualAnchor: -1, visualAnchor: -1,
hiddenfiles: gOpts.hiddenfiles, hiddenfiles: gOpts.hiddenfiles,
ignorecase: gOpts.ignorecase, ignorecase: gOpts.ignorecase,
@@ -639,7 +599,6 @@ func (nav *nav) checkDir(dir *dir) {
dir.dironly != getDirOnly(dir.path) || dir.dironly != getDirOnly(dir.path) ||
dir.hidden != getHidden(dir.path) || dir.hidden != getHidden(dir.path) ||
dir.reverse != getReverse(dir.path) || dir.reverse != getReverse(dir.path) ||
dir.locale != getLocale(dir.path) ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase || dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia: dir.ignoredia != gOpts.ignoredia:
-13
View File
@@ -75,7 +75,6 @@ var gOpts struct {
info []string info []string
infotimefmtnew string infotimefmtnew string
infotimefmtold string infotimefmtold string
locale string
mouse bool mouse bool
number bool number bool
numberfmt string numberfmt string
@@ -125,7 +124,6 @@ var gLocalOpts struct {
dironly map[string]bool dironly map[string]bool
hidden map[string]bool hidden map[string]bool
info map[string][]string info map[string][]string
locale map[string]string
reverse map[string]bool reverse map[string]bool
sortby map[string]sortMethod sortby map[string]sortMethod
} }
@@ -183,15 +181,6 @@ func getInfo(path string) []string {
return gOpts.info return gOpts.info
} }
func getLocale(path string) string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.locale[key]; ok {
return val
}
}
return gOpts.locale
}
func getReverse(path string) bool { func getReverse(path string) bool {
for _, key := range localOptPaths(path) { for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.reverse[key]; ok { if val, ok := gLocalOpts.reverse[key]; ok {
@@ -242,7 +231,6 @@ func init() {
gOpts.info = nil gOpts.info = nil
gOpts.infotimefmtnew = "Jan _2 15:04" gOpts.infotimefmtnew = "Jan _2 15:04"
gOpts.infotimefmtold = "Jan _2 2006" gOpts.infotimefmtold = "Jan _2 2006"
gOpts.locale = localeStrDisable
gOpts.mouse = false gOpts.mouse = false
gOpts.number = false gOpts.number = false
gOpts.numberfmt = "\033[33m" gOpts.numberfmt = "\033[33m"
@@ -417,7 +405,6 @@ func init() {
gLocalOpts.dironly = make(map[string]bool) gLocalOpts.dironly = make(map[string]bool)
gLocalOpts.hidden = make(map[string]bool) gLocalOpts.hidden = make(map[string]bool)
gLocalOpts.info = make(map[string][]string) gLocalOpts.info = make(map[string][]string)
gLocalOpts.locale = make(map[string]string)
gLocalOpts.reverse = make(map[string]bool) gLocalOpts.reverse = make(map[string]bool)
gLocalOpts.sortby = make(map[string]sortMethod) gLocalOpts.sortby = make(map[string]sortMethod)