mirror of
https://github.com/polybar/polybar.git
synced 2024-11-11 13:50:56 -05:00
refactor: Unescape action cmd before emitting
This commit is contained in:
parent
38f551f884
commit
f8e4a5932a
2 changed files with 51 additions and 14 deletions
|
@ -64,6 +64,33 @@ void parser::codeblock(string&& data, const bar_settings& bar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char tag{data[0]};
|
char tag{data[0]};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contains the string from the current position to the next space or
|
||||||
|
* closing curly bracket (})
|
||||||
|
*
|
||||||
|
* This may be unsuitable for some tags (e.g. action tag) to use
|
||||||
|
* These MUST set value to the actual string they parsed from the beginning
|
||||||
|
* of data (or a string with the same length). The length of value is used
|
||||||
|
* to progress the cursor further.
|
||||||
|
*
|
||||||
|
* example:
|
||||||
|
*
|
||||||
|
* data = A1:echo "test": ...}
|
||||||
|
*
|
||||||
|
* erase(0,1)
|
||||||
|
* -> data = 1:echo "test": ...}
|
||||||
|
*
|
||||||
|
* case 'A', parse_action_cmd
|
||||||
|
* -> value = echo "test"
|
||||||
|
*
|
||||||
|
* Padding value
|
||||||
|
* -> value = echo "test"0::
|
||||||
|
*
|
||||||
|
* erase(0, value.length())
|
||||||
|
* -> data = ...}
|
||||||
|
*
|
||||||
|
*/
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
// Remove the tag
|
// Remove the tag
|
||||||
|
@ -134,28 +161,38 @@ void parser::codeblock(string&& data, const bar_settings& bar) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
if (isdigit(data[0]) || data[0] == ':') {
|
{
|
||||||
value = parse_action_cmd(data.substr(data[0] != ':' ? 1 : 0));
|
bool has_btn_id = (data[0] != ':');
|
||||||
mousebtn btn = parse_action_btn(data);
|
if (isdigit(data[0]) || !has_btn_id) {
|
||||||
m_actions.push_back(static_cast<int>(btn));
|
value = parse_action_cmd(data.substr(has_btn_id ? 1 : 0));
|
||||||
m_sig.emit(action_begin{action{btn, value}});
|
mousebtn btn = parse_action_btn(data);
|
||||||
|
m_actions.push_back(static_cast<int>(btn));
|
||||||
|
|
||||||
// make sure we strip the correct length (btn+wrapping colons)
|
// Unescape colons inside command before sending it to the renderer
|
||||||
if (value[0] != ':') {
|
auto cmd = string_util::replace_all(value, "\\:", ":");
|
||||||
value += "0";
|
m_sig.emit(action_begin{action{btn, cmd}});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* make sure value has the same length as the inside of the action
|
||||||
|
* tag which is btn_id + ':' + value + ':'
|
||||||
|
*/
|
||||||
|
if (has_btn_id) {
|
||||||
|
value += "0";
|
||||||
|
}
|
||||||
|
value += "::";
|
||||||
|
} else if (!m_actions.empty()) {
|
||||||
|
m_sig.emit(action_end{parse_action_btn(value)});
|
||||||
|
m_actions.pop_back();
|
||||||
}
|
}
|
||||||
value += "::";
|
break;
|
||||||
} else if (!m_actions.empty()) {
|
|
||||||
m_sig.emit(action_end{parse_action_btn(value)});
|
|
||||||
m_actions.pop_back();
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw unrecognized_token("Unrecognized token '" + string{tag} + "'");
|
throw unrecognized_token("Unrecognized token '" + string{tag} + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
|
// Remove the parsed string from data
|
||||||
data.erase(0, !value.empty() ? value.length() : 1);
|
data.erase(0, !value.empty() ? value.length() : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -798,7 +798,7 @@ bool renderer::on(const signals::parser::action_begin& evt) {
|
||||||
action.button = a.button == mousebtn::NONE ? mousebtn::LEFT : a.button;
|
action.button = a.button == mousebtn::NONE ? mousebtn::LEFT : a.button;
|
||||||
action.align = m_align;
|
action.align = m_align;
|
||||||
action.start_x = m_blocks.at(m_align).x;
|
action.start_x = m_blocks.at(m_align).x;
|
||||||
action.command = string_util::replace_all(a.command, "\\:", ":");
|
action.command = a.command;
|
||||||
action.active = true;
|
action.active = true;
|
||||||
m_actions.emplace_back(action);
|
m_actions.emplace_back(action);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue