wizkit
v1.8.3
Published
The functional programming programming utility and terminal logger.
Downloads
63
Maintainers
Readme
A functional programming utility kit with a robust logger for the terminal and browser.
Author: Robert Edward Steckroth II
var up = new Wizkit("Example 1").set_option({"debug": "verbose"})
up.sp("The first instance of Wizkit will store the default settings for the others.")
.line("Here are the configurable settings:", up.mutable_options).log()
up.log("Calling log with multiple arguments", "will use the", "last known",
"separator (a space is the default).")
var cont = up.line("Adding lines is easy now").log("These use the last known", "separator (a line now)")
cont.log("We can continue form any point including..", "..log() call.")
// A new copy of the logger is created every time a logging command is called form the base class.
var log_1 = up.sp("Instance one of the logger.")
var log_2 = up.sp("Instance two of the logger.")
log_1.log()
log_2.log()
log_1.log("This is called again after the first time sense the original text is strored in the logger instance created by the parent class.")
log_1.clear().log("The logger can have its text cleared with the clear() command.")
var logger = up.sp("Some text for example sake.")
up.log("Wizkit also accepts itself as a logging potion other than text", logger)
up.log("The text() method will return a plain string instead of pretty logging ->", logger.text())
up.log("The contains_text property will tell us if the logger is holding anything (which can be cleared)",
up.sp("Some text").contains_text, up.sp("Some text").clear().contains_text)
up.line("We can also specify objects").line(complex_object).log()
up.tab("the initial separator is ignored", "like the tab at the", "beginning of this line").log()
var complex_object = {"Test Object": [1,2,3,4,"Test String", {"obj in array": {test_array: ["deep", false, 234]}}]}
up.line("We can also specify objects").line(complex_object).log()
up.indentation_string = ">>"
up.log("..and change the the indentation_string option").log(complex_object)
up.compress_level = 4
up.set_option({indentation_string: "-"})
up.line(" "," ").sp("..and compress the object").log("to level", up.compress_level, complex_object)
up.line().line().sp("..and compress the object").set_option({compress_level: 3}).log("to level", 3, complex_object)
up.line(" "," ").sp("..and compress the object").set_option({compress_level: 2}).log("to level", 2, complex_object)
up.line(" "," ").sp("..and compress the object").set_option({compress_level: 1}).log("to level", 1, complex_object)
var example_2 = up.new_copy("Example 2")
example_2.log("Example two was created with new copy and has the exact same options as example 1 but is uniquely threaded.",
example_2.mutable_options)
var example_3 = new Wizkit(example_2, "Example 3")
example_2.log("Example three was created with the Wizkit constructor and passed a title as a string.",
"It has the exact same options as example 2 but is uniquely threaded as well.", example_2.mutable_options)
var t_f = function(opt, cb, err) {
}
var my_func = function(opt, cb, err) {
cb = up.cb(cb, this)
err = up.error_cb(err, this)
this.more = "no data yet.."
if ( opt ) cb(up.sp("Calling success callback with prototype").line(this).line("----------------"))
else err(up.sp("Calling error callback with prototype").line(this).line("----------------"))
}
var new_proto = { "more": "data" }
var cb_a = function() {
this.Robert = "Bob"
console.log("msg sent to Wizkit error callback: "+this.msg)
up.sp("Prototype of callback -> ").line(this).log()
}
cb_a.prototype = {"cb_a permanent_data": "here"}
var cb_b = function() {
this.Robert = "Bob"
console.log("msg sent to Wizkit error callback: "+this.msg)
up.sp("Prototype of callback -> ").line(this).log()
}
cb_b.prototype = {"cb_b permanent_data": "here"}
var test_callbacks = function() {
cb_a = up.error_cb(cb_a, "msg for end user display") // msgs do no regard the debug state and are always availible
cb_a("An internally generated error msg")
cb_a = up.error_cb(cb_a, new_proto, "Prototypes can not be changed once they are set to a function.") // msgs do no regard the debug state and are always availible
cb_a("An internally generated error msg with the same prototype initially assigned")
up.error_cb(cb_a, new_proto, "A different msg for end user display")("An different internally generated error msg")
cb_b = up.error_cb(cb_b, {"Custom_prototype": true}, up.sp("Wizkit logger is usefull here as well. This log will be sent regardless of the debug state."))
cb_b()
up.error_cb({"test": ["test data"], "up": up}, function() {
this.up.sp("We got Wizkit from the prototype passed in:").sp(this.test).log()
})()
up.error_cb()("Simple error reporting through Wizkit")
}
var test_printing = function() {
up.sp("cool").sp(null).sp(false).sp(y).sp("cool").sp(null).sp(false).sp(y).log("a"*3)
var y
up.log_app_name = "" // Turn off auto app printing
var output = up.pass()
output.set_option({use_color: false}).add("Starting empty").add().line().line().line()
//assert(output.toString() === "Starting empty\n\n\n")
up.tab("This starts at the beggining of line because the first separater is ignored").log()
up.line("good").sp("deal").log()
up.sp("one blank line separates").line().line("these two lines").log()
up.sp().sp("one space before this").log()
up.sp().sp().sp("two spaces before this").log()
// up.line().set_option({use_color: false}).line().line().line(new Error("Wizkit will auto-print Errors"))
// .line().set_option({use_color: true}).line("In color now!").log(new Error("Wizkit will auto-print Errors"))
up.tab("All separators are ignored when the first separator command is called (except lines)").log()
up.line("Lines will newline even on the first command call").log()
up.line().log()
up.sp("Clear all of the data after this msg and log the last string").clear().line().tab("This is not printed").clear().tab("last chain after clear here").log()
up.always().sp("Ignore the debugging state with the always command.").log()
up.always().sp("Ignore the debugging state with the always command.").log()
console.log(up.always().sp("Ignore the debugging state with the always command.").text())
up.log_app_name = "Wizkit testing utility" // Turn on auto app printing
up.log(function() {
// print this function
this.robert = "bob"
})
}
function test_debug_state() {
up.log_app_name = "Testing debug switches"
up.debug = "verbose"
up.sp("Debug state is set to", up.debug).log()
up.error_cb()(up.always().sp("an error msg"))
up.debug = true
up.sp("Debug state is set to", up.debug).log()
up.error_cb()("another an error msg")
up.debug = false
up.sp("Debug state is set to").sp(up.debug).log()
up.error_cb()(up.always().sp("yet another error msg"))
}
test_printing()
test_callbacks()
test_debug_state()
Works in gecko based browsers