Skip to content

Commit

Permalink
Added TuiContainer and TuiDialog and TuiFileBox. TuiWindow now adds w…
Browse files Browse the repository at this point in the history
…idgets to a container subclass. It is easier this way. All containers clip to their rect and all widgets clip to their context space.

Added some preliminary exceptions. Fixed a bug in Directory Scaffold for Windows. Separated variadic string format from Console. Prettied output for debugger.
  • Loading branch information
wilkie committed Aug 21, 2009
1 parent c67421a commit cbb6b53
Show file tree
Hide file tree
Showing 20 changed files with 861 additions and 314 deletions.
13 changes: 8 additions & 5 deletions analyzing/debugger.d
Expand Up @@ -42,18 +42,21 @@ public:
}
}

Console.putln("");
Console.setColor(fgColor.BrightRed);

if (t is null) {
Console.put("Unhandled Main Exception: ", e.toString());
Console.putln("Unhandled Main Exception: ");
Console.putln(" cause: ", e.toString());
}
else {
Console.put("Unhandled Thread Exception: ", e.toString());
Console.putln("Unhandled Thread Exception: ");
Console.putln(" cause: ", e.toString());
}

version(LDC) {
// Tango provides a traceback for us
Console.put(" from file: ", e.file);
Console.putln(" file: ", e.file);
}
else {
}
Expand All @@ -63,14 +66,14 @@ public:
ClassInfo ci = w.classinfo;
String className = new String(ci.name);

Console.put(" from window: ", className.array, " [", w.text.array, "]");
Console.put(" window: ", className.array, " [", w.text.array, "]");
}
if (t !is null) {
// get class name
ClassInfo ci = t.classinfo;
String className = new String(ci.name);

Console.put(" from thread: ", className.array);
Console.put(" thread: ", className.array);
}

Console.setColor(fgColor.White);
Expand Down
41 changes: 41 additions & 0 deletions core/exception.d
@@ -0,0 +1,41 @@
/*
* exception.d
*
* This module defines common exceptions.
*
* Author: Dave Wilkinson
* Originated: August 20th, 2009
*
*/

module core.exception;

import core.string;

class FileNotFound : Exception {
this() {
super("File Not Found");
}

this(String path) {
super("File Not Found: " ~ path.toString());
}

this(string path) {
super("File Not Found: " ~ path);
}
}

class DirectoryNotFound : Exception {
this() {
super("Directory Not Found");
}

this(String path) {
super("Directory Not Found: " ~ path.toString());
}

this(string path) {
super("Directory Not Found: " ~ path);
}
}
8 changes: 6 additions & 2 deletions core/format.d
Expand Up @@ -31,6 +31,10 @@ template formatToString() {
if (_arguments[curArg] is typeid(String)) {
toParse ~= va_arg!(String)(_argptr);
}
else if (_arguments[curArg] is typeid(char*)) {
char* argval = cast(char*)va_arg!(char*)(_argptr);
char[] dstr = argval[0..strlen(argval)-1];
}
else if (_arguments[curArg] is typeid(bool)) {
bool argval = cast(bool)va_arg!(bool)(_argptr);
if (argval) {
Expand Down Expand Up @@ -78,11 +82,11 @@ template formatToString() {
}
else if (_arguments[curArg] is typeid(wchar[])) {
wchar[] chrs = va_arg!(wchar[])(_argptr);
toParse ~= cast(char[])chrs;
toParse ~= Unicode.toUtf8(chrs);
}
else if (_arguments[curArg] is typeid(dchar[])) {
dchar[] chrs = va_arg!(dchar[])(_argptr);
toParse ~= cast(char[])chrs;
toParse ~= Unicode.toUtf8(chrs);
}
else if (_arguments[curArg] is typeid(dchar)) {
dchar chr = va_arg!(dchar)(_argptr);
Expand Down
58 changes: 58 additions & 0 deletions core/string.d
Expand Up @@ -1007,3 +1007,61 @@ private:
uint _capacity;
Char _data[];
}

// Standard string functions (for C)

// strlen
size_t strlen(char* chr) {
uint ret = 0;
while(*chr++) {
ret++;
}
return ret;
}

void strncpy(char* dest, char* src, int length) {
while(((*dest++ = *src++) != 0) && --length){}
*(--dest) = '\0';
}

void strncat(char* dest, char* src, int length) {
while(*dest++){}
strncpy(--dest,src,length);
}

int strcmp(char* a, char* b) {
while((*a == *b) && *a++ && *b++){}
return *a - *b;
}

int strncmp(char* a, char* b, int length) {
while(--length && (*a == *b) && *a++ && *b++){}
return *a - *b;
}

void strcpy(char* dest, char* src) {
while((*dest++ = *src++) != 0){}
}

void strcat(char* dest, char* src) {
while(*dest++){}
strcpy(--dest,src);
}

void strupr(char* str) {
while(*str) {
if (*str >= 'a' || *str <= 'z') {
*str -= 32;
}
str++;
}
}

void strlwr(char* str) {
while(*str) {
if (*str >= 'A' || *str <= 'Z') {
*str += 32;
}
str++;
}
}
78 changes: 39 additions & 39 deletions io/console.d
Expand Up @@ -171,11 +171,22 @@ static:
ConsoleSetPosition(x,y);
}

uint[] position() {
uint x;
uint y;
ConsoleGetPosition(x,y);
return [x,y];
void position(Coord coord) {
ConsoleSetPosition(coord.x, coord.y);
}

void position(uint[] coord) {
ConsoleSetPosition(coord[0], coord[1]);
}

void position(uint x, uint y) {
ConsoleSetPosition(x,y);
}

Coord position() {
Coord ret;
ConsoleGetPosition(cast(uint*)&ret.x,cast(uint*)&ret.y);
return ret;
}

// Description: Moves the position of the caret relative to its current location.
Expand Down Expand Up @@ -288,6 +299,10 @@ static:
}
}

void putString(String str) {
_putString(str);
}

// Description: Will print out this character to the screen and the current location.
// chr: The UTF-32 character to print.
void putChar(dchar chr) {
Expand Down Expand Up @@ -490,23 +505,36 @@ private:
} while(value /= 10);
ConsolePutString(foo);
}

