On Mon, 12 Nov 2001, Tomohiro KUBOTA wrote: > > On Thu, 8 Nov 2001, Daniel Yacob wrote: > > > Is there a way to detect if the terminal that a script is running in > > > can display UTF-8 text? > > > > No, not by communicating with the terminal directly. There is > > neither a practical method that doesn't involve asking the user > > for what she can see, nor is there a recommendable formal > > standard solution. > > I think it would be helpful if terminal itself sets some environmental > variable for this purpose. Here is an example of such variables. > > TERMENCODING > This would be set by the terminal and will be one of followings: > ASCII, ISO-8859-*, KOI8-*, EUC-*, ISO-2022-*, UTF-*, TIS-620, VISCII, > and so on.
I don't think, this is feasible or useful. Environment variables can only be set by a parent process for its children. In the case of a pty terminal emulator that starts applications as child processes (e.g., xterm), we have already the locale variables providing the encoding information to both the terminal emulator (e.g., xterm) and its children (shell, applications). In other connections, terminal and applications are just connected by some byte-serial communications channel that doesn't transmit environment variables. Modifying all communications channels to do that is further of then using UTF-8 everywhere, so why bother? We could define a feature-query control sequence though, but I'm not too optimistic it is of any help. If the required terminal features are missing, what are you going to do? If the needed characters are not available, they are not available. The user will find out anyway, whether via mojibake or via a neat warning message. > These information can be used to set LANG variable in .bashrc and so on. Set the LANG variable and start a rather sophisticated/dangerous piece of software that changes all your files and file names, you mean? No, I don't think that's a good idea. > For example, we want to set LANG=C when the terminal cannot display > our favorite languages. And loose information about what encoding is used in our files? No, not a good idea. I think, if you use inappropriate terminals, best-effort filter tools such as luit and screen are what you need. Markus