2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "TitlePlaceholderMapper.h"
11 #include "TermConst.h"
14 // #pragma mark - TitlePlaceholderMapper
17 TitlePlaceholderMapper::TitlePlaceholderMapper(const ShellInfo
& shellInfo
,
18 const ActiveProcessInfo
& processInfo
)
20 fShellInfo(shellInfo
),
21 fProcessInfo(processInfo
)
27 TitlePlaceholderMapper::MapPlaceholder(char placeholder
, int64 number
,
28 bool numberGiven
, BString
& _string
)
30 switch (placeholder
) {
33 // current working directory
35 // If a number is given, extract the respective number of rightmost
37 BString
directory(fProcessInfo
.CurrentDirectory());
38 if (numberGiven
&& number
> 0) {
39 int32 index
= directory
.Length();
40 while (number
> 0 && index
> 0) {
41 index
= directory
.FindLast('/', index
- 1);
45 if (number
== 0 && index
>= 0 && index
+ 1 < directory
.Length())
46 directory
.Remove(0, index
+ 1);
54 if (fShellInfo
.Encoding() != M_UTF8
) {
56 _string
<< "[" << fShellInfo
.EncodingName() << "]";
61 // process name -- use "--", if the shell is active and it is the
63 if (fProcessInfo
.ID() == fShellInfo
.ProcessID()
64 && fShellInfo
.IsDefaultShell()) {
67 _string
= fProcessInfo
.Name();
75 // #pragma mark - WindowTitlePlaceholderMapper
78 WindowTitlePlaceholderMapper::WindowTitlePlaceholderMapper(
79 const ShellInfo
& shellInfo
, const ActiveProcessInfo
& processInfo
,
80 int32 windowIndex
, const BString
& tabTitle
)
82 TitlePlaceholderMapper(shellInfo
, processInfo
),
83 fWindowIndex(windowIndex
),
90 WindowTitlePlaceholderMapper::MapPlaceholder(char placeholder
, int64 number
,
91 bool numberGiven
, BString
& _string
)
93 switch (placeholder
) {
95 // The Terminal application name for the current locale
96 _string
= B_TRANSLATE_SYSTEM_NAME("Terminal");
102 if (fWindowIndex
!= 0)
103 _string
<< fWindowIndex
;
112 return TitlePlaceholderMapper::MapPlaceholder(placeholder
, number
,
113 numberGiven
, _string
);
117 // #pragma mark - TabTitlePlaceholderMapper
120 TabTitlePlaceholderMapper::TabTitlePlaceholderMapper(const ShellInfo
& shellInfo
,
121 const ActiveProcessInfo
& processInfo
, int32 tabIndex
)
123 TitlePlaceholderMapper(shellInfo
, processInfo
),
130 TabTitlePlaceholderMapper::MapPlaceholder(char placeholder
, int64 number
,
131 bool numberGiven
, BString
& _string
)
133 switch (placeholder
) {
137 _string
<< fTabIndex
;
141 return TitlePlaceholderMapper::MapPlaceholder(placeholder
, number
,
142 numberGiven
, _string
);