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
|
} else
|
||||||
fShellInfo.SetDefaultShell(false);
|
fShellInfo.SetDefaultShell(false);
|
||||||
|
|
||||||
|
fShellInfo.SetEncoding(parameters.Encoding());
|
||||||
|
|
||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
|
||||||
// get a pseudo-tty
|
// get a pseudo-tty
|
||||||
@@ -548,7 +550,7 @@ Shell::_Spawn(int row, int col, const ShellParameters& parameters)
|
|||||||
*/
|
*/
|
||||||
setenv("TERM", kTerminalType, true);
|
setenv("TERM", kTerminalType, true);
|
||||||
setenv("TTY", ttyName, true);
|
setenv("TTY", ttyName, true);
|
||||||
setenv("TTYPE", parameters.Encoding(), true);
|
setenv("TTYPE", fShellInfo.EncodingName(), true);
|
||||||
|
|
||||||
// set the current working directory, if one is given
|
// set the current working directory, if one is given
|
||||||
if (parameters.CurrentDirectory().Length() > 0)
|
if (parameters.CurrentDirectory().Length() > 0)
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ public:
|
|||||||
const ShellInfo& Info() const
|
const ShellInfo& Info() const
|
||||||
{ return fShellInfo; }
|
{ return fShellInfo; }
|
||||||
|
|
||||||
|
int Encoding() const
|
||||||
|
{ return fShellInfo.Encoding(); }
|
||||||
|
void SetEncoding(int encoding)
|
||||||
|
{ fShellInfo.SetEncoding(encoding); }
|
||||||
|
|
||||||
bool HasActiveProcesses() const;
|
bool HasActiveProcesses() const;
|
||||||
bool GetActiveProcessInfo(
|
bool GetActiveProcessInfo(
|
||||||
ActiveProcessInfo& _info) const;
|
ActiveProcessInfo& _info) const;
|
||||||
|
|||||||
@@ -6,10 +6,30 @@
|
|||||||
|
|
||||||
#include "ShellInfo.h"
|
#include "ShellInfo.h"
|
||||||
|
|
||||||
|
#include <CharacterSet.h>
|
||||||
|
#include <CharacterSetRoster.h>
|
||||||
|
|
||||||
|
#include "TermConst.h"
|
||||||
|
|
||||||
|
using namespace BPrivate ; // BCharacterSet stuff
|
||||||
|
|
||||||
|
|
||||||
ShellInfo::ShellInfo()
|
ShellInfo::ShellInfo()
|
||||||
:
|
:
|
||||||
fProcessID(-1),
|
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 <OS.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class ShellInfo {
|
class ShellInfo {
|
||||||
@@ -23,9 +24,17 @@ public:
|
|||||||
void SetDefaultShell(bool isDefault)
|
void SetDefaultShell(bool isDefault)
|
||||||
{ fIsDefaultShell = isDefault; }
|
{ fIsDefaultShell = isDefault; }
|
||||||
|
|
||||||
|
int Encoding() const
|
||||||
|
{ return fEncoding; }
|
||||||
|
const BString& EncodingName() const
|
||||||
|
{ return fEncodingName; }
|
||||||
|
void SetEncoding(int encoding);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pid_t fProcessID;
|
pid_t fProcessID;
|
||||||
bool fIsDefaultShell;
|
bool fIsDefaultShell;
|
||||||
|
int fEncoding;
|
||||||
|
BString fEncodingName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "ShellParameters.h"
|
#include "ShellParameters.h"
|
||||||
|
|
||||||
|
#include "TermConst.h"
|
||||||
|
|
||||||
|
|
||||||
ShellParameters::ShellParameters(int argc, const char* const* argv,
|
ShellParameters::ShellParameters(int argc, const char* const* argv,
|
||||||
const BString& currentDirectory)
|
const BString& currentDirectory)
|
||||||
@@ -13,7 +15,7 @@ ShellParameters::ShellParameters(int argc, const char* const* argv,
|
|||||||
fArguments(argv),
|
fArguments(argv),
|
||||||
fArgumentCount(argc),
|
fArgumentCount(argc),
|
||||||
fCurrentDirectory(currentDirectory),
|
fCurrentDirectory(currentDirectory),
|
||||||
fEncoding("UTF8")
|
fEncoding(M_UTF8)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ ShellParameters::SetCurrentDirectory(const BString& currentDirectory)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShellParameters::SetEncoding(const BString& encoding)
|
ShellParameters::SetEncoding(int encoding)
|
||||||
{
|
{
|
||||||
fEncoding = encoding;
|
fEncoding = encoding;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ public:
|
|||||||
const BString& CurrentDirectory() const
|
const BString& CurrentDirectory() const
|
||||||
{ return fCurrentDirectory; }
|
{ return fCurrentDirectory; }
|
||||||
|
|
||||||
void SetEncoding(const BString& encoding);
|
void SetEncoding(int encoding);
|
||||||
const BString& Encoding() const
|
int Encoding() const
|
||||||
{ return fEncoding; }
|
{ return fEncoding; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* const* fArguments;
|
const char* const* fArguments;
|
||||||
int fArgumentCount;
|
int fArgumentCount;
|
||||||
BString fCurrentDirectory;
|
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\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\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%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%i\t-\tThe index of the window.\n"
|
||||||
"\t%p\t-\tThe name of the active process in the current tab.\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"
|
"\t%t\t-\tThe title of the current tab.\n"
|
||||||
|
|||||||
@@ -30,8 +30,6 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <CharacterSet.h>
|
|
||||||
#include <CharacterSetRoster.h>
|
|
||||||
#include <Clipboard.h>
|
#include <Clipboard.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -67,8 +65,6 @@
|
|||||||
#include "VTkeymap.h"
|
#include "VTkeymap.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate ; // BCharacterSet stuff
|
|
||||||
|
|
||||||
// defined in VTKeyTbl.c
|
// defined in VTKeyTbl.c
|
||||||
extern int function_keycode_table[];
|
extern int function_keycode_table[];
|
||||||
extern char *function_key_char_table[];
|
extern char *function_key_char_table[];
|
||||||
@@ -364,10 +360,7 @@ TermView::_InitObject(const ShellParameters& shellParameters)
|
|||||||
|
|
||||||
// set the shell parameters' encoding
|
// set the shell parameters' encoding
|
||||||
ShellParameters modifiedShellParameters(shellParameters);
|
ShellParameters modifiedShellParameters(shellParameters);
|
||||||
|
modifiedShellParameters.SetEncoding(fEncoding);
|
||||||
const BCharacterSet* charset
|
|
||||||
= BCharacterSetRoster::GetCharacterSetByConversionID(fEncoding);
|
|
||||||
modifiedShellParameters.SetEncoding(charset ? charset->GetName() : "UTF-8");
|
|
||||||
|
|
||||||
error = fShell->Open(fRows, fColumns, modifiedShellParameters);
|
error = fShell->Open(fRows, fColumns, modifiedShellParameters);
|
||||||
|
|
||||||
@@ -700,6 +693,9 @@ TermView::SetEncoding(int encoding)
|
|||||||
{
|
{
|
||||||
fEncoding = encoding;
|
fEncoding = encoding;
|
||||||
|
|
||||||
|
if (fShell != NULL)
|
||||||
|
fShell->SetEncoding(fEncoding);
|
||||||
|
|
||||||
BAutolock _(fTextBuffer);
|
BAutolock _(fTextBuffer);
|
||||||
fTextBuffer->SetEncoding(fEncoding);
|
fTextBuffer->SetEncoding(fEncoding);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
bool IsShellBusy() const;
|
bool IsShellBusy() const;
|
||||||
bool GetActiveProcessInfo(
|
bool GetActiveProcessInfo(
|
||||||
ActiveProcessInfo& _info) const;
|
ActiveProcessInfo& _info) const;
|
||||||
bool GetShellInfo(ShellInfo& _info) const;
|
bool GetShellInfo(ShellInfo& _info) const;
|
||||||
|
|
||||||
const char* TerminalName() const;
|
const char* TerminalName() const;
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "TitlePlaceholderMapper.h"
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
|
||||||
#include "TitlePlaceholderMapper.h"
|
#include "TermConst.h"
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - TitlePlaceholderMapper
|
// #pragma mark - TitlePlaceholderMapper
|
||||||
@@ -36,8 +38,8 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
|
|||||||
if (numberGiven && number > 0) {
|
if (numberGiven && number > 0) {
|
||||||
int32 index = directory.Length();
|
int32 index = directory.Length();
|
||||||
while (number > 0 && index > 0) {
|
while (number > 0 && index > 0) {
|
||||||
index = directory.FindLast('/', index - 1);
|
index = directory.FindLast('/', index - 1);
|
||||||
number--;
|
number--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number == 0 && index >= 0 && index + 1 < directory.Length())
|
if (number == 0 && index >= 0 && index + 1 < directory.Length())
|
||||||
@@ -48,6 +50,13 @@ TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
if (fShellInfo.Encoding() != M_UTF8) {
|
||||||
|
_string.Truncate(0);
|
||||||
|
_string << "[" << fShellInfo.EncodingName() << "]";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
// process name -- use "--", if the shell is active and it is the
|
// process name -- use "--", if the shell is active and it is the
|
||||||
// default shell
|
// default shell
|
||||||
|
|||||||
Reference in New Issue
Block a user