Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added terminal.d, fixed the docs for json.d

  • Loading branch information...
commit 136bbf329a6912fdc24c730c22b1e559ec6966c8 1 parent b2824e4
@carlor authored
View
13 Makefile
@@ -0,0 +1,13 @@
+
+CC=dmd
+SRC_FILES = containers/lookahead.d text/json.d ui/terminal.d
+
+
+all: build
+
+build:
+ $(CC) -c -odbin $(SRC_FILES)
+
+doc:
+ $(CC) -D -Dddocs -o- $(SRC_FILES)
+
View
BIN  bin/json.o
Binary file not shown
View
BIN  bin/lookahead.o
Binary file not shown
View
BIN  bin/terminal.o
Binary file not shown
View
493 docs/json.html
@@ -0,0 +1,493 @@
+<html><head>
+ <META http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>dcaflib.text.json</title>
+ </head><body>
+ <h1>dcaflib.text.json</h1>
+ <!-- Generated by Ddoc from text/json.d -->
+<u>json</u>.d contains functions and classes for reading, parsing, and writing JSON
+ documents. It is adapted from LibDJSON:
+ <a href="https://256.makerslocal.org/wiki/index.php/Libdjson">https://256.makerslocal.org/wiki/index.php/Libdjson</a>
+<br><br>
+<b>Authors:</b><br>
+William K. Moore, III (original author of LibDJSON)
+ Nathan M. Swan (added motifications)
+
+<br><br>
+<b>License:</b><br>
+Boost Software License - Version 1.0 - August 17th, 2003
+<br><br>
+
+ Permission is hereby granted, free of charge, to any person or organization
+ obtaining a copy of the software and accompanying documentation covered by
+ this license (the "Software") to use, reproduce, display, distribute,
+ execute, and transmit the Software, and to prepare derivative works of the
+ Software, and to permit third-parties to whom the Software is furnished to
+ do so, all subject to the following:
+<br><br>
+
+ The copyright notices in the Software and this entire statement, including
+ the above license grant, this restriction and the following disclaimer,
+ must be included in all copies of the Software, in whole or in part, and
+ all derivative works of the Software, unless such copies or derivative
+ works are solely in the form of machine-executable object code generated by
+ a source language processor.
+<br><br>
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+
+<br><br>
+<b>Standards:</b><br>
+Attempts to conform to the subset of Javascript required to
+ implement the JSON Specification.<br><br>
+
+<dl><dt><big>JSONType <u>readJSON</u>(string <i>src</i>);
+</big></dt>
+<dd>Read an entire string into a JSON tree.
+<br><br>
+<b>Returns:</b><br>
+A JSONObject with no name that is the root of the document that was read.
+<br><br>
+<b>Throws:</b><br>
+JSONException on any parsing errors.<br><br>
+
+</dd>
+<dt><big>class <u>JSONTypeError</u>: object.Error;
+</big></dt>
+<dd>Thrown when attempting an operation on a JSON object.<br><br>
+
+</dd>
+<dt><big>class <u>JSONException</u>: object.Exception;
+</big></dt>
+<dd>Thrown when parsing goes wrong.<br><br>
+
+</dd>
+<dt><big>abstract class <u>JSONType</u>;
+</big></dt>
+<dd>This is the interface implemented by all classes that represent JSON objects.<br><br>
+
+<dl><dt><big>JSONObject <u>toJSONObject</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONObject
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONArray <u>toJSONArray</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONArray
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONString <u>toJSONString</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONString
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONBoolean <u>toJSONBoolean</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONBoolean
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONNumber <u>toJSONNumber</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONNumber
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONNull <u>toJSONNull</u>();
+</big></dt>
+<dd>Convenience function for casting to JSONNull
+<br><br>
+<b>Returns:</b><br>
+The casted object or <b>null</b> if the cast fails<br><br>
+
+</dd>
+<dt><big>JSONType <u>opIndex</u>(string <i>key</i>);
+</big></dt>
+<dd>Associative array index function for objects describing associative array-like attributes.
+<br><br>
+<b>Returns:</b><br>
+The chosen index or a <b>null</b> reference if the index does not exist.<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref string, ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Allow foreach over the object with string key and ref value.<br><br>
+
+</dd>
+<dt><big>JSONType <u>opIndex</u>(int <i>key</i>);
+</big></dt>
+<dd>Array index function for objects describing array-like attributes.
+<br><br>
+<b>Returns:</b><br>
+The chosen index or a <b>null</b> reference if the index does not exist.<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref ulong, ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Allow foreach over the object with integer key and ref value.<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Convenience function for iteration that apply to both AA and array type operations with ref value<br><br>
+
+</dd>
+<dt><big>JSONType* <u>opIn_r</u>(string <i>key</i>);
+</big></dt>
+<dd>Allow "in" operator to work as expected for object types without an explicit cast<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONObject</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONObject</u> represents a single JSON object node and has methods for
+ adding children. All methods that make changes modify this
+ <u>JSONObject</u> rather than making a copy, unless otherwise noted. Many methods
+ return a self reference to allow cascaded calls.<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>Nothing to see here except for the boring constructor, move along.<br><br>
+
+</dd>
+<dt><big>void <u>opIndexAssign</u>(JSONType <i>type</i>, string <i>key</i>);
+</big></dt>
+<dd>Operator overload for setting keys in the AA.<br><br>
+
+</dd>
+<dt><big>JSONType <u>opIndex</u>(string <i>key</i>);
+</big></dt>
+<dd>Operator overload for accessing values already in the AA.
+<br><br>
+<b>Returns:</b><br>
+The child node if it exists, otherwise <b>null</b>.<br><br>
+
+</dd>
+<dt><big>ulong <u>length</u>();
+</big></dt>
+<dd>Allow the user to get the number of elements in this object
+<br><br>
+<b>Returns:</b><br>
+The number of child nodes contained within this JSONObject<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Operator overload for foreach iteration through the object with values only and allow modification of the reference<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref string, ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Operator overload for foreach iteration through the object with key and value and allow modification of the reference<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONObject to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONObject to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONObject out of a string<br><br>
+
+</dd>
+<dt><big>JSONType* <u>opIn_r</u>(string <i>key</i>);
+</big></dt>
+<dd>Allow "in" operator to work as expected for object types without an explicit cast<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONArray</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONArray</u> represents a single JSON array, capable of being heterogenous<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>Nothing to see here, move along.<br><br>
+
+</dd>
+<dt><big>void <u>opCatAssign</u>(JSONType <i>child</i>);
+</big></dt>
+<dd>Operator overload to allow addition of children<br><br>
+
+</dd>
+<dt><big>JSONType <u>opIndex</u>(int <i>key</i>);
+</big></dt>
+<dd>Operator overload to allow access of children
+<br><br>
+<b>Returns:</b><br>
+The child node if it exists, otherwise <b>null</b>.<br><br>
+
+</dd>
+<dt><big>ulong <u>length</u>();
+</big></dt>
+<dd>Allow the user to get the number of elements in this object
+<br><br>
+<b>Returns:</b><br>
+The number of child nodes contained within this JSONObject<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Operator overload for foreach iteration through the array with values only and allow modification of the reference<br><br>
+
+</dd>
+<dt><big>int <u>opApply</u>(int delegate(ref ulong, ref JSONType) <i>dg</i>);
+</big></dt>
+<dd>Operator overload for foreach iteration through the array with key and value and allow modification of the reference<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONArray to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONArray to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONArray out of a string<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONString</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONString</u> represents a JSON string. Internal representation is escaped for faster parsing and JSON generation.<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>The boring default constructor.<br><br>
+
+</dd>
+<dt><big>this(string <i>data</i>);
+</big></dt>
+<dd>The ever so slightly more interesting initializing constructor.<br><br>
+
+</dd>
+<dt><big>void <u>set</u>(string <i>data</i>);
+</big></dt>
+<dd>Allow the <i>data</i> to be <u>set</u> so the object can be reused.<br><br>
+
+</dd>
+<dt><big>string <u>get</u>();
+</big></dt>
+<dd>Allow the data to be retreived.<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONString to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONString to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONArray out of a string and eats characters as it goes, hence the ref string parameter.<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONBoolean</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONBoolean</u> represents a JSON boolean value.<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>The boring constructor, again.<br><br>
+
+</dd>
+<dt><big>this(bool <i>data</i>);
+</big></dt>
+<dd>Only a bit of input for this constructor.<br><br>
+
+</dd>
+<dt><big>void <u>set</u>(bool <i>data</i>);
+</big></dt>
+<dd>Allow setting of the hidden bit.<br><br>
+
+</dd>
+<dt><big>bool <u>get</u>();
+</big></dt>
+<dd>Allow the bit to be retreived.<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONBoolean to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONBoolean to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this object and it's contents.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONBoolean out of a string and eats characters as it goes, hence the ref string parameter.<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONNull</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONNull</u> represents a JSON <b>null</b> value.<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>You're forced to use the boring constructor here.<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONNull to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+"<b>null</b>". Always. Forever.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONNull to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+"<b>null</b>". Always. Forever.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONNull out of a string. Really, it just rips "<b>null</b>" off the beginning of the string and eats whitespace.<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>class <u>JSONNumber</u>: dcaflib.text.json.JSONType;
+</big></dt>
+<dd><u>JSONNumber</u> represents any JSON numeric value.<br><br>
+
+<dl><dt><big>this();
+</big></dt>
+<dd>Another boring constructor...<br><br>
+
+</dd>
+<dt><big>this(real <i>data</i>);
+</big></dt>
+<dd>...and its slightly less boring sibling.<br><br>
+
+</dd>
+<dt><big>void <u>set</u>(real <i>data</i>);
+</big></dt>
+<dd>Allow setting of the hidden number.<br><br>
+
+</dd>
+<dt><big>real <u>get</u>();
+</big></dt>
+<dd>Allow the number to be retreived.<br><br>
+
+</dd>
+<dt><big>string <u>toString</u>();
+</big></dt>
+<dd>A method to convert this JSONNumber to a user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this number.<br><br>
+
+</dd>
+<dt><big>string <u>toPrettyString</u>(string <i>indent</i> = null);
+</big></dt>
+<dd>A method to convert this JSONNumber to a formatted, user-readable format.
+<br><br>
+<b>Returns:</b><br>
+A JSON string representing this number.<br><br>
+
+</dd>
+<dt><big>void <u>parse</u>(ref string <i>source</i>);
+</big></dt>
+<dd>This function parses a JSONNumber out of a string and eats characters as it goes, hence the ref string parameter.<br><br>
+
+</dd>
+</dl>
+</dd>
+<dt><big>string <u>JSONEncode</u>(string <i>src</i>);
+</big></dt>
+<dd>Perform JSON escapes on a string
+<br><br>
+<b>Returns:</b><br>
+A JSON encoded string<br><br>
+
+</dd>
+<dt><big>string <u>JSONDecode</u>(string <i>src</i>);
+</big></dt>
+<dd>Unescape a JSON string
+<br><br>
+<b>Returns:</b><br>
+A decoded string.<br><br>
+
+</dd>
+<dt><big>string <u>quickUTF8</u>(dchar <i>dachar</i>);
+</big></dt>
+<dd>This probably needs documentation. It looks like it converts a dchar to the necessary length string of chars.<br><br>
+
+</dd>
+</dl>
+
+ <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. (c) 2009 William K. Moore, III
+ (nyphbl8d (at) gmail (dot) com, opticron on freenode)
+</small>
+ </body></html>
View
93 docs/lookahead.html
@@ -0,0 +1,93 @@
+<html><head>
+ <META http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>dcaflib.containers.lookahead</title>
+ </head><body>
+ <h1>dcaflib.containers.lookahead</h1>
+ <!-- Generated by Ddoc from containers/lookahead.d -->
+<u>lookahead</u>.d contains the Lookahead class, which operates on ranges but is
+ optimized for slices.
+<br><br>
+<b>Authors:</b><br>
+Nathan M. Swan, aka carlor
+<br><br>
+<b>License:</b><br>
+Boost Software License - Version 1.0
+<br><br>
+
+ Permission is hereby granted, free of charge, to any person or organization
+ obtaining a copy of the software and accompanying documentation covered by
+ this license (the "Software") to use, reproduce, display, distribute,
+ execute, and transmit the Software, and to prepare derivative works of the
+ Software, and to permit third-parties to whom the Software is furnished to
+ do so, all subject to the following:
+<br><br>
+
+ The copyright notices in the Software and this entire statement, including
+ the above license grant, this restriction and the following disclaimer,
+ must be included in all copies of the Software, in whole or in part, and
+ all derivative works of the Software, unless such copies or derivative
+ works are solely in the form of machine-executable object code generated by
+ a source language processor.
+<br><br>
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.<br><br>
+
+<dl><dt><big>interface <u>Lookahead</u>(Param);
+</big></dt>
+<dd> is an infinite lookahead of, if Param is a range, a
+ Param, else an array of Params.<br><br>
+
+<dl><dt><big>void <u>consume</u>(size_t <i>howmuch</i> = 1);
+</big></dt>
+<dd>Consumes <i>howmuch</i> of the buffer.<br><br>
+
+</dd>
+<dt><big>T <u>get</u>(size_t <i>howmuch</i> = 0);
+</big></dt>
+<dd>Loads in the buffer and gets <i>howmuch</i> of it, or the sentinel. <br><br>
+
+</dd>
+<dt><big>T <u>front</u>();
+</big></dt>
+<dd>same as get(0)
+ Implements a range.<br><br>
+
+</dd>
+<dt><big>bool <u>empty</u>();
+</big></dt>
+<dd>whether the looked range is consumed<br><br>
+
+</dd>
+<dt><big>void <u>popFront</u>();
+</big></dt>
+<dd>same as consume(1)<br><br>
+
+</dd>
+<dt><big>Lookahead!(Param) <u>save</u>();
+</big></dt>
+<dd>clones the lookahead<br><br>
+
+</dd>
+<dt><big>T <u>opIndex</u>(size_t <i>n</i>);
+</big></dt>
+<dd>same as get(<i>n</i>)<br><br>
+
+</dd>
+<dt><big>Lookahead!(Param) <u>create</u>(R <i>range</i>, T <i>sentinel</i> = T.init);
+</big></dt>
+<dd>Creates a new lookahead from the <i>range</i> that gives <i>sentinel</i> on empty.<br><br>
+
+</dd>
+</dl>
+</dd>
+</dl>
+
+ <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. (C) 2012 Nathan M. Swan
+</small>
+ </body></html>
View
61 docs/terminal.html
@@ -0,0 +1,61 @@
+<html><head>
+ <META http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>dcaflib.ui.terminal</title>
+ </head><body>
+ <h1>dcaflib.ui.terminal</h1>
+ <!-- Generated by Ddoc from ui/terminal.d -->
+<u>terminal</u>.d contains functions for styling the <u>terminal</u>. Currently, only
+ foreground text color on Posix is implemented, though more is planned.
+<br><br>
+<b>Author:</b><br>
+Nathan M. Swan, aka carlor
+<br><br>
+<b>License:</b><br>
+Boost Software License - Version 1.0
+<br><br>
+
+ Permission is hereby granted, free of charge, to any person or organization
+ obtaining a copy of the software and accompanying documentation covered by
+ this license (the "Software") to use, reproduce, display, distribute,
+ execute, and transmit the Software, and to prepare derivative works of the
+ Software, and to permit third-parties to whom the Software is furnished to
+ do so, all subject to the following:
+<br><br>
+
+ The copyright notices in the Software and this entire statement, including
+ the above license grant, this restriction and the following disclaimer,
+ must be included in all copies of the Software, in whole or in part, and
+ all derivative works of the Software, unless such copies or derivative
+ works are solely in the form of machine-executable object code generated by
+ a source language processor.
+<br><br>
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.<br><br>
+
+<dl><dt><big>@property TermColor <u>fgColor</u>();
+</big></dt>
+<dd>Gets the foreground color.<br><br>
+
+</dd>
+<dt><big>@property void <u>fgColor</u>(TermColor <i>tc</i>);
+</big></dt>
+<dd>Sets the foreground color.<br><br>
+
+</dd>
+<dt><big>enum <u>TermColor</u>;
+</big></dt>
+<dd>Colors supported by the terminals. They are not guaranteed to be the same
+ on all platforms, but they should be similar.<br><br>
+
+</dd>
+</dl>
+
+ <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. (C) 2012 Nathan M. Swan
+</small>
+ </body></html>
View
2  text/json.d
@@ -1,7 +1,7 @@
/**
* json.d contains functions and classes for reading, parsing, and writing JSON
* documents. It is adapted from LibDJSON:
- * https://256.makerslocal.org/wiki/index.php/Libdjson
+ * $(LINK https://256.makerslocal.org/wiki/index.php/Libdjson)
*
* Copyright:
* (c) 2009 William K. Moore, III
View
111 ui/terminal.d
@@ -0,0 +1,111 @@
+/++
+ + terminal.d contains functions for styling the terminal. Currently, only
+ + foreground text color on Posix is implemented, though more is planned.
+ +
+ + Copyright: (C) 2012 Nathan M. Swan
+ + Author: Nathan M. Swan, aka carlor
+ + License: Boost Software License - Version 1.0
+ +
+ + Permission is hereby granted, free of charge, to any person or organization
+ + obtaining a copy of the software and accompanying documentation covered by
+ + this license (the "Software") to use, reproduce, display, distribute,
+ + execute, and transmit the Software, and to prepare derivative works of the
+ + Software, and to permit third-parties to whom the Software is furnished to
+ + do so, all subject to the following:
+ +
+ + The copyright notices in the Software and this entire statement, including
+ + the above license grant, this restriction and the following disclaimer,
+ + must be included in all copies of the Software, in whole or in part, and
+ + all derivative works of the Software, unless such copies or derivative
+ + works are solely in the form of machine-executable object code generated by
+ + a source language processor.
+ +
+ + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ + FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ + SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ + FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ + DEALINGS IN THE SOFTWARE.
+ +/
+
+
+module dcaflib.ui.terminal;
+
+version (Posix) version = tbash;
+
+version (tbash) {
+ import std.stdio;
+} else {
+ static assert(0, "dcaflib.ui.terminal is unsupported on your system");
+}
+
+
+version (unittest) import std.stdio;
+
+
+public:
+/// Gets the foreground color.
+@property TermColor fgColor() {
+ return fg;
+}
+
+/// Sets the foreground color.
+@property void fgColor(TermColor tc) {
+ fg = tc;
+ update();
+}
+
+/// Colors supported by the terminals. They are not guaranteed to be the same
+/// on all platforms, but they should be similar.
+enum TermColor {
+ DEFAULT,
+ BLUE,
+ CYAN,
+ GREEN,
+ YELLOW,
+ RED,
+ PURPLE,
+ BLACK,
+ WHITE,
+}
+
+private:
+
+static ~this() {
+ fgColor = TermColor.DEFAULT;
+}
+
+void update() {
+ version (tbash) {
+ writef("\033[0m");
+ if (fg != TermColor.DEFAULT) {
+ writef("\033[3%dm", colorCode(fg));
+ }
+ }
+}
+
+version (tbash) uint colorCode(TermColor tc) {
+ switch (tc) {
+ case TermColor.BLUE: return 4;
+ case TermColor.CYAN: return 6;
+ case TermColor.GREEN: return 2;
+ case TermColor.YELLOW: return 3;
+ case TermColor.RED: return 1;
+ case TermColor.PURPLE: return 5;
+ case TermColor.BLACK: return 0;
+ case TermColor.WHITE: return 7;
+ default:
+ assert(0, "unknown color code");
+ }
+}
+
+TermColor fg;
+
+unittest {
+ fgColor = TermColor.RED;
+ writeln("this is red!");
+ fgColor = TermColor.BLUE;
+ writeln("this is blue!");
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.