HaikuDepot: notify work status from main window
[haiku.git] / src / apps / terminal / TitlePlaceholderMapper.cpp
blob29e9b4b6ee4e3d7a4d1ce4066109a9fbfce6fa76
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "TitlePlaceholderMapper.h"
9 #include <Catalog.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)
26 bool
27 TitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
28 bool numberGiven, BString& _string)
30 switch (placeholder) {
31 case 'd':
33 // current working directory
35 // If a number is given, extract the respective number of rightmost
36 // components.
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);
42 number--;
45 if (number == 0 && index >= 0 && index + 1 < directory.Length())
46 directory.Remove(0, index + 1);
49 _string = directory;
50 return true;
53 case 'e':
54 if (fShellInfo.Encoding() != M_UTF8) {
55 _string.Truncate(0);
56 _string << "[" << fShellInfo.EncodingName() << "]";
58 return true;
60 case 'p':
61 // process name -- use "--", if the shell is active and it is the
62 // default shell
63 if (fProcessInfo.ID() == fShellInfo.ProcessID()
64 && fShellInfo.IsDefaultShell()) {
65 _string = "--";
66 } else
67 _string = fProcessInfo.Name();
68 return true;
71 return false;
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),
84 fTabTitle(tabTitle)
89 bool
90 WindowTitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
91 bool numberGiven, BString& _string)
93 switch (placeholder) {
94 case 'T':
95 // The Terminal application name for the current locale
96 _string = B_TRANSLATE_SYSTEM_NAME("Terminal");
97 return true;
99 case 'i':
100 // window index
101 _string.Truncate(0);
102 if (fWindowIndex != 0)
103 _string << fWindowIndex;
104 return true;
106 case 't':
107 // the tab title
108 _string = fTabTitle;
109 return true;
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),
124 fTabIndex(tabIndex)
129 bool
130 TabTitlePlaceholderMapper::MapPlaceholder(char placeholder, int64 number,
131 bool numberGiven, BString& _string)
133 switch (placeholder) {
134 case 'i':
135 // tab index
136 _string.Truncate(0);
137 _string << fTabIndex;
138 return true;
141 return TitlePlaceholderMapper::MapPlaceholder(placeholder, number,
142 numberGiven, _string);