void _putString(String str) {
uint x;
uint y;
uint r;
uint b;

ConsoleGetPosition(x,y);
// Clip to the bounds of the screen first
ConsoleGetPosition(&x,&y);

r = x + str.length;
b = y + 1;

/*if ((x >= this.width) || (y >= this.height)) {
// Outside bounds of screen completely
return;
}
// Do we need to clip the string? (right edge)
if (r > this.width) {
uint rightPos = r - (this.width);
str = str.subString(0, str.length - rightPos);
r = x + str.length;
}*/

if (_clippingRegions.length == 0) {
ConsolePutString(str.toUtf32());
return;
}

r = x + str.length;
b = y + 1;

// This will contain lengths of substrings
// It will alternate, OUT IN OUT IN OUT etc
// Where OUT means it is not drawn, and IN is
Expand All @@ -515,12 +543,6 @@ private:
uint[] formatArray = [str.length, 0];

foreach(region; _clippingRegions) {
/*ConsolePutString("cr[");
foreach (item; formatArray) {
_putInt(item);
ConsolePutString(", ");
}
ConsolePutString("]");*/
if (!(x > region.right || r < region.left || y > region.bottom || b < region.top)) {
// This string clips this clipping rectangle
// Grab the substring within the clipping region
Expand Down Expand Up @@ -573,12 +595,6 @@ private:
endIdx = formatArray.length - 1;
endPos = pos;
}
/*ConsolePutString("se[");
_putInt(startIdx);
ConsolePutString(", ");
_putInt(endIdx);
ConsolePutString(", ");
ConsolePutString("]");*/

// Add to formatArray
uint oldLength = 0;
Expand Down Expand Up @@ -620,23 +636,11 @@ private:
oldLength = formatArray[startIdx];
newLength = start + startPos;
}
//ConsolePutString("ln[");
// _putInt(oldLength);
// ConsolePutString(", ");
// _putInt(newLength);
// ConsolePutString(", ");
//ConsolePutString("]");

if ((endIdx & 1) == 1) {
// endIdx represents something that will be outputted
uint finalPos = endPos + formatArray[endIdx];
uint outLength = finalPos - start;
/*ConsolePutString("fo[");
_putInt(endPos);
ConsolePutString(", ");
_putInt(outLength);
ConsolePutString(", ");
ConsolePutString("]");*/
if (endIdx + 1 < formatArray.length) {
formatArray = formatArray[0..startIdx] ~ [newLength, outLength] ~ formatArray[endIdx+1..$];
}
Expand All @@ -662,19 +666,15 @@ private:

bool isOut = true;
uint pos = 0;
//ConsolePutString("[");

for (uint i; i < formatArray.length; i++, isOut = !isOut) {
//_putInt(formatArray[i]);
//ConsolePutString(", ");
if (isOut) {
ConsoleSetRelative(formatArray[i], 0);
// ConsolePutString(str.subString(pos, formatArray[i]).toUtf32());
}
else {
ConsolePutString(str.subString(pos, formatArray[i]).toUtf32());
}
pos += formatArray[i];
}
//ConsolePutString("]");
}
}
10 changes: 7 additions & 3 deletions io/directory.d
Expand Up @@ -13,6 +13,7 @@ module io.directory;
import core.string;
import core.system;
import core.definitions;
import core.exception;

