Support %e (cur.encoding) for Terminal titles
Optional parameter %e to indicate current tab view encoding in the window title. It is not shown in case tab view encoding is default UTF-8. Inspired by Sergei Reznikov. Thanks.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,10 +6,30 @@
|
||||
|
||||
#include "ShellInfo.h"
|
||||
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
|
||||
#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";
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include <Application.h>
|
||||
#include <Beep.h>
|
||||
#include <Catalog.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
#include <Clipboard.h>
|
||||
#include <Debug.h>
|
||||
#include <Directory.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "TitlePlaceholderMapper.h"
|
||||
|
||||
#include <Catalog.h>
|
||||
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user