mirror of https://github.com/adamdruppe/arsd.git
merge in terminal emulator core as a lib
This commit is contained in:
parent
01219f4978
commit
2fc0b49c07
21
dub.json
21
dub.json
|
@ -318,12 +318,29 @@
|
|||
"name": "builtin_emulator",
|
||||
"versions": ["TerminalDirectToEmulator"],
|
||||
"dependencies": {
|
||||
"adr-terminalemulator:core": ">=0.0.8",
|
||||
"arsd-official:minigui": "*"
|
||||
"arsd-official:terminalemulator": "*",
|
||||
"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",
|
||||
"description": "port of stb_ttf to D",
|
||||
|
|
2
http2.d
2
http2.d
|
@ -1149,7 +1149,7 @@ class HttpRequest {
|
|||
if(colon == -1)
|
||||
return;
|
||||
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
|
||||
assert(colon + 2 < header.length, header);
|
||||
auto value = header[colon + 2 .. $]; // skipping the colon itself and the following space
|
||||
|
|
21
minigui.d
21
minigui.d
|
@ -5204,17 +5204,18 @@ class Menu : Window {
|
|||
void popup(Widget parent, int offsetX = 0, int offsetY = int.min) {
|
||||
this.menuParent = parent;
|
||||
|
||||
auto w = 150;
|
||||
auto h = paddingTop + paddingBottom;
|
||||
Widget previousChild;
|
||||
foreach(child; this.children) {
|
||||
h += child.minHeight();
|
||||
h += mymax(child.marginTop(), previousChild ? previousChild.marginBottom() : 0);
|
||||
previousChild = child;
|
||||
}
|
||||
int w = 150;
|
||||
int h = paddingTop + paddingBottom;
|
||||
if(this.children.length) {
|
||||
// hacking it to get the ideal height out of recomputeChildLayout
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
this.recomputeChildLayout();
|
||||
h = this.children[$-1].y + this.children[$-1].height + this.children[$-1].marginBottom;
|
||||
h += paddingBottom;
|
||||
|
||||
if(previousChild)
|
||||
h += previousChild.marginBottom();
|
||||
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
|
||||
}
|
||||
|
||||
if(offsetY == int.min)
|
||||
offsetY = parent.parentWindow.lineHeight;
|
||||
|
|
|
@ -6223,6 +6223,8 @@ class OperatingSystemFont {
|
|||
XFontSet fontset;
|
||||
} else version(Windows) {
|
||||
HFONT font;
|
||||
int width_;
|
||||
int height_;
|
||||
} else version(OSXCocoa) {
|
||||
// FIXME
|
||||
} else static assert(0);
|
||||
|
@ -6274,6 +6276,15 @@ class OperatingSystemFont {
|
|||
} else version(Windows) {
|
||||
WCharzBuffer buffer = WCharzBuffer(name);
|
||||
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) {
|
||||
// FIXME
|
||||
} else static assert(0);
|
||||
|
@ -6307,6 +6318,26 @@ class OperatingSystemFont {
|
|||
} 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
|
||||
void loadDefault() {
|
||||
|
||||
|
@ -6320,12 +6351,9 @@ class OperatingSystemFont {
|
|||
|
||||
/* Metrics */
|
||||
/+
|
||||
GetFontMetrics
|
||||
GetABCWidth
|
||||
GetKerningPairs
|
||||
|
||||
XLoadQueryFont
|
||||
|
||||
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.
|
||||
|
||||
|
|
35
terminal.d
35
terminal.d
|
@ -1015,6 +1015,8 @@ struct Terminal {
|
|||
bool hasDefaultDarkBackground() {
|
||||
version(Win32Console) {
|
||||
return !(defaultBackgroundColor & 0xf);
|
||||
} version(TerminalDirectToEmulator) {
|
||||
return integratedTerminalEmulatorConfiguration.defaultBackground.g < 100;
|
||||
} else {
|
||||
// FIXME: there is probably a better way to do this
|
||||
// but like idk how reliable it is.
|
||||
|
@ -5717,9 +5719,14 @@ version(TerminalDirectToEmulator) {
|
|||
/// Default background color of the terminal.
|
||||
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
|
||||
/// the user's system, in which case it will fallback to one.
|
||||
/++
|
||||
Font to use in the window. It should be a monospace font,
|
||||
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;
|
||||
/// ditto
|
||||
int fontSize = 14;
|
||||
|
@ -5735,15 +5742,16 @@ version(TerminalDirectToEmulator) {
|
|||
if scroll lock is on...
|
||||
+/
|
||||
|
||||
/// You can set this in a static module constructor.
|
||||
immutable IntegratedTerminalEmulatorConfiguration integratedTerminalEmulatorConfiguration;
|
||||
/// You can set this in a static module constructor. (`shared static this() {}`)
|
||||
__gshared IntegratedTerminalEmulatorConfiguration integratedTerminalEmulatorConfiguration;
|
||||
|
||||
import arsd.terminalemulator;
|
||||
import arsd.minigui;
|
||||
|
||||
private class TerminalEmulatorWindow : MainWindow {
|
||||
|
||||
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);
|
||||
tew = new TerminalEmulatorWidget(term, smw);
|
||||
|
@ -6085,12 +6093,17 @@ version(TerminalDirectToEmulator) {
|
|||
|
||||
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;
|
||||
defaultBackground = integratedTerminalEmulatorConfiguration.defaultBackground;
|
||||
|
@ -6185,8 +6198,6 @@ version(TerminalDirectToEmulator) {
|
|||
});
|
||||
}
|
||||
|
||||
static int fontSize = 14;
|
||||
|
||||
bool clearScreenRequested = true;
|
||||
void redraw() {
|
||||
if(widget.parentWindow is null || widget.parentWindow.win is null || widget.parentWindow.win.closed)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue