diff --git a/doc.md b/doc.md index f0e821e1..0ba51001 100644 --- a/doc.md +++ b/doc.md @@ -177,7 +177,6 @@ The following options can be used to customize the behavior of lf: info []string (default '') infotimefmtnew string (default 'Jan _2 15:04') infotimefmtold string (default 'Jan _2 2006') - locale string (default '') mouse bool (default false) number bool (default false) 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. -## 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) 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) 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: setlocal /foo/bar hidden # boolean enable diff --git a/doc.txt b/doc.txt index b5a89946..22264a60 100644 --- a/doc.txt +++ b/doc.txt @@ -167,7 +167,6 @@ The following options can be used to customize the behavior of lf: info []string (default '') infotimefmtnew string (default 'Jan _2 15:04') infotimefmtold string (default 'Jan _2 2006') - locale string (default '') mouse bool (default false) number bool (default false) 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 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) Send mouse events as input. @@ -1403,9 +1394,9 @@ 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. Adding a -trailing path separator (i.e. / for Unix and \ for Windows) sets the -option for the given directory along with its subdirectories: +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: setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden true # boolean enable diff --git a/eval.go b/eval.go index ba48890c..7bbd6875 100644 --- a/eval.go +++ b/eval.go @@ -276,17 +276,6 @@ func (e *setExpr) eval(app *app, args []string) { gOpts.infotimefmtnew = e.val case "infotimefmtold": 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": gOpts.numberfmt = e.val case "period": @@ -523,17 +512,6 @@ func (e *setLocalExpr) eval(app *app, args []string) { gLocalOpts.sortby[e.path] = method app.nav.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: err = fmt.Errorf("unknown option: %s", e.opt) } diff --git a/go.mod b/go.mod index d6600d57..66c8c098 100644 --- a/go.mod +++ b/go.mod @@ -3,18 +3,17 @@ module github.com/gokcehan/lf go 1.23.0 require ( - github.com/Xuanwo/go-locale v1.1.3 github.com/djherbis/times v1.6.0 github.com/fsnotify/fsnotify v1.9.0 github.com/gdamore/tcell/v2 v2.9.0 github.com/mattn/go-runewidth v0.0.16 golang.org/x/sys v0.35.0 golang.org/x/term v0.34.0 - golang.org/x/text v0.28.0 ) require ( github.com/gdamore/encoding v1.0.1 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/text v0.28.0 // indirect ) diff --git a/go.sum b/go.sum index e5fd5bcb..264cebe6 100644 --- a/go.sum +++ b/go.sum @@ -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/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= diff --git a/lf.1 b/lf.1 index 57993678..1df3551b 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" 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 lf \- terminal file manager .SH SYNOPSIS @@ -182,7 +182,6 @@ incsearch bool (default false) info []string (default \(aq\(aq) infotimefmtnew string (default \(aqJan _2 15:04\(aq) infotimefmtold string (default \(aqJan _2 2006\(aq) -locale string (default \(aq\(aq) mouse bool (default false) number bool (default false) numberfmt string (default \(dq\(rs033[33m\(dq) @@ -806,14 +805,6 @@ this year. .SS infotimefmtold (string) (default \f[CR]Jan _2 2006\f[R]) Format string of the file time shown in the info column when it 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) Send mouse events as input. .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. 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]info\f[R], \f[CR]locale\f[R], \f[CR]reverse\f[R] and -\f[CR]sortby\f[R]. +\f[CR]info\f[R], \f[CR]reverse\f[R] and \f[CR]sortby\f[R]. Adding a trailing path separator (i.e. \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: diff --git a/misc.go b/misc.go index 0f5a5a6c..ef8adf98 100644 --- a/misc.go +++ b/misc.go @@ -13,15 +13,7 @@ import ( "unicode" "unicode/utf8" - "github.com/Xuanwo/go-locale" "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 } @@ -344,40 +336,6 @@ var ( 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 // or a subpath of it. // This is useful for clearing cached data when a directory is moved or deleted. diff --git a/misc_test.go b/misc_test.go index 2b983747..776265c8 100644 --- a/misc_test.go +++ b/misc_test.go @@ -7,8 +7,6 @@ import ( "strings" "testing" "time" - - "golang.org/x/text/collate" ) 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) { tests := []struct { s string diff --git a/nav.go b/nav.go index cd7edaef..72a3b61a 100644 --- a/nav.go +++ b/nav.go @@ -18,7 +18,6 @@ import ( "time" "github.com/djherbis/times" - "golang.org/x/text/collate" ) type linkState byte @@ -188,7 +187,6 @@ type dir struct { filter []string // last filter for this directory ignorecase bool // ignorecase 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 } @@ -227,7 +225,6 @@ func (dir *dir) sort() { dir.dironly = getDirOnly(dir.path) dir.hidden = getHidden(dir.path) dir.reverse = getReverse(dir.path) - dir.locale = getLocale(dir.path) dir.hiddenfiles = gOpts.hiddenfiles dir.ignorecase = gOpts.ignorecase dir.ignoredia = gOpts.ignoredia @@ -238,68 +235,32 @@ func (dir *dir) sort() { // of equivalent elements will be reversed switch dir.sortby { case naturalSort: - if collator, err := makeCollator(dir.locale, collate.Numeric); err == nil { - sort.SliceStable(dir.files, func(i, j int) bool { - s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) - result := collator.CompareString(s1, s2) - if !dir.reverse { - return result < 0 - } 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) - } - }) - } + 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: - if collator, err := makeCollator(dir.locale, collate.Numeric); err == nil { - 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) - result := collator.CompareString(s1, s2) - if !dir.reverse { - return result < 0 - } 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) - } - }) - } + 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: - if collator, err := makeCollator(dir.locale); err == nil { - sort.SliceStable(dir.files, func(i, j int) bool { - s1, s2 := normalize(dir.files[i].Name(), dir.files[j].Name(), dir.ignorecase, dir.ignoredia) - result := collator.CompareString(s1, s2) - if !dir.reverse { - return result < 0 - } 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 - } - }) - } + 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: sizeVal := func(f *file) int64 { if f.IsDir() && dir.dircounts { @@ -589,7 +550,6 @@ func (nav *nav) loadDir(path string) *dir { dironly: getDirOnly(path), hidden: getHidden(path), reverse: getReverse(path), - locale: getLocale(path), visualAnchor: -1, hiddenfiles: gOpts.hiddenfiles, ignorecase: gOpts.ignorecase, @@ -639,7 +599,6 @@ func (nav *nav) checkDir(dir *dir) { dir.dironly != getDirOnly(dir.path) || dir.hidden != getHidden(dir.path) || dir.reverse != getReverse(dir.path) || - dir.locale != getLocale(dir.path) || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) || dir.ignorecase != gOpts.ignorecase || dir.ignoredia != gOpts.ignoredia: diff --git a/opts.go b/opts.go index c6bc791a..04bb529e 100644 --- a/opts.go +++ b/opts.go @@ -75,7 +75,6 @@ var gOpts struct { info []string infotimefmtnew string infotimefmtold string - locale string mouse bool number bool numberfmt string @@ -125,7 +124,6 @@ var gLocalOpts struct { dironly map[string]bool hidden map[string]bool info map[string][]string - locale map[string]string reverse map[string]bool sortby map[string]sortMethod } @@ -183,15 +181,6 @@ func getInfo(path string) []string { 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 { for _, key := range localOptPaths(path) { if val, ok := gLocalOpts.reverse[key]; ok { @@ -242,7 +231,6 @@ func init() { gOpts.info = nil gOpts.infotimefmtnew = "Jan _2 15:04" gOpts.infotimefmtold = "Jan _2 2006" - gOpts.locale = localeStrDisable gOpts.mouse = false gOpts.number = false gOpts.numberfmt = "\033[33m" @@ -417,7 +405,6 @@ func init() { gLocalOpts.dironly = make(map[string]bool) gLocalOpts.hidden = make(map[string]bool) gLocalOpts.info = make(map[string][]string) - gLocalOpts.locale = make(map[string]string) gLocalOpts.reverse = make(map[string]bool) gLocalOpts.sortby = make(map[string]sortMethod)