diff --git a/source/dcell/coord.d b/source/dcell/coord.d index be9cba4..cde7c8b 100644 --- a/source/dcell/coord.d +++ b/source/dcell/coord.d @@ -10,6 +10,8 @@ */ module dcell.coord; +import std.format : format; + /** * Coordinates are X, Y values. */ @@ -17,4 +19,9 @@ struct Coord { int x; // aka column int y; // aka row + + string toString() const pure + { + return format("(%d, %d)", x, y); + } } diff --git a/source/dcell/event.d b/source/dcell/event.d index 0c60a59..70f46c7 100644 --- a/source/dcell/event.d +++ b/source/dcell/event.d @@ -11,6 +11,7 @@ module dcell.event; import core.time; +import std.format : format; import std.range; import dcell.key; @@ -46,6 +47,29 @@ struct Event PasteEvent paste; FocusEvent focus; } + + string toString() const + { + final switch (type) + { + case EventType.none: + return "Event[none]"; + case EventType.closed: + return "Event[closed]"; + case EventType.error: + return "Event[error]"; + case EventType.key: + return format("Event[key: %s]", key.toString()); + case EventType.mouse: + return format("Event[mouse: %s]", mouse.toString()); + case EventType.paste: + return format("Event[paste: %s]", paste.toString()); + case EventType.resize: + return format("Event[resize: %s]", resize.toString()); + case EventType.focus: + return format("Event[focus: %s]", focus.toString()); + } + } } /** @@ -55,6 +79,10 @@ struct Event */ struct ResizeEvent { + string toString() const pure + { + return "Resize"; + } } /** @@ -64,12 +92,27 @@ struct PasteEvent { string content; /// string content for normal paste ubyte[] binary; /// binary data via OSC 52 or similar + + string toString() const pure + { + if (content.length > 0) + return format("Paste[%d chars]", content.length); + else if (binary.length > 0) + return format("Paste[%d bytes binary]", binary.length); + else + return "Paste[empty]"; + } } /// Focus event. struct FocusEvent { bool focused; + + string toString() const pure + { + return focused ? "Focus[gained]" : "Focus[lost]"; + } } /** diff --git a/source/dcell/mouse.d b/source/dcell/mouse.d index b78b900..489de24 100644 --- a/source/dcell/mouse.d +++ b/source/dcell/mouse.d @@ -10,6 +10,9 @@ */ module dcell.mouse; +import std.array : Appender; +import std.format : format; + public import dcell.coord; public import dcell.key : Modifiers; @@ -78,4 +81,59 @@ struct MouseEvent Buttons btn; /// Buttons involved. Modifiers mod; /// Keyboard modifiers pressed during event. Coord pos; /// Coordinates of mouse. + + string toString() const pure + { + Appender!string s; + + // Add modifiers + if (mod & Modifiers.ctrl) + s.put("Ctrl+"); + if (mod & Modifiers.shift) + s.put("Shift+"); + if (mod & Modifiers.meta) + s.put("Meta+"); + if (mod & Modifiers.alt) + s.put("Alt+"); + if (mod & Modifiers.hyper) + s.put("Hyper+"); + + // Add button names + string[] buttons; + if (btn & Buttons.button1) + buttons ~= "Button1"; + if (btn & Buttons.button2) + buttons ~= "Button2"; + if (btn & Buttons.button3) + buttons ~= "Button3"; + if (btn & Buttons.button4) + buttons ~= "Button4"; + if (btn & Buttons.button5) + buttons ~= "Button5"; + if (btn & Buttons.button6) + buttons ~= "Button6"; + if (btn & Buttons.button7) + buttons ~= "Button7"; + if (btn & Buttons.button8) + buttons ~= "Button8"; + if (btn & Buttons.wheelUp) + buttons ~= "WheelUp"; + if (btn & Buttons.wheelDown) + buttons ~= "WheelDown"; + if (btn & Buttons.wheelLeft) + buttons ~= "WheelLeft"; + if (btn & Buttons.wheelRight) + buttons ~= "WheelRight"; + + if (buttons.length == 0) + s.put("None"); + else + { + import std.array : join; + s.put(buttons.join("+")); + } + + s.put(format("@%s", pos.toString())); + return s.data; + } }