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

Skip to content
Merged
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
3 changes: 1 addition & 2 deletions demos/colors/source/colors.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module color;

import std.stdio;
import std.string;
import std.concurrency;
import std.random;
import std.range;
import dcell;
Expand Down Expand Up @@ -137,7 +136,7 @@ void main()
while (!done)
{
cb.makeBox(s);
auto ev = s.receiveEvent(msecs(50));
auto ev = s.waitEvent(msecs(50));
switch (ev.type)
{
case EventType.key:
Expand Down
104 changes: 51 additions & 53 deletions demos/hello/source/hello.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Hello world demo for Dcell.
*
* Copyright: Copyright 2022 Garrett D'Amore
* Copyright: Copyright 2025 Garrett D'Amore
* Authors: Garrett D'Amore
* License:
* Distributed under the Boost Software License, Version 1.0.
Expand All @@ -12,77 +12,75 @@ module hello;

import std.stdio;
import std.string;
import std.concurrency;

import dcell;

void emitStr(Screen s, int x, int y, Style style, string str)
{
// NB: this naively assumes only ASCII
while (str != "")
{
s[x, y] = Cell(str[0], style);
str = str[1..$];
x += 1;
}
// NB: this naively assumes only ASCII
while (str != "")
{
s[x, y] = Cell(str[0], style);
str = str[1 .. $];
x += 1;
}
}

void displayHelloWorld(Screen s)
{
auto size = s.size();
Style def;
def.bg = Color.silver;
def.fg = Color.black;
s.setStyle(def);
s.clear();
Style style = {fg: Color.red, bg: Color.papayaWhip};
emitStr(s, size.x / 2 - 9, size.y / 2 - 1, style, " Hello, World! ");
emitStr(s, size.x / 2 - 11, size.y / 2 + 1, def, " Press ESC to exit. ");
auto size = s.size();
Style def;
def.bg = Color.silver;
def.fg = Color.black;
s.setStyle(def);
s.clear();
Style style = {fg: Color.red, bg: Color.papayaWhip};
emitStr(s, size.x / 2 - 9, size.y / 2 - 1, style, " Hello, World! ");
emitStr(s, size.x / 2 - 11, size.y / 2 + 1, def, " Press ESC to exit. ");

// this demonstrates a different method.
// it places a red X in the center of the screen.
s[$/2, $/2].text = "X";
s[$/2, $/2].style.fg = Color.white;
s[$/2, $/2].style.bg = Color.red;
s.show();
// this demonstrates a different method.
// it places a red X in the center of the screen.
s[$ / 2, $ / 2].text = "X";
s[$ / 2, $ / 2].style.fg = Color.white;
s[$ / 2, $ / 2].style.bg = Color.red;
s.show();
}

void handleEvent(Screen ts, Event ev)
{
import core.stdc.stdlib : exit;
import core.stdc.stdlib : exit;

switch (ev.type)
{
case EventType.key:
if (ev.key.key == Key.esc || ev.key.key == Key.f1)
{
ts.stop();
exit(0);
}
break;
case EventType.resize:
ts.resize();
displayHelloWorld(ts);
ts.sync();
break;
default:
break;
}
switch (ev.type)
{
case EventType.key:
if (ev.key.key == Key.esc || ev.key.key == Key.f1)
{
ts.stop();
exit(0);
}
break;
case EventType.resize:
ts.resize();
displayHelloWorld(ts);
ts.sync();
break;
default:
break;
}
}

void main()
{
import std.stdio;
import std.stdio;

auto ts = newScreen();
assert(ts !is null);
auto ts = newScreen();
assert(ts !is null);

ts.start(thisTid());
displayHelloWorld(ts);
for (;;)
{
receive(
(Event ev) { handleEvent(ts, ev); }
);
}
ts.start();
displayHelloWorld(ts);
for (;;)
{
Event ev = ts.waitEvent();
handleEvent(ts, ev);
}
}
8 changes: 2 additions & 6 deletions demos/mouse/source/mouse.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module mouse;

import std.stdio;
import std.string;
import std.concurrency;
import core.stdc.stdlib;

import dcell;
Expand Down Expand Up @@ -105,7 +104,7 @@ void main()
dstring kStr = "";
dstring pStr = "";

s.start(thisTid());
s.start();
s.showCursor(Cursor.hidden);
s.enableMouse(MouseEnable.all);
s.enablePaste(true);
Expand Down Expand Up @@ -140,10 +139,7 @@ void main()
emitStr(s, pos, white, format(pasteFmt, pStr.length, ps));
s.show();
bStr = "";
Event ev;
receive(
(Event ee) { ev = ee; }
);
Event ev = s.waitEvent();
Style st;
st.bg = Color.red;
Style up;
Expand Down
120 changes: 0 additions & 120 deletions source/dcell/evqueue.d

This file was deleted.

2 changes: 1 addition & 1 deletion source/dcell/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ class Parser
return cast(Event[]) res;
}

// Parse the supplied content, returns true if data is fully parsed.
bool parse(string b)
{
buf ~= b;
Expand Down Expand Up @@ -360,7 +361,6 @@ private:
Event[] evs;
int utfLen; // how many UTF bytes are expected
ubyte escChar; // character immediately following escape (zero if none)
const KeyCode[string] keyCodes;
bool partial; // record partially parsed sequences
MonoTime keyStart; // when the timer started
Duration seqTime = msecs(50); // time to fully decode a partial sequence
Expand Down
32 changes: 9 additions & 23 deletions source/dcell/screen.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
module dcell.screen;

import core.time;
import std.concurrency;

public import dcell.cell;
public import dcell.cursor;
Expand Down Expand Up @@ -94,21 +93,11 @@ interface Screen
Coord size();

/**
* If start was called without a Tid to send to, then events
* are delivered into a queue that can be polled via this API.
* This function is thread safe.
* Params:
* dur = maximum time to wait, if no event is available then EventType.none is returned.
* Returns:
* The event, which will be EventType.none if it times out, or EventType.closed if it is stopped.
* Wait for an event, up to the given duration. This is used
* to rescan for changes as well, so it should be called as
* frequently.
*/
Event receiveEvent(Duration dur);

/**
* Receive events, without a timeout. This only works if start
* was called without a tid.
*/
Event receiveEvent();
Event waitEvent(Duration dur = msecs(100));

/**
* Enable bracketed paste mode mode. Bracketed paste mode
Expand Down Expand Up @@ -211,20 +200,17 @@ interface Screen
void resize();

/**
* Start should be called to start processing. Once this begins,
* events (see event.d) will be delivered to the caller via
* std.concurrency.send(). Additionally, this may change terminal
* Start sets up the terminal. This changes terminal
* settings to put the input stream into raw mode, etc.
*/
void start();
void start(Tid);

/**
* Stop is called to stop processing on the screen. The terminal
* settings will be restored, and the screen may be cleared. Input
* events will no longer be delivered. This should be called when
* the program is exited, or if suspending (to run a sub-shell process
* interactively for example).
* settings will be restored, and the screen may be cleared.
*
* This should be called when the program is exited, or if suspending
* (to run a sub-shell process interactively for example).
*/
void stop();
}
Loading