mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 13:57:17 +08:00
Formatting
This commit is contained in:
parent
8a66ba6c35
commit
e31431140a
|
@ -1009,9 +1009,10 @@ static int builtin_emit(parser_t &parser, wchar_t **argv)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!argv[woptind]) {
|
if (!argv[woptind])
|
||||||
append_format(stderr_buffer, L"%ls: expected event name\n", argv[0]);
|
{
|
||||||
return STATUS_BUILTIN_ERROR;
|
append_format(stderr_buffer, L"%ls: expected event name\n", argv[0]);
|
||||||
|
return STATUS_BUILTIN_ERROR;
|
||||||
}
|
}
|
||||||
wchar_t *eventname = argv[woptind];
|
wchar_t *eventname = argv[woptind];
|
||||||
wcstring_list_t args(argv + woptind + 1, argv + argc);
|
wcstring_list_t args(argv + woptind + 1, argv + argc);
|
||||||
|
|
164
event.cpp
164
event.cpp
|
@ -200,7 +200,7 @@ wcstring event_get_desc(const event_t &e)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = format_string(_(L"Unknown event type '0x%x'"), e.type);
|
result = format_string(_(L"Unknown event type '0x%x'"), e.type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -222,68 +222,86 @@ static void show_all_handlers(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Give a more condensed description of \c event compared to \c event_get_desc.
|
Give a more condensed description of \c event compared to \c event_get_desc.
|
||||||
It includes what function will fire if the \c event is an event handler.
|
It includes what function will fire if the \c event is an event handler.
|
||||||
*/
|
*/
|
||||||
static wcstring event_desc_compact(const event_t &event) {
|
static wcstring event_desc_compact(const event_t &event)
|
||||||
wcstring res;
|
{
|
||||||
wchar_t const *temp;
|
wcstring res;
|
||||||
int sig;
|
wchar_t const *temp;
|
||||||
switch(event.type) {
|
int sig;
|
||||||
case EVENT_ANY:
|
switch (event.type)
|
||||||
res = L"EVENT_ANY";
|
{
|
||||||
break;
|
case EVENT_ANY:
|
||||||
case EVENT_VARIABLE:
|
res = L"EVENT_ANY";
|
||||||
if(event.str_param1.c_str()) {
|
break;
|
||||||
res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str());
|
case EVENT_VARIABLE:
|
||||||
} else {
|
if (event.str_param1.c_str())
|
||||||
res = L"EVENT_VARIABLE([any])";
|
{
|
||||||
}
|
res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str());
|
||||||
break;
|
}
|
||||||
case EVENT_SIGNAL:
|
else
|
||||||
sig = event.param1.signal;
|
{
|
||||||
if(sig == EVENT_ANY_SIGNAL) {
|
res = L"EVENT_VARIABLE([any])";
|
||||||
temp = L"[all signals]";
|
}
|
||||||
} else if(sig == 0) {
|
break;
|
||||||
temp = L"not set";
|
case EVENT_SIGNAL:
|
||||||
} else {
|
sig = event.param1.signal;
|
||||||
temp = sig2wcs(sig);
|
if (sig == EVENT_ANY_SIGNAL)
|
||||||
}
|
{
|
||||||
res = format_string(L"EVENT_SIGNAL(%ls)", temp);
|
temp = L"[all signals]";
|
||||||
break;
|
}
|
||||||
case EVENT_EXIT:
|
else if (sig == 0)
|
||||||
if(event.param1.pid == EVENT_ANY_PID) {
|
{
|
||||||
res = wcstring(L"EVENT_EXIT([all child processes])");
|
temp = L"not set";
|
||||||
} else if (event.param1.pid > 0) {
|
}
|
||||||
res = format_string(L"EVENT_EXIT(pid %d)", event.param1.pid);
|
else
|
||||||
} else {
|
{
|
||||||
job_t *j = job_get_from_pid(-event.param1.pid);
|
temp = sig2wcs(sig);
|
||||||
if (j)
|
}
|
||||||
res = format_string(L"EVENT_EXIT(jobid %d: \"%ls\")", j->job_id, j->command_wcstr());
|
res = format_string(L"EVENT_SIGNAL(%ls)", temp);
|
||||||
else
|
break;
|
||||||
res = format_string(L"EVENT_EXIT(pgid %d)", -event.param1.pid);
|
case EVENT_EXIT:
|
||||||
}
|
if (event.param1.pid == EVENT_ANY_PID)
|
||||||
break;
|
{
|
||||||
case EVENT_JOB_ID:
|
res = wcstring(L"EVENT_EXIT([all child processes])");
|
||||||
{
|
}
|
||||||
job_t *j = job_get(event.param1.job_id);
|
else if (event.param1.pid > 0)
|
||||||
if (j)
|
{
|
||||||
res = format_string(L"EVENT_JOB_ID(job %d: \"%ls\")", j->job_id, j->command_wcstr());
|
res = format_string(L"EVENT_EXIT(pid %d)", event.param1.pid);
|
||||||
else
|
}
|
||||||
res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id);
|
else
|
||||||
break;
|
{
|
||||||
}
|
job_t *j = job_get_from_pid(-event.param1.pid);
|
||||||
case EVENT_GENERIC:
|
if (j)
|
||||||
res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str());
|
res = format_string(L"EVENT_EXIT(jobid %d: \"%ls\")", j->job_id, j->command_wcstr());
|
||||||
break;
|
else
|
||||||
default:
|
res = format_string(L"EVENT_EXIT(pgid %d)", -event.param1.pid);
|
||||||
res = format_string(L"unknown/illegal event(%x)", event.type);
|
}
|
||||||
}
|
break;
|
||||||
if(event.function_name.size()) {
|
case EVENT_JOB_ID:
|
||||||
return format_string(L"%ls: \"%ls\"", res.c_str(), event.function_name.c_str());
|
{
|
||||||
} else {
|
job_t *j = job_get(event.param1.job_id);
|
||||||
return res;
|
if (j)
|
||||||
}
|
res = format_string(L"EVENT_JOB_ID(job %d: \"%ls\")", j->job_id, j->command_wcstr());
|
||||||
|
else
|
||||||
|
res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EVENT_GENERIC:
|
||||||
|
res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = format_string(L"unknown/illegal event(%x)", event.type);
|
||||||
|
}
|
||||||
|
if (event.function_name.size())
|
||||||
|
{
|
||||||
|
return format_string(L"%ls: \"%ls\"", res.c_str(), event.function_name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,7 +309,8 @@ void event_add_handler(const event_t &event)
|
||||||
{
|
{
|
||||||
event_t *e;
|
event_t *e;
|
||||||
|
|
||||||
if(debug_level >= 3) {
|
if (debug_level >= 3)
|
||||||
|
{
|
||||||
wcstring desc = event_desc_compact(event);
|
wcstring desc = event_desc_compact(event);
|
||||||
debug(3, "register: %ls\n", desc.c_str());
|
debug(3, "register: %ls\n", desc.c_str());
|
||||||
}
|
}
|
||||||
|
@ -315,7 +334,8 @@ void event_remove(const event_t &criterion)
|
||||||
size_t i;
|
size_t i;
|
||||||
event_list_t new_list;
|
event_list_t new_list;
|
||||||
|
|
||||||
if(debug_level >= 3) {
|
if (debug_level >= 3)
|
||||||
|
{
|
||||||
wcstring desc = event_desc_compact(criterion);
|
wcstring desc = event_desc_compact(criterion);
|
||||||
debug(3, "unregister: %ls\n", desc.c_str());
|
debug(3, "unregister: %ls\n", desc.c_str());
|
||||||
}
|
}
|
||||||
|
@ -436,11 +456,11 @@ static void event_fire_internal(const event_t &event)
|
||||||
event_list_t fire;
|
event_list_t fire;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
First we free all events that have been removed, but only if this
|
First we free all events that have been removed, but only if this
|
||||||
invocation of event_fire_internal is not a recursive call.
|
invocation of event_fire_internal is not a recursive call.
|
||||||
*/
|
*/
|
||||||
if(is_event <= 1)
|
if (is_event <= 1)
|
||||||
event_free_kills();
|
event_free_kills();
|
||||||
|
|
||||||
if (events.empty())
|
if (events.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -501,7 +521,7 @@ static void event_fire_internal(const event_t &event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug( 1, L"Event handler fires command '%ls'", buffer.c_str() );
|
// debug( 1, L"Event handler fires command '%ls'", buffer.c_str() );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Event handlers are not part of the main flow of code, so
|
Event handlers are not part of the main flow of code, so
|
||||||
|
@ -522,8 +542,8 @@ static void event_fire_internal(const event_t &event)
|
||||||
/*
|
/*
|
||||||
Free killed events
|
Free killed events
|
||||||
*/
|
*/
|
||||||
if(is_event <= 1)
|
if (is_event <= 1)
|
||||||
event_free_kills();
|
event_free_kills();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,4 +723,4 @@ event_t event_t::generic_event(const wcstring &str)
|
||||||
event.str_param1 = str;
|
event.str_param1 = str;
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
event.h
2
event.h
|
@ -89,7 +89,7 @@ struct event_t
|
||||||
event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() { }
|
event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() { }
|
||||||
|
|
||||||
/** default copy constructor */
|
/** default copy constructor */
|
||||||
//event_t(const event_t &x);
|
//event_t(const event_t &x);
|
||||||
|
|
||||||
|
|
||||||
static event_t signal_event(int sig);
|
static event_t signal_event(int sig);
|
||||||
|
|
|
@ -674,7 +674,8 @@ static void test_path()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum word_motion_t {
|
enum word_motion_t
|
||||||
|
{
|
||||||
word_motion_left,
|
word_motion_left,
|
||||||
word_motion_right
|
word_motion_right
|
||||||
};
|
};
|
||||||
|
@ -682,9 +683,10 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style, co
|
||||||
{
|
{
|
||||||
wcstring command;
|
wcstring command;
|
||||||
std::set<size_t> stops;
|
std::set<size_t> stops;
|
||||||
|
|
||||||
// Carets represent stops and should be cut out of the command
|
// Carets represent stops and should be cut out of the command
|
||||||
for (size_t i=0; i < test.size(); i++) {
|
for (size_t i=0; i < test.size(); i++)
|
||||||
|
{
|
||||||
wchar_t wc = test.at(i);
|
wchar_t wc = test.at(i);
|
||||||
if (wc == L'^')
|
if (wc == L'^')
|
||||||
{
|
{
|
||||||
|
@ -695,7 +697,7 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style, co
|
||||||
command.push_back(wc);
|
command.push_back(wc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t idx, end;
|
size_t idx, end;
|
||||||
if (motion == word_motion_left)
|
if (motion == word_motion_left)
|
||||||
{
|
{
|
||||||
|
@ -707,7 +709,7 @@ static void test_1_word_motion(word_motion_t motion, move_word_style_t style, co
|
||||||
idx = 0;
|
idx = 0;
|
||||||
end = command.size();
|
end = command.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
move_word_state_machine_t sm(style);
|
move_word_state_machine_t sm(style);
|
||||||
while (idx != end)
|
while (idx != end)
|
||||||
{
|
{
|
||||||
|
@ -752,14 +754,14 @@ static void test_word_motion()
|
||||||
say(L"Testing word motion");
|
say(L"Testing word motion");
|
||||||
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"^echo ^hello_^world.^txt");
|
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"^echo ^hello_^world.^txt");
|
||||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ hello^_world^.txt^");
|
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ hello^_world^.txt^");
|
||||||
|
|
||||||
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"echo ^foo_^foo_^foo/^/^/^/^/^ ");
|
test_1_word_motion(word_motion_left, move_word_style_punctuation, L"echo ^foo_^foo_^foo/^/^/^/^/^ ");
|
||||||
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ foo^_foo^_foo^/^/^/^/^/ ^");
|
test_1_word_motion(word_motion_right, move_word_style_punctuation, L"echo^ foo^_foo^_foo^/^/^/^/^/ ^");
|
||||||
|
|
||||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^/^foo/^bar/^baz/");
|
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^/^foo/^bar/^baz/");
|
||||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^--foo ^--bar");
|
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^--foo ^--bar");
|
||||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^hi ^> /^dev/^null");
|
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo ^hi ^> /^dev/^null");
|
||||||
|
|
||||||
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo /^foo/^bar{^aaa,^bbb,^ccc}^bak/");
|
test_1_word_motion(word_motion_left, move_word_style_path_components, L"^echo /^foo/^bar{^aaa,^bbb,^ccc}^bak/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1578,7 +1580,7 @@ int main(int argc, char **argv)
|
||||||
builtin_init();
|
builtin_init();
|
||||||
reader_init();
|
reader_init();
|
||||||
env_init();
|
env_init();
|
||||||
|
|
||||||
test_word_motion();
|
test_word_motion();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -677,7 +677,7 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c)
|
||||||
s_alphanumeric,
|
s_alphanumeric,
|
||||||
s_end
|
s_end
|
||||||
};
|
};
|
||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
while (state != s_end && ! consumed)
|
while (state != s_end && ! consumed)
|
||||||
{
|
{
|
||||||
|
@ -688,7 +688,7 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c)
|
||||||
consumed = true;
|
consumed = true;
|
||||||
state = s_whitespace;
|
state = s_whitespace;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case s_whitespace:
|
case s_whitespace:
|
||||||
if (iswspace(c))
|
if (iswspace(c))
|
||||||
{
|
{
|
||||||
|
@ -700,7 +700,7 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c)
|
||||||
state = s_alphanumeric;
|
state = s_alphanumeric;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case s_alphanumeric:
|
case s_alphanumeric:
|
||||||
if (iswalnum(c))
|
if (iswalnum(c))
|
||||||
{
|
{
|
||||||
|
@ -712,7 +712,7 @@ bool move_word_state_machine_t::consume_char_punctuation(wchar_t c)
|
||||||
state = s_end;
|
state = s_end;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case s_end:
|
case s_end:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -738,7 +738,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c)
|
||||||
s_path_component_characters,
|
s_path_component_characters,
|
||||||
s_end
|
s_end
|
||||||
};
|
};
|
||||||
|
|
||||||
//printf("state %d, consume '%lc'\n", state, c);
|
//printf("state %d, consume '%lc'\n", state, c);
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
while (state != s_end && ! consumed)
|
while (state != s_end && ! consumed)
|
||||||
|
@ -752,7 +752,7 @@ bool move_word_state_machine_t::consume_char_path_components(wchar_t c)
|
||||||
}
|
}
|
||||||
state = s_whitespace;
|
state = s_whitespace;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case s_whitespace:
|
case s_whitespace:
|
||||||
if (iswspace(c))
|
if (iswspace(c))
|
||||||
{
|
{
|
||||||
|
@ -820,9 +820,12 @@ bool move_word_state_machine_t::consume_char(wchar_t c)
|
||||||
{
|
{
|
||||||
switch (style)
|
switch (style)
|
||||||
{
|
{
|
||||||
case move_word_style_punctuation: return consume_char_punctuation(c);
|
case move_word_style_punctuation:
|
||||||
case move_word_style_path_components: return consume_char_path_components(c);
|
return consume_char_punctuation(c);
|
||||||
default: return false;
|
case move_word_style_path_components:
|
||||||
|
return consume_char_path_components(c);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,11 +193,11 @@ enum move_word_style_t
|
||||||
class move_word_state_machine_t
|
class move_word_state_machine_t
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool consume_char_punctuation(wchar_t c);
|
bool consume_char_punctuation(wchar_t c);
|
||||||
bool consume_char_path_components(wchar_t c);
|
bool consume_char_path_components(wchar_t c);
|
||||||
bool is_path_component_character(wchar_t c);
|
bool is_path_component_character(wchar_t c);
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
move_word_style_t style;
|
move_word_style_t style;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user