Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/dcell/coord.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
*/
module dcell.coord;

import std.format : format;

/**
* Coordinates are X, Y values.
*/
struct Coord
{
int x; // aka column
int y; // aka row

string toString() const pure
{
return format("(%d, %d)", x, y);
}
}
43 changes: 43 additions & 0 deletions source/dcell/event.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
module dcell.event;

import core.time;
import std.format : format;
import std.range;

import dcell.key;
Expand Down Expand Up @@ -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());
}
}
}

/**
Expand All @@ -55,6 +79,10 @@ struct Event
*/
struct ResizeEvent
{
string toString() const pure
{
return "Resize";
}
}

/**
Expand All @@ -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]";
}
}

/**
Expand Down
58 changes: 58 additions & 0 deletions source/dcell/mouse.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
module dcell.mouse;

import std.array : Appender;
import std.format : format;

public import dcell.coord;
public import dcell.key : Modifiers;

Expand Down Expand Up @@ -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;
}
}