Skip to content

Commit

Permalink
terminal: Improve default locale handling
Browse files Browse the repository at this point in the history
* Use `LANG` instead of `LC_ALL` (`LC_ALL` is the highest priority which will override any other end-user settings; when that isn't set things fall back to separate `LC_*` variables; and when those aren't set things fall back to `LANG`). [0]
* Only set `LANG` for our child if necessary (if it already exists in the parent, then the child will inherit that, no need for us to do anything)

[0] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02

Tested cases:

- LANG not set: zed inserts `en_US.UTF-8`
- LANG set to `en_GB.UTF-8`: zed does nothing, child terminal inherits this from parent terminal

Release Notes:

- Use the system locale in the terminal instead of forcing `en_US.UTF-8`
  • Loading branch information
shish committed Oct 10, 2024
1 parent fe1078e commit 745fa15
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/terminal/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,15 @@ impl TerminalBuilder {
completion_tx: Sender<()>,
cx: &AppContext,
) -> Result<TerminalBuilder> {
// TODO: Properly set the current locale,
env.entry("LC_ALL".to_string())
.or_insert_with(|| "en_US.UTF-8".to_string());
// If the parent environment doesn't have a locale set
// (As is the case when launched from a .app on MacOS),
// and the Project doesn't have a locale set (as is the
// case when a remote project is opened over SSH), then
// set a fallback for our child environment to use.
if std::env::var("LANG").is_err() {
env.entry("LANG".to_string())
.or_insert_with(|| "en_US.UTF-8".to_string());
}

env.insert("ZED_TERM".to_string(), "true".to_string());
env.insert("TERM_PROGRAM".to_string(), "zed".to_string());
Expand Down

0 comments on commit 745fa15

Please sign in to comment.