| 1 |
//go:build !windows && !nacl && !plan9 |
| 2 |
// +build !windows,!nacl,!plan9 |
| 3 |
|
| 4 |
// Copyright 2016 The TCell Authors |
| 5 |
// |
| 6 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
// you may not use 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 tcell |
| 19 |
|
| 20 |
import ( |
| 21 |
"os" |
| 22 |
"strings" |
| 23 |
) |
| 24 |
|
| 25 |
func 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 = os.Getenv("LC_ALL"); locale == "" { |
| 31 |
if locale = os.Getenv("LC_CTYPE"); locale == "" { |
| 32 |
locale = os.Getenv("LANG") |
| 33 |
} |
| 34 |
} |
| 35 |
if locale == "POSIX" || locale == "C" { |
| 36 |
return "US-ASCII" |
| 37 |
} |
| 38 |
if i := strings.IndexRune(locale, '@'); i >= 0 { |
| 39 |
locale = locale[:i] |
| 40 |
} |
| 41 |
if i := strings.LastIndexByte(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 |
// XXX: add support for aliases |
| 49 |
return locale |
| 50 |
} |