Fix event::print's header printing

Turns out doing `==` on Enums with values will do a deep comparison,
including the values.

So EventDescription::Signal(SIGTERM) is !=
EventDescription::Signal(SIGWINCH).

That's not what we want here, so this does a bit of a roundabout thing.
This commit is contained in:
Fabian Boehm 2023-08-10 18:42:11 +02:00
parent 4f86f303f5
commit ee8e790aa7
2 changed files with 24 additions and 4 deletions

View file

@ -845,19 +845,25 @@ pub fn print(streams: &mut io_streams_t, type_filter: &wstr) {
tmp.sort_by(|e1, e2| e1.desc.cmp(&e2.desc));
let mut last_type = None;
let mut last_type = std::mem::discriminant(&EventDescription::Any);
for evt in tmp {
// If we have a filter, skip events that don't match.
if !evt.desc.matches_filter(type_filter) {
continue;
}
if last_type.as_ref() != Some(&evt.desc) {
if last_type.is_some() {
// Print a "Event $TYPE" header for each event type.
// This compares only the event *type*, not the entire event,
// so we don't compare variable events for different variables as different.
//
// This assumes EventDescription::Any is not a valid value for an event to have
// - it's marked "unreachable!()" below!
if last_type != std::mem::discriminant(&evt.desc) {
if last_type != std::mem::discriminant(&EventDescription::Any) {
streams.out.append(L!("\n"));
}
last_type = Some(evt.desc.clone());
last_type = std::mem::discriminant(&evt.desc);
streams
.out
.append(&sprintf!(L!("Event %ls\n"), evt.desc.name()));

View file

@ -171,3 +171,17 @@ functions --no-details --details t
# CHECKERR: ^
# CHECKERR: (Type 'help functions' for related documentation)
# XXX FIXME ^ caret should point at --no-details --details
function term1 --on-signal TERM
end
function term2 --on-signal TERM
end
function term3 --on-signal TERM
end
functions --handlers-type signal
# CHECK: Event signal
# CHECK: SIGTRAP fish_sigtrap_handler
# CHECK: SIGTERM term1
# CHECK: SIGTERM term2
# CHECK: SIGTERM term3