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
5 changes: 5 additions & 0 deletions demos/colors/source/colors.d
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ void main()

auto s = newScreen();
assert(s !is null);
scope (exit)
{
s.stop();
}

ColorBoxes cb = new ColorBoxes();

auto now = MonoTime.currTime();
Expand Down
4 changes: 4 additions & 0 deletions demos/hello/source/hello.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void main()

auto ts = newScreen();
assert(ts !is null);
scope (exit)
{
ts.stop();
}

ts.start();
displayHelloWorld(ts);
Expand Down
5 changes: 5 additions & 0 deletions demos/mouse/source/mouse.d
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void main()

auto s = newScreen();
assert(s !is null);
scope (exit)
{
s.stop();
}

dstring posFmt = "Mouse: %d, %d";
dstring btnFmt = "Buttons: %s";
Expand All @@ -108,6 +112,7 @@ void main()
s.showCursor(Cursor.hidden);
s.enableMouse(MouseEnable.all);
s.enablePaste(true);
s.setTitle("Dcell Event Demo");
Style white;
white.fg = Color.midnightBlue;
white.bg = Color.lightCoral;
Expand Down
9 changes: 9 additions & 0 deletions source/dcell/screen.d
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ interface Screen
*/
void enableAlternateScreen(bool on);

/**
* Set the title of the window. This only works for emulators running
* in a windowing environment, and is not universally supported.
* Setting an empty string as the title may let the emulator set
* a specific default, but it may also leave it empty - it depends
* on the specific terminal implementation.
*/
void setTitle(string);

/**
* If the terminal supports color, this returns the
* the number of colors.
Expand Down
48 changes: 34 additions & 14 deletions source/dcell/ttyscreen.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ class TtyScreen : Screen
string enterURL = "\x1b]8;;%s\x1b\\";
string exitURL = "\x1b]8;;\x1b\\";
string setWindowSize = "\x1b[8;%d;%dt";
// Some terminals do not support the title stack, but do support
// changing the title. For those we set the title back to the
// empty string (which they take to mean unset) as a reasonable
// fallback. Shell programs generally change this as needed anyway.
string saveTitle = "\x1b[22;2t";
string restoreTitle = "\x1b[23;2t";
string restoreTitle = "\x1b]2;\x1b\\" ~ "\x1b[23;2t";
string setTitle = "\x1b[>2t\x1b]2;%s\x1b\\";
// three advanced keyboard protocols:
// - xterm modifyOtherKeys (uses CSI 27 ~ )
Expand Down Expand Up @@ -233,14 +237,14 @@ class TtyScreen : Screen

if (legacy)
{
vt.enterURL = "";
vt.exitURL = "";
vt.setWindowSize = "";
vt.setTitle = "";
vt.restoreTitle = "";
vt.saveTitle = "";
vt.enableCsiU = "";
vt.disableCsiU = "";
vt.enterURL = null;
vt.exitURL = null;
vt.setWindowSize = null;
vt.setTitle = null;
vt.restoreTitle = null;
vt.saveTitle = null;
vt.enableCsiU = null;
vt.disableCsiU = null;
}
}

Expand All @@ -257,18 +261,22 @@ class TtyScreen : Screen
parser = new Parser(); // if we are restarting, this discards the old one
ti.save();
ti.raw();
puts(vt.hideCursor);
puts(vt.disableAutoMargin);
puts(vt.enableCsiU);
if (altScrEn)
{
puts(vt.enterCA);
}
puts(vt.hideCursor);
puts(vt.disableAutoMargin);
puts(vt.enableCsiU);
puts(vt.saveTitle);
puts(vt.enterKeypad);
puts(vt.enableFocus);
puts(vt.enableAltChars);
puts(vt.clear);
if (title && !vt.setTitle.empty)
{
puts(format(vt.setTitle, title));
}

resize();
draw();
Expand All @@ -287,6 +295,7 @@ class TtyScreen : Screen
puts(vt.cursorReset);
puts(vt.showCursor);
puts(vt.cursorReset);
puts(vt.restoreTitle);
if (altScrEn)
{
puts(vt.clear);
Expand Down Expand Up @@ -428,6 +437,16 @@ class TtyScreen : Screen
}
}

void setTitle(string title)
{
this.title = title;
if (started && !vt.setTitle.empty)
{
puts(format(vt.setTitle, title));
flush();
}
}

Event waitEvent(Duration dur = msecs(100))
{
// naive polling loop for now.
Expand Down Expand Up @@ -510,6 +529,7 @@ private:
Vt vt;
Event[] events;
Parser parser;
string title;

void puts(string s)
{
Expand Down Expand Up @@ -620,7 +640,7 @@ private:
{
if (pos != pos_)
{
puts(format!(Vt.setCursorPosition)(pos.y + 1, pos.x + 1));
puts(format!(vt.setCursorPosition)(pos.y + 1, pos.x + 1));
pos_ = pos;
}
}
Expand Down Expand Up @@ -705,7 +725,7 @@ private:
}
if (c.style.url != style_.url)
{
if (c.style.url != "")
if (c.style.url != "" && vt.enterURL !is null)
{
puts(format(vt.enterURL, c.style.url));
}
Expand Down