import io.file;
import io.console;
Expand Down Expand Up @@ -198,11 +199,14 @@ class Directory
// directoryName: The _name of the directory.
// Returns: The child directory specified.
Directory traverse(String directoryName) {
Directory ret = new Directory(_path ~ "/" ~ directoryName);
if (isDir(directoryName)) {
Directory ret = new Directory(_path ~ "/" ~ directoryName);

ret._parent = this;
ret._parent = this;

return ret;
return ret;
}
throw new DirectoryNotFound(_path ~ "/" ~ directoryName);
}

// Description: This function will return the Directory representing the directory specified within the current path.
Expand Down
4 changes: 2 additions & 2 deletions makefile
Expand Up @@ -26,7 +26,7 @@ DFILES_PLATFORM_WIN = platform/win/platform/vars/tui.d platform/win/scaffold/tui
DFILES_PLATFORM_XOMB = platform/xomb/main.d platform/xomb/common.d platform/xomb/scaffold.d platform/xomb/vars.d platform/xomb/console.d platform/xomb/definitions.d platform/xomb/scaffolds/wave.d platform/xomb/scaffolds/graphics.d platform/xomb/scaffolds/thread.d platform/xomb/scaffolds/menu.d platform/xomb/scaffolds/window.d platform/xomb/scaffolds/view.d platform/xomb/scaffolds/color.d platform/xomb/scaffolds/file.d platform/xomb/scaffolds/socket.d platform/xomb/scaffolds/app.d platform/xomb/scaffolds/time.d platform/xomb/oscontrolinterface.d

DFILES_ANALYZING = analyzing/debugger.d
DFILES_CORE = core/event.d core/library.d core/system.d core/random.d core/regex.d core/arguments.d core/definitions.d core/application.d core/format.d core/time.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d
DFILES_CORE = core/exception.d core/event.d core/library.d core/system.d core/random.d core/regex.d core/arguments.d core/definitions.d core/application.d core/format.d core/time.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d
DFILES_GUI = gui/container.d gui/trackbar.d gui/radiogroup.d gui/progressbar.d gui/togglefield.d gui/listfield.d gui/listbox.d gui/vscrollbar.d gui/hscrollbar.d gui/button.d gui/textfield.d gui/window.d gui/widget.d gui/application.d
DFILES_UTILS = utils/stack.d utils/arraylist.d utils/linkedlist.d
DFILES_PARSING = parsing/lexer.d parsing/cfg.d
Expand All @@ -41,7 +41,7 @@ DFILES_RESOURCE = resource/sound.d resource/image.d resource/resource.d resource
DFILES_CODEC = codecs/codec.d
DFILES_HASHES = hashes/digest.d hashes/all.d hashes/md5.d hashes/sha1.d hashes/sha224.d hashes/sha256.d
DFILES_CONSOLE = console/prompt.d
DFILES_TUI = tui/container.d tui/dialog.d tui/window.d tui/application.d tui/widget.d tui/telnet.d tui/buffer.d tui/vt100.d tui/listbox.d tui/textfield.d tui/label.d tui/textbox.d tui/codebox.d
DFILES_TUI = tui/filebox.d tui/container.d tui/dialog.d tui/window.d tui/application.d tui/widget.d tui/telnet.d tui/buffer.d tui/vt100.d tui/listbox.d tui/textfield.d tui/label.d tui/textbox.d tui/codebox.d
DFILES_SCRIPTING = scripting/lua.d
DFILES_BINDING = binding/lua.d
DFILES_INTERFACES = interfaces/container.d interfaces/mod.d interfaces/list.d
Expand Down

0 comments on commit cbb6b53

Please sign in to comment.