Force a UTF-8 ctype, stable buffer ids, redraw after deferred opens

- main: when the environment's locale is not UTF-8 (LANG unset, C/POSIX),
  switch LC_CTYPE to a UTF-8 locale so ncurses delivers and draws
  multibyte characters instead of dropping them.
- Buffer::Id(): a process-unique id that survives moves and is fresh for
  copies. The terminal renderer's skip and cursor caches and the reload
  confirmation now key on it rather than the buffer's address, which is
  reused after a buffer is closed.
- The reload confirmation is cancelled by any other command, like the
  quit confirmation.
- TerminalFrontend redraws when a deferred open starts a prompt or sets a
  status (e.g. the swap recovery question), not only when a buffer opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
Claude
2026-09-24 09:16:04 -07:00
committed by Kyle Isom
parent 91ceb9bb01
commit 93901928da
8 changed files with 119 additions and 14 deletions
+24
View File
@@ -1,4 +1,5 @@
#include <clocale>
#include <langinfo.h>
#include <cctype>
#include <cerrno>
#include <cstdio>
@@ -113,10 +114,33 @@ RunStressHighlighter(unsigned seconds)
}
// kte edits UTF-8 text. With LANG unset (common in containers and ssh
// sessions) the C locale cannot decode or encode non-ASCII characters, and
// typed or pasted non-ASCII text was dropped (with the rest of the paste).
// Use a UTF-8 character-type locale when the environment does not give one.
static void
ensure_utf8_ctype()
{
auto is_utf8 = [] {
std::string cs = nl_langinfo(CODESET);
for (auto &c: cs)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
return cs == "utf-8" || cs == "utf8";
};
if (is_utf8())
return;
for (const char *name: {"C.UTF-8", "C.utf8", "en_US.UTF-8", "en_US.utf8"}) {
if (std::setlocale(LC_CTYPE, name) && is_utf8())
return;
}
}
int
main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "");
ensure_utf8_ctype();
// Ensure the error handler (and its log file) is initialised early.
kte::ErrorHandler::Instance();