| 1 | //go:build unix |
| 2 | // +build unix |
| 3 | |
| 4 | // Copyright 2026 The TCell Authors |
| 5 | // |
| 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | // you may not use this file except in compliance with the License. |
| 8 | // You may obtain a copy of the License at |
| 9 | // |
| 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | // |
| 12 | // Unless required by applicable law or agreed to in writing, software |
| 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | // See the License for the specific language governing permissions and |
| 16 | // limitations under the License. |
| 17 | |
| 18 | package tcellscip-go gomod github.com/gdamore/tcell/v3 . `github.com/gdamore/tcell/v3`/ |
| 19 | |
| 20 | import ( |
| 21 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 22 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 23 | ) |
| 24 | |
| 25 | func getCharsetscip-go gomod github.com/gdamore/tcell/v3 . `github.com/gdamore/tcell/v3`/getCharset().() string { |
| 26 | // Determine the character set. This can help us later. |
| 27 | // Per POSIX, we search for LC_ALL first, then LC_CTYPE, and |
| 28 | // finally LANG. First one set wins. |
| 29 | locale := "" |
| 30 | if locale = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("LC_ALL"); locale == "" { |
| 31 | if locale = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("LC_CTYPE"); locale == "" { |
| 32 | locale = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("LANG") |
| 33 | } |
| 34 | } |
| 35 | if locale == "POSIX" || locale == "C" { |
| 36 | return "US-ASCII" |
| 37 | } |
| 38 | if i := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexRunescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexRune().(locale, '@'); i >= 0 { |
| 39 | locale = locale[:i] |
| 40 | } |
| 41 | if i := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexRunescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexRune().(locale, '.'); i >= 0 { |
| 42 | locale = locale[i+1:] |
| 43 | } else { |
| 44 | // Default assumption, and on Linux we can see LC_ALL |
| 45 | // without a character set, which we assume implies UTF-8. |
| 46 | return "UTF-8" |
| 47 | } |
| 48 | return locale |
| 49 | } |