Skip to content

functions --hooks#4694

Closed
hamon-e wants to merge 7 commits into
fish-shell:masterfrom
hamon-e:event
Closed

functions --hooks#4694
hamon-e wants to merge 7 commits into
fish-shell:masterfrom
hamon-e:event

Conversation

@hamon-e
Copy link
Copy Markdown
Contributor

@hamon-e hamon-e commented Jan 31, 2018

Add a little options to list all events hooks
The current output it's not really pretty but i had no idea to make it better

It's my first contribution don't hesitate to criticize

@ridiculousfish
Copy link
Copy Markdown
Member

This looks nice! Thanks for doing this!

I don' t know about the name "hooks," we don't use that term anywhere else. Users cause a function to respond to an event via --on-event, how do you feel about "event handlers?"

A few nits I'll put in code review. Also if you get to it you can add this to the CHANGELOG, if not I'll do it.

@fish-shell fish-shell deleted a comment from ridiculousfish Jan 31, 2018
Comment thread src/builtin_functions.cpp Outdated
{L"help", no_argument, NULL, 'h'}, {L"query", no_argument, NULL, 'q'},
{L"copy", no_argument, NULL, 'c'}, {L"details", no_argument, NULL, 'D'},
{L"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}};
{L"verbose", no_argument, NULL, 'v'}, {L"hooks", optional_argument, NULL, 'o'},
Copy link
Copy Markdown

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.

@hamon-e
Copy link
Copy Markdown
Contributor Author

hamon-e commented Feb 1, 2018

yeah i prefer it too ; what do you think of it ?

@hamon-e
Copy link
Copy Markdown
Contributor Author

hamon-e commented Feb 2, 2018

I don't find optional argument really pratical
so i create another one

Comment thread src/event.cpp Outdated
void event_print(io_streams_t &streams, const wcstring *filter) {
std::vector<shared_ptr<event_t>> tmp;

static std::map<int, wcstring> dico = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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):

static const wchar_t *name_for_event_type(int which) {
   switch (which) {
     case EVENT_ANY: return L"any";
     ...
   }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)
and for that i can't do a switch statement

Comment thread src/event.cpp Outdated
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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you can write e1->type == e2->type here, no need for get()

Comment thread src/event.cpp Outdated
});

int type = -1;
for (std::vector<shared_ptr<event_t>>::iterator iter = tmp.begin();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const shared_ptr<event_t> & evt : tmp) {... is nicer. fish has graduated into C++11 :)

Comment thread src/event.cpp Outdated
static std::map<int, wcstring> dico = {
{EVENT_ANY, L"any"},
{EVENT_SIGNAL, L"signal"},
{EVENT_VARIABLE, L"any"},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a copy-paste error, "any" should be "variable" here.

@faho
Copy link
Copy Markdown
Member

faho commented Mar 6, 2018

What's the status here? @ridiculousfish: Did you forget about this?

@ridiculousfish
Copy link
Copy Markdown
Member

It's been in my dock all this time :/

@ridiculousfish
Copy link
Copy Markdown
Member

Merged as 3819437, documented as 9a5afe3. Thanks!

@ridiculousfish ridiculousfish added this to the fish-3.0 milestone Mar 10, 2018
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants