-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions --hooks #4694
functions --hooks #4694
Changes from 4 commits
bb0dbaf
fd12df1
e359296
d508f36
67e0514
3a72269
f0e8ceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,6 +448,69 @@ void event_fire(const event_t *event) { | |
} | ||
} | ||
|
||
void event_print(io_streams_t &streams, const wcstring *filter) { | ||
std::vector<shared_ptr<event_t>> tmp; | ||
|
||
static std::map<int, wcstring> dico = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just use a switch statement here (an external function or a lambda):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also need to do the reverse operation (have a string and get a int) |
||
{EVENT_ANY, L"any"}, | ||
{EVENT_SIGNAL, L"signal"}, | ||
{EVENT_VARIABLE, L"variable"}, | ||
{EVENT_EXIT, L"exit"}, | ||
{EVENT_JOB_ID, L"job-id"}, | ||
{EVENT_GENERIC, L"generic"} | ||
}; | ||
|
||
tmp = s_event_handlers; | ||
std::sort(tmp.begin(), tmp.end(), | ||
[](const shared_ptr<event_t> &e1, const shared_ptr<event_t> &e2) { | ||
if (e1.get()->type == e2.get()->type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI you can write |
||
switch (e1.get()->type) { | ||
case EVENT_SIGNAL: | ||
return e1.get()->param1.signal < e2.get()->param1.signal; | ||
case EVENT_JOB_ID: | ||
return e1.get()->param1.job_id < e2.get()->param1.job_id; | ||
case EVENT_VARIABLE: | ||
case EVENT_GENERIC: | ||
return e1.get()->str_param1 < e2.get()->str_param1; | ||
} | ||
} else { | ||
return e1.get()->type < e2.get()->type; | ||
} | ||
}); | ||
|
||
int type = -1; | ||
for (std::vector<shared_ptr<event_t>>::iterator iter = tmp.begin(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
iter != tmp.end(); ++iter) { | ||
if (!filter || *filter == dico[iter->get()->type]) { | ||
if (iter->get()->type != type) { | ||
if (type != -1) | ||
streams.out.append(L"\n"); | ||
type = iter->get()->type; | ||
streams.out.append_format(L"Event %ls\n", dico[iter->get()->type].c_str()); | ||
} | ||
switch (iter->get()->type) { | ||
case EVENT_SIGNAL: | ||
streams.out.append_format(L"%ls %ls\n", sig2wcs(iter->get()->param1.signal), | ||
iter->get()->function_name.c_str()); | ||
break; | ||
case EVENT_JOB_ID: | ||
streams.out.append_format(L"%d %ls\n", iter->get()->param1, | ||
iter->get()->function_name.c_str()); | ||
break; | ||
case EVENT_VARIABLE: | ||
case EVENT_GENERIC: | ||
streams.out.append_format(L"%ls %ls\n", iter->get()->str_param1.c_str(), | ||
iter->get()->function_name.c_str()); | ||
break; | ||
default: | ||
streams.out.append_format(L"%ls\n", iter->get()->function_name.c_str()); | ||
break; | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
void event_init() {} | ||
|
||
void event_destroy() { s_event_handlers.clear(); } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding @ridiculousfish's comment: "event_handlers" would be more consistent.