merge in terminal emulator core as a lib

This commit is contained in:
Adam D. Ruppe 2020-03-26 21:06:00 -04:00
parent 01219f4978
commit 2fc0b49c07
6 changed files with 4479 additions and 28 deletions

View File

@ -318,12 +318,29 @@
"name": "builtin_emulator", "name": "builtin_emulator",
"versions": ["TerminalDirectToEmulator"], "versions": ["TerminalDirectToEmulator"],
"dependencies": { "dependencies": {
"adr-terminalemulator:core": ">=0.0.8", "arsd-official:terminalemulator": "*",
"arsd-official:minigui": "*" "arsd-official:minigui": "*",
"arsd-official:png":"*",
"arsd-official:jpeg":"*",
"arsd-official:svg":"*",
"arsd-official:bmp":"*"
} }
} }
] ]
}, },
{
"name": "terminalemulator",
"description": "A terminal emulation core as an in-memory library. Also includes mixin templates to assist with creating UIs, etc.",
"targetType": "library",
"importPaths": ["."],
"libs-posix": ["util"],
"sourceFiles": ["terminalemulator.d"],
"dflags": ["-mv=arsd.terminalemulator=terminalemulator.d"],
"dependencies": {
"arsd-official:color_base":"*"
}
},
{ {
"name": "ttf", "name": "ttf",
"description": "port of stb_ttf to D", "description": "port of stb_ttf to D",

View File

@ -1149,7 +1149,7 @@ class HttpRequest {
if(colon == -1) if(colon == -1)
return; return;
auto name = header[0 .. colon]; auto name = header[0 .. colon];
if(colon + 1 == header.length) if(colon + 1 == header.length || colon + 2 == header.length) // assuming a space there
return; // empty header, idk return; // empty header, idk
assert(colon + 2 < header.length, header); assert(colon + 2 < header.length, header);
auto value = header[colon + 2 .. $]; // skipping the colon itself and the following space auto value = header[colon + 2 .. $]; // skipping the colon itself and the following space

View File

@ -5204,17 +5204,18 @@ class Menu : Window {
void popup(Widget parent, int offsetX = 0, int offsetY = int.min) { void popup(Widget parent, int offsetX = 0, int offsetY = int.min) {
this.menuParent = parent; this.menuParent = parent;
auto w = 150; int w = 150;
auto h = paddingTop + paddingBottom; int h = paddingTop + paddingBottom;
Widget previousChild; if(this.children.length) {
foreach(child; this.children) { // hacking it to get the ideal height out of recomputeChildLayout
h += child.minHeight(); this.width = w;
h += mymax(child.marginTop(), previousChild ? previousChild.marginBottom() : 0); this.height = h;
previousChild = child; this.recomputeChildLayout();
} h = this.children[$-1].y + this.children[$-1].height + this.children[$-1].marginBottom;
h += paddingBottom;
if(previousChild) h -= 2; // total hack, i just like the way it looks a bit tighter even though technically MenuItem reserves some space to center in normal circumstances
h += previousChild.marginBottom(); }
if(offsetY == int.min) if(offsetY == int.min)
offsetY = parent.parentWindow.lineHeight; offsetY = parent.parentWindow.lineHeight;

View File

@ -6223,6 +6223,8 @@ class OperatingSystemFont {
XFontSet fontset; XFontSet fontset;
} else version(Windows) { } else version(Windows) {
HFONT font; HFONT font;
int width_;
int height_;
} else version(OSXCocoa) { } else version(OSXCocoa) {
// FIXME // FIXME
} else static assert(0); } else static assert(0);
@ -6274,6 +6276,15 @@ class OperatingSystemFont {
} else version(Windows) { } else version(Windows) {
WCharzBuffer buffer = WCharzBuffer(name); WCharzBuffer buffer = WCharzBuffer(name);
font = CreateFont(size, 0, 0, 0, cast(int) weight, italic, 0, 0, 0, 0, 0, 0, 0, buffer.ptr); font = CreateFont(size, 0, 0, 0, cast(int) weight, italic, 0, 0, 0, 0, 0, 0, 0, buffer.ptr);
TEXTMETRIC tm;
auto dc = GetDC(null);
SelectObject(dc, font);
GetTextMetrics(dc, &tm);
ReleaseDC(null, dc);
width_ = tm.tmAveCharWidth;
height_ = tm.tmHeight;
} else version(OSXCocoa) { } else version(OSXCocoa) {
// FIXME // FIXME
} else static assert(0); } else static assert(0);
@ -6307,6 +6318,26 @@ class OperatingSystemFont {
} else static assert(0); } else static assert(0);
} }
// Assuming monospace!!!!!
// added March 26, 2020
int averageWidth() {
version(X11)
return font.max_bounds.width;
else version(Windows)
return width_;
else assert(0);
}
// Assuming monospace!!!!!
// added March 26, 2020
int height() {
version(X11)
return font.max_bounds.ascent + font.max_bounds.descent;
else version(Windows)
return height_;
else assert(0);
}
/// FIXME not implemented /// FIXME not implemented
void loadDefault() { void loadDefault() {
@ -6320,12 +6351,9 @@ class OperatingSystemFont {
/* Metrics */ /* Metrics */
/+ /+
GetFontMetrics
GetABCWidth GetABCWidth
GetKerningPairs GetKerningPairs
XLoadQueryFont
if I do it right, I can size it all here, and match if I do it right, I can size it all here, and match
what happens when I draw the full string with the OS functions. what happens when I draw the full string with the OS functions.

View File

@ -1015,6 +1015,8 @@ struct Terminal {
bool hasDefaultDarkBackground() { bool hasDefaultDarkBackground() {
version(Win32Console) { version(Win32Console) {
return !(defaultBackgroundColor & 0xf); return !(defaultBackgroundColor & 0xf);
} version(TerminalDirectToEmulator) {
return integratedTerminalEmulatorConfiguration.defaultBackground.g < 100;
} else { } else {
// FIXME: there is probably a better way to do this // FIXME: there is probably a better way to do this
// but like idk how reliable it is. // but like idk how reliable it is.
@ -5717,9 +5719,14 @@ version(TerminalDirectToEmulator) {
/// Default background color of the terminal. /// Default background color of the terminal.
Color defaultBackground = Color.white; Color defaultBackground = Color.white;
/// Font to use in the window. It should be a monospace font, /++
/// and your selection may not actually be used if not available on Font to use in the window. It should be a monospace font,
/// the user's system, in which case it will fallback to one. and your selection may not actually be used if not available on
the user's system, in which case it will fallback to one.
History:
Implemented March 26, 2020
+/
string fontName; string fontName;
/// ditto /// ditto
int fontSize = 14; int fontSize = 14;
@ -5735,15 +5742,16 @@ version(TerminalDirectToEmulator) {
if scroll lock is on... if scroll lock is on...
+/ +/
/// You can set this in a static module constructor. /// You can set this in a static module constructor. (`shared static this() {}`)
immutable IntegratedTerminalEmulatorConfiguration integratedTerminalEmulatorConfiguration; __gshared IntegratedTerminalEmulatorConfiguration integratedTerminalEmulatorConfiguration;
import arsd.terminalemulator; import arsd.terminalemulator;
import arsd.minigui; import arsd.minigui;
private class TerminalEmulatorWindow : MainWindow { private class TerminalEmulatorWindow : MainWindow {
this(Terminal* term) { this(Terminal* term) {
super("Terminal Application", integratedTerminalEmulatorConfiguration.initialWidth * 7, integratedTerminalEmulatorConfiguration.initialHeight * 14); super("Terminal Application", integratedTerminalEmulatorConfiguration.initialWidth * integratedTerminalEmulatorConfiguration.fontSize / 2, integratedTerminalEmulatorConfiguration.initialHeight * integratedTerminalEmulatorConfiguration.fontSize);
smw = new ScrollMessageWidget(this); smw = new ScrollMessageWidget(this);
tew = new TerminalEmulatorWidget(term, smw); tew = new TerminalEmulatorWidget(term, smw);
@ -6085,12 +6093,17 @@ version(TerminalDirectToEmulator) {
this.widget = widget; this.widget = widget;
loadDefaultFont(); if(integratedTerminalEmulatorConfiguration.fontName.length) {
this.font = new OperatingSystemFont(integratedTerminalEmulatorConfiguration.fontName, integratedTerminalEmulatorConfiguration.fontSize, FontWeight.medium);
this.fontWidth = font.averageWidth;
this.fontHeight = font.height;
}
auto desiredWidth = 80;
auto desiredHeight = 24;
super(desiredWidth, desiredHeight); if(this.font is null || this.font.isNull)
loadDefaultFont(integratedTerminalEmulatorConfiguration.fontSize);
super(integratedTerminalEmulatorConfiguration.initialWidth, integratedTerminalEmulatorConfiguration.initialHeight);
defaultForeground = integratedTerminalEmulatorConfiguration.defaultForeground; defaultForeground = integratedTerminalEmulatorConfiguration.defaultForeground;
defaultBackground = integratedTerminalEmulatorConfiguration.defaultBackground; defaultBackground = integratedTerminalEmulatorConfiguration.defaultBackground;
@ -6185,8 +6198,6 @@ version(TerminalDirectToEmulator) {
}); });
} }
static int fontSize = 14;
bool clearScreenRequested = true; bool clearScreenRequested = true;
void redraw() { void redraw() {
if(widget.parentWindow is null || widget.parentWindow.win is null || widget.parentWindow.win.closed) if(widget.parentWindow is null || widget.parentWindow.win is null || widget.parentWindow.win.closed)

4394
terminalemulator.d Normal file

File diff suppressed because it is too large Load Diff