diff --git a/src/apps/terminal/Shell.cpp b/src/apps/terminal/Shell.cpp index be93b97114..11793568ba 100644 --- a/src/apps/terminal/Shell.cpp +++ b/src/apps/terminal/Shell.cpp @@ -412,6 +412,8 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters) } else fShellInfo.SetDefaultShell(false); + fShellInfo.SetEncoding(parameters.Encoding()); + signal(SIGTTOU, SIG_IGN); // get a pseudo-tty @@ -548,7 +550,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters) */ setenv("TERM", kTerminalType, true); setenv("TTY", ttyName, true); - setenv("TTYPE", parameters.Encoding(), true); + setenv("TTYPE", fShellInfo.EncodingName(), true); // set the current working directory, if one is given if (parameters.CurrentDirectory().Length() > 0) diff --git a/src/apps/terminal/Shell.h b/src/apps/terminal/Shell.h index bc01fc9e42..df14406e82 100644 --- a/src/apps/terminal/Shell.h +++ b/src/apps/terminal/Shell.h @@ -49,6 +49,11 @@ public: const ShellInfo& Info() const { return fShellInfo; } + int Encoding() const + { return fShellInfo.Encoding(); } + void SetEncoding(int encoding) + { fShellInfo.SetEncoding(encoding); } + bool HasActiveProcesses() const; bool GetActiveProcessInfo( ActiveProcessInfo& _info) const; diff --git a/src/apps/terminal/ShellInfo.cpp b/src/apps/terminal/ShellInfo.cpp index c4dcf97bee..c3b64051b0 100644 --- a/src/apps/terminal/ShellInfo.cpp +++ b/src/apps/terminal/ShellInfo.cpp @@ -6,10 +6,30 @@ #include "ShellInfo.h" +#include +#include + +#include "TermConst.h" + +using namespace BPrivate ; // BCharacterSet stuff + ShellInfo::ShellInfo() : fProcessID(-1), - fIsDefaultShell(true) + fIsDefaultShell(true), + fEncoding(M_UTF8), + fEncodingName("UTF-8") { } + + +void +ShellInfo::SetEncoding(int encoding) +{ + fEncoding = encoding; + + const BCharacterSet* charset + = BCharacterSetRoster::GetCharacterSetByConversionID(fEncoding); + fEncodingName = charset ? charset->GetName() : "UTF-8"; +} diff --git a/src/apps/terminal/ShellInfo.h b/src/apps/terminal/ShellInfo.h index 540868527d..63d9eed898 100644 --- a/src/apps/terminal/ShellInfo.h +++ b/src/apps/terminal/ShellInfo.h @@ -7,6 +7,7 @@ #include +#include class ShellInfo { @@ -23,9 +24,17 @@ public: void SetDefaultShell(bool isDefault) { fIsDefaultShell = isDefault; } + int Encoding() const + { return fEncoding; } + const BString& EncodingName() const + { return fEncodingName; } + void SetEncoding(int encoding); + private: pid_t fProcessID; bool fIsDefaultShell; + int fEncoding; + BString fEncodingName; }; diff --git a/src/apps/terminal/ShellParameters.cpp b/src/apps/terminal/ShellParameters.cpp index e5cb02af99..136abcc856 100644 --- a/src/apps/terminal/ShellParameters.cpp +++ b/src/apps/terminal/ShellParameters.cpp @@ -6,6 +6,8 @@ #include "ShellParameters.h" +#include "TermConst.h" + ShellParameters::ShellParameters(int argc, const char* const* argv, const BString& currentDirectory) @@ -13,7 +15,7 @@ ShellParameters::ShellParameters(int argc, const char* const* argv, fArguments(argv), fArgumentCount(argc), fCurrentDirectory(currentDirectory), - fEncoding("UTF8") + fEncoding(M_UTF8) { } @@ -34,7 +36,7 @@ ShellParameters::SetCurrentDirectory(const BString& currentDirectory) void -ShellParameters::SetEncoding(const BString& encoding) +ShellParameters::SetEncoding(int encoding) { fEncoding = encoding; } diff --git a/src/apps/terminal/ShellParameters.h b/src/apps/terminal/ShellParameters.h index 8074cb19e3..ccbd2c3f0f 100644 --- a/src/apps/terminal/ShellParameters.h +++ b/src/apps/terminal/ShellParameters.h @@ -27,15 +27,15 @@ public: const BString& CurrentDirectory() const { return fCurrentDirectory; } - void SetEncoding(const BString& encoding); - const BString& Encoding() const + void SetEncoding(int encoding); + int Encoding() const { return fEncoding; } private: const char* const* fArguments; int fArgumentCount; BString fCurrentDirectory; - BString fEncoding; + int fEncoding; }; diff --git a/src/apps/terminal/TermConst.cpp b/src/apps/terminal/TermConst.cpp index e3d5efa1c6..1b88bc0493 100644 --- a/src/apps/terminal/TermConst.cpp +++ b/src/apps/terminal/TermConst.cpp @@ -26,6 +26,7 @@ const char* const kTooTipSetWindowTitlePlaceholders = B_TRANSLATE( "\t\t\tcurrent tab. Optionally the maximum number of path components\n" "\t\t\tcan be specified. E.g. '%2d' for at most two components.\n" "\t%T\t-\tThe Terminal application name for the current locale.\n" + "\t%e\t-\tThe encoding of the current tab. Not shown for UTF-8.\n" "\t%i\t-\tThe index of the window.\n" "\t%p\t-\tThe name of the active process in the current tab.\n" "\t%t\t-\tThe title of the current tab.\n" diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index e6e3d4be01..17d2d428c7 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -30,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -67,8 +65,6 @@ #include "VTkeymap.h" -using namespace BPrivate ; // BCharacterSet stuff - // defined in VTKeyTbl.c extern int function_keycode_table[]; extern char *function_key_char_table[]; @@ -364,10 +360,7 @@ TermView::_InitObject(const ShellParameters& shellParameters) // set the shell parameters' encoding ShellParameters modifiedShellParameters(shellParameters); - - const BCharacterSet* charset - = BCharacterSetRoster::GetCharacterSetByConversionID(fEncoding); - modifiedShellParameters.SetEncoding(charset ? charset->GetName() : "UTF-8"); + modifiedShellParameters.SetEncoding(fEncoding); error = fShell->Open(fRows, fColumns, modifiedShellParameters); @@ -700,6 +693,9 @@ TermView::SetEncoding(int encoding) { fEncoding = encoding; + if (fShell != NULL) + fShell->SetEncoding(fEncoding); + BAutolock _(fTextBuffer); fTextBuffer->SetEncoding(fEncoding); } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 2766f25686..9e0721511a 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -60,7 +60,7 @@ public: bool IsShellBusy() const; bool GetActiveProcessInfo( ActiveProcessInfo& _info) const; - bool GetShellInfo(ShellInfo& _info) const; + bool GetShellInfo(ShellInfo& _info) const; const char* TerminalName() const; diff --git a/src/apps/terminal/TitlePlaceholderMapper.cpp b/src/apps/terminal/TitlePlaceholderMapper.cpp index 9cac1b51c8..29e9b4b6ee 100644 --- a/src/apps/terminal/TitlePlaceholderMapper.cpp +++ b/src/apps/terminal/TitlePlaceholderMapper.cpp @@ -4,9 +4,11 @@ */ +#include "TitlePlaceholderMapper.h" + #include -#include "TitlePlaceholderMapper.h" +#include "TermConst.h" // #pragma mark - TitlePlaceholderMapper @@ -36,8 +38,8 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number, if (numberGiven && number > 0) { int32 index = directory.Length(); while (number > 0 && index > 0) { - index = directory.FindLast('/', index - 1); - number--; + index = directory.FindLast('/', index - 1); + number--; } if (number == 0 && index >= 0 && index + 1 < directory.Length()) @@ -48,6 +50,13 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number, return true; } + case 'e': + if (fShellInfo.Encoding() != M_UTF8) { + _string.Truncate(0); + _string << "[" << fShellInfo.EncodingName() << "]"; + } + return true; + case 'p': // process name -- use "--", if the shell is active and it is the // default shell