Terminal: added basic conditional title patterns.
* You can now insert arbitrary text only if the following or previous placeholder does not resolve to an empty value using the %<, %> and %- placeholders. * Additionally, any non-alpha numeric character between % and the placeholder character will only be displayed if the placeholder does not resolve to an empty value, too. * All of this allows you to get rid of the extra space between "Terminal" and ":" before the current path -- which is now the default.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2010, Haiku, Inc.
|
* Copyright 2001-2015, Haiku, Inc.
|
||||||
* Copyright 2003-2004 Kian Duffy, [email protected]
|
* Copyright 2003-2004 Kian Duffy, [email protected]
|
||||||
* Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
|
* Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
@@ -133,7 +133,8 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
|||||||
new BMessage(MSG_TAB_TITLE_SETTING_CHANGED));
|
new BMessage(MSG_TAB_TITLE_SETTING_CHANGED));
|
||||||
fTabTitle->SetToolTip(BString(B_TRANSLATE(
|
fTabTitle->SetToolTip(BString(B_TRANSLATE(
|
||||||
"The pattern specifying the tab titles. The following placeholders\n"
|
"The pattern specifying the tab titles. The following placeholders\n"
|
||||||
"can be used:\n")) << kTooTipSetTabTitlePlaceholders);
|
"can be used:")) << "\n" << kTooTipSetTabTitlePlaceholders
|
||||||
|
<< "\n" << kToolTipCommonTitlePlaceholders);
|
||||||
|
|
||||||
fWindowTitle = new BTextControl("windowTitle", B_TRANSLATE("Window title:"),
|
fWindowTitle = new BTextControl("windowTitle", B_TRANSLATE("Window title:"),
|
||||||
"", NULL);
|
"", NULL);
|
||||||
@@ -141,7 +142,8 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
|||||||
new BMessage(MSG_WINDOW_TITLE_SETTING_CHANGED));
|
new BMessage(MSG_WINDOW_TITLE_SETTING_CHANGED));
|
||||||
fWindowTitle->SetToolTip(BString(B_TRANSLATE(
|
fWindowTitle->SetToolTip(BString(B_TRANSLATE(
|
||||||
"The pattern specifying the window titles. The following placeholders\n"
|
"The pattern specifying the window titles. The following placeholders\n"
|
||||||
"can be used:\n")) << kTooTipSetWindowTitlePlaceholders);
|
"can be used:")) << "\n" << kTooTipSetWindowTitlePlaceholders
|
||||||
|
<< "\n" << kToolTipCommonTitlePlaceholders);
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this)
|
BLayoutBuilder::Group<>(this)
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, Ingo Weinhold, [email protected].
|
* Copyright 2010, Ingo Weinhold, [email protected].
|
||||||
|
* Copyright 2015, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,24 +20,69 @@
|
|||||||
PatternEvaluator::Evaluate(const char* pattern, PlaceholderMapper& mapper)
|
PatternEvaluator::Evaluate(const char* pattern, PlaceholderMapper& mapper)
|
||||||
{
|
{
|
||||||
BString result;
|
BString result;
|
||||||
|
BString before;
|
||||||
|
bool isBefore = false;
|
||||||
|
bool isAfter = false;
|
||||||
|
bool hadResult = false;
|
||||||
|
bool began = false;
|
||||||
|
|
||||||
while (*pattern != '\0') {
|
while (*pattern != '\0') {
|
||||||
// find next placeholder
|
// find next placeholder
|
||||||
const char* placeholder = strchr(pattern, '%');
|
const char* placeholder = strchr(pattern, '%');
|
||||||
if (placeholder == NULL)
|
size_t length = 0;
|
||||||
return result.Append(pattern);
|
if (placeholder != NULL)
|
||||||
|
length = placeholder - pattern;
|
||||||
|
else
|
||||||
|
length = INT_MAX;
|
||||||
|
|
||||||
// append skipped chars
|
// append skipped chars
|
||||||
if (placeholder != pattern)
|
if (placeholder != pattern) {
|
||||||
result.Append(pattern, placeholder - pattern);
|
if (isBefore) {
|
||||||
|
before.SetTo(pattern, length);
|
||||||
|
isBefore = false;
|
||||||
|
} else if (!isAfter || hadResult) {
|
||||||
|
result.Append(pattern, length);
|
||||||
|
isBefore = false;
|
||||||
|
before.SetTo(NULL);
|
||||||
|
isAfter = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (placeholder == NULL)
|
||||||
|
return result;
|
||||||
|
|
||||||
pattern = placeholder + 1;
|
pattern = placeholder + 1;
|
||||||
|
|
||||||
// check for an escaped '%'
|
// check for special placeholders
|
||||||
if (*pattern == '%') {
|
switch (pattern[0]) {
|
||||||
result += '%';
|
case '%':
|
||||||
|
// An escaped '%'
|
||||||
|
result += '%';
|
||||||
|
pattern++;
|
||||||
|
continue;
|
||||||
|
case '<':
|
||||||
|
// An optional before string
|
||||||
|
isBefore = began = true;
|
||||||
|
hadResult = false;
|
||||||
|
pattern++;
|
||||||
|
continue;
|
||||||
|
case '>':
|
||||||
|
// An optional after string
|
||||||
|
isAfter = true;
|
||||||
|
began = false;
|
||||||
|
before.SetTo(NULL);
|
||||||
|
pattern++;
|
||||||
|
continue;
|
||||||
|
case '-':
|
||||||
|
// End of any other section; ignore
|
||||||
|
pattern++;
|
||||||
|
isBefore = false;
|
||||||
|
isAfter = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Count non alpha numeric characters to the before section
|
||||||
|
while (pattern[0] != '\0' && !isalnum(pattern[0])) {
|
||||||
|
before.Append(pattern[0], 1);
|
||||||
pattern++;
|
pattern++;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a number, if there is one
|
// parse a number, if there is one
|
||||||
@@ -53,12 +99,19 @@ PatternEvaluator::Evaluate(const char* pattern, PlaceholderMapper& mapper)
|
|||||||
if (*pattern != '\0' && mapper.MapPlaceholder(*pattern,
|
if (*pattern != '\0' && mapper.MapPlaceholder(*pattern,
|
||||||
number, hasNumber, mappedValue)) {
|
number, hasNumber, mappedValue)) {
|
||||||
// mapped successfully -- append the replacement string
|
// mapped successfully -- append the replacement string
|
||||||
|
if (began && !mappedValue.IsEmpty())
|
||||||
|
hadResult = true;
|
||||||
|
if (!before.IsEmpty() && !mappedValue.IsEmpty()) {
|
||||||
|
result += before;
|
||||||
|
before.SetTo(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
result += mappedValue;
|
result += mappedValue;
|
||||||
pattern++;
|
pattern++;
|
||||||
} else {
|
} else {
|
||||||
// something went wrong -- just append the literal part of the
|
// something went wrong -- just append the literal part of the
|
||||||
// pattern
|
// pattern
|
||||||
result.Append(placeholder, pattern - placeholder);
|
result.Append(placeholder, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +119,6 @@ PatternEvaluator::Evaluate(const char* pattern, PlaceholderMapper& mapper)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - PlaceholderMapper
|
// #pragma mark - PlaceholderMapper
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2003-2013, Haiku, Inc. All Rights Reserved.
|
* Copyright 2003-2015, Haiku, Inc. All Rights Reserved.
|
||||||
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Copyright (c) 1998,99 Kazuho Okui and Takashi Murai.
|
* Copyright (c) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
@@ -85,7 +85,7 @@ static const pref_defaults kTermDefaults[] = {
|
|||||||
{ PREF_IM_AWARE, "0"},
|
{ PREF_IM_AWARE, "0"},
|
||||||
|
|
||||||
{ PREF_TAB_TITLE, "%1d: %p%e" },
|
{ PREF_TAB_TITLE, "%1d: %p%e" },
|
||||||
{ PREF_WINDOW_TITLE, "%T %i: %t" },
|
{ PREF_WINDOW_TITLE, "%T% i: %t" },
|
||||||
{ PREF_BLINK_CURSOR, PREF_TRUE },
|
{ PREF_BLINK_CURSOR, PREF_TRUE },
|
||||||
{ PREF_WARN_ON_EXIT, PREF_TRUE },
|
{ PREF_WARN_ON_EXIT, PREF_TRUE },
|
||||||
{ PREF_CURSOR_STYLE, PREF_BLOCK_CURSOR },
|
{ PREF_CURSOR_STYLE, PREF_BLOCK_CURSOR },
|
||||||
|
|||||||
@@ -30,8 +30,18 @@ const char* const kTooTipSetWindowTitlePlaceholders = B_TRANSLATE(
|
|||||||
"\t%e\t-\tThe encoding of the current tab. Not shown for UTF-8.\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.");
|
||||||
"\t%%\t-\tThe character '%'.");
|
|
||||||
|
const char* const kToolTipCommonTitlePlaceholders = B_TRANSLATE(
|
||||||
|
"\t%%\t-\tThe character '%'.\n"
|
||||||
|
"\t%<\t-\tStarts a section that will only be shown if a placeholder\n"
|
||||||
|
"\t\t\tafterwards is not empty.\n"
|
||||||
|
"\t%>\t-\tStarts a section that will only be shown if a placeholder\n"
|
||||||
|
"\t\t\tbetween a previous %< section and this one is not empty.\n"
|
||||||
|
"\t%-\t-\tEnds a %< or %> section.\n\n"
|
||||||
|
"Any non alpha numeric character between '%' and the format "
|
||||||
|
"letter will insert a space only\nif the placeholder value is not "
|
||||||
|
"empty. It will add to the %< section.");
|
||||||
|
|
||||||
const char* const kShellEscapeCharacters = " ~`#$&*()\\|[]{};'\"<>?!";
|
const char* const kShellEscapeCharacters = " ~`#$&*()\\|[]{};'\"<>?!";
|
||||||
const char* const kDefaultAdditionalWordCharacters = ":@-./_~";
|
const char* const kDefaultAdditionalWordCharacters = ":@-./_~";
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ static const char* const PREF_WINDOW_TITLE = "Window title";
|
|||||||
// shared strings
|
// shared strings
|
||||||
extern const char* const kTooTipSetTabTitlePlaceholders;
|
extern const char* const kTooTipSetTabTitlePlaceholders;
|
||||||
extern const char* const kTooTipSetWindowTitlePlaceholders;
|
extern const char* const kTooTipSetWindowTitlePlaceholders;
|
||||||
|
extern const char* const kToolTipCommonTitlePlaceholders;
|
||||||
|
|
||||||
extern const char* const kShellEscapeCharacters;
|
extern const char* const kShellEscapeCharacters;
|
||||||
extern const char* const kDefaultAdditionalWordCharacters;
|
extern const char* const kDefaultAdditionalWordCharacters;
|
||||||
|
|||||||
Reference in New Issue
Block a user