[Class] Console - Standardized Console GUI with Methods
Posted: 13 Feb 2014, 15:29
by AfterLemon
Class: Console - Standardized Console GUI with Methods
by: tidbit, AfterLemon
Version 1.8 | Tue March 11, 2014 [Downloads][Screenshot]
Thank you for your interest! Good ol' tidbit and I worked on this with ease of use, seamless handling, and robust ability in mind. We hope you like it.
As always, we're both here, and on the IRC channel (irc.freenode.net #ahk & #ahkscript) to help.
Now on to the details:
This class is meant to simplify debugging for scripts from simple text handling, to outputting and logging data & arrays.
There's a lot here, so jump in and test it out using our demo scripts below, or write your own setup and tell us what you think we need to add!
Name: [Class] Console
Version: 1.8 (Tue March 11, 2014)
Created: Tue February 11, 2014
Authors: AfterLemon tidbit
GitHub: https://github.com/AfterLemon/Class_Console
AutoHotkey: http://www.autohotkey.com/board/topic/101881-class-console-standardized-console-gui-with-methods/
AHKScript: http://ahkscript.org/boards/viewtopic.php?f=6&t=2116&p=14026
Functions Available:
Class_Console to build the console object - use this in place of Console:=new console()
Desc_Console to view the description of the class
Methods_Console to view the documentation for the methods
Class:
Class_Console(Name,x,y,w,h [,Timestamp,HTML,Font,Fontsize])
This creates a new console object with the name of "Name".
All the below stuff will use the console defined above.
You may use any name you like in your code.
Methods:
aaa.append([text,delim,justify,pad,colsep])
Add text to the end of the console without a timestamp.
aaa.catch([line,var,value])
Detect when a variable is a certain value or a certain line of code is executed.
aaa.clear()
Remove all the text on the console.
aaa.close()
Close the console but don't destroy it. Basically you Hide it.
aaa.color([c])
Sets text color for following lines. Default is white.
Specify "list" to see the color table.
aaa.cmd(command [,breakOn,AppendConsole])
Run (and return) a command-prompt command and get the input line-by-line.
aaa.cmdWait(command [,AppendConsole])
Run (and return) a command-prompt command and wait for it to fully finish.
aaa.destroy()
Destroy the console, it can not be shown until recreated.
aaa.debug(debugType)
Show AHK's debug info: KeyHistory, ListVars (Vars), ListLines (Lines), and ListHotkeys (Hotkeys).
aaa.eval(In [,Append])
Evaluate expression with numbers,+ # - / and *.
aaa.log([text,delim,justify,pad,colsep])
Same as append, but with a timestamp.
aaa.prepend([text,delim,justify,pad,colsep])
Same as append, but adds the text to the TOP (line 1) of the console.
aaa.pull()
Get the current console text.
aaa.save([FileName,Overwrite (flag)])
Save the console to a file.
aaa.show(GuiName)
Show a closed or recently created console.
aaa.timeSinceLastCall([id,reset])
Get the amount of time (in MS) since the last time this function was called.
aaa.update(debugType)
This is similar to doing a CLEAR and then LOG(DEBUG()).
Color Table
.-----------------.
| Name | Color |
| ----------------|
| yellow | yellow |
| orange | orange |
| white | white | <- default
| red | red |
| blue | cyan |
| lime | lime |
| green | green |
| gray | gray |
| black | black |
'-----------------'
ConsoleBar_Commands
[!ExitApp]
Desc: Exits entire script.
Syntax: ExitApp
[*Catch]
Desc: Detect when a variable is a certain value,
OR Detect when a line in ListLines exists.
Syntax: catch var varName Value command
Syntax: catch var line DebugLineNum Command
Example: catch var d 4 prepend %d%
Example: catch line 11 log line 11 was accessed!
[*Settimer]
Desc: Run a
[command] every N milliseconds (1000=1 second, 5000=5 seconds, etc).
Syntax: SetTimer N command
Example: SetTimer 1000 var Banana
[?About]
Desc: Show information about this Console and its Creators.
Syntax: About
[Append]
Desc: Add text to the end of the console.
You may use variables such as %varName%.
Syntax: Append Text
Example: Append I'm at the end of the log! For now...
[Clear]
Desc: Clear all text in the console.
Syntax: Clear
[Close]
Desc: Close (or hide) the console. It can be re-shown.
Syntax: Close
[Cmd]
Desc: Run cmd.exe commands here. You can ping, run programs, whatever you want. Output will go to the console. This gets stuff line-by-line.
Syntax: cmd cmd.exe stuff
Example: Cmd ipconfig
[CmdWait]
Desc: Run cmd.exe commands here. You can ping, run programs, whatever you want. Output will go to the console. This waits for the whole command to finish before printing to the console.
Syntax: CmdWait cmd.exe stuff
Example: CmdWait ipconfig
[Color]
Desc: Apply a color
[N] to all below lines.
Available colors: Yellow, Orange, White, Red, Blue, Lime, Green, Gray, Black.
Or type 'color list' for a visual list of all the colors.
Syntax: Color N|List
Example: color blue
Example: color list
[Debug]
Desc: Get various AHK debugging info such as Last Lines.
UNIT should be one of the following: Hotkeys, KeyHistory, Lines or Vars
Syntax: debug UNIT
Example: Debug Vars
[Destroy]
Desc: Destroy the console. It can NOT be re-shown.
Syntax: Destroy
Example: Destroy
[Log]
Desc: Add text to the end of the console with a formatted timestamp above the new text.
You may use variables such as %varName%.
Syntax: Log Text
Example: Log Some new data
[Operators]
Desc: Create and/or do math or do other unforsaken things to variables, such as append text. You do not need to use quotes around text.
Available Operators: := .= += -= *= /= //= &= ^= |=
Syntax: var+=5
Example: SomeVar.=New text at the end.
[Prepend]
Desc: Adds text to the TOP of the console, not the bottom.
You may use variables such as %varName%.
Syntax: Prepend Text
Example: Prepend I'M ON TOP OF THE WOR... CONSOLE!
[Pull]
Desc: Pulls data from console window (line/lines specifies the line numbers) and saves it in a variable (or the clipboard).
Syntax: Pull
[lines|line First-Last|N] VarName|Clipboard
Example: Pull banana
OR Pull lines 1-10 banana
OR Pull line 3 banana
[Run]
Desc: Runs a label within the script.
Syntax: Run Label
Example: Run BananaLabel -> BananaLabel: ....
[Save]
Desc: Save the console text to the specified file.
Syntax: Save Filepath
Example: Save C:\blah\log.txt
[Show]
Desc: Show a specified closed (not destroyed) console or reshow the current one.
Syntax: Show NAME
Example: Show Variable
[TimeSinceLastCall]
Desc: ID and Reset are optional. Appends time in milliseconds since the last time this command was run.
Syntax: TimeSinceLastCall ID Reset
Example: TimeSinceLastCall 1
[Update]
Desc: Uses last Debug UNIT, clearing the log and re-running the debug.
Syntax: Update
Example: Debug vars --> SetTimer 3000 Update
[Var]
Desc: Print the value of a variable to the console. no %'s needed.
-1 = Prepend, 1 = Log. Default is Append.
Syntax: Var VariableName (-1,0,1)
Example: Var Banana
----------------
<><><><><><><>
<> example: <>
<><><><><><><>
; create the console with a long time/date timestamp.
; it can now be called using "a." followed by the above method list.
a.new console("title", 100, 100, 500, 300, 1)
a.show() ; show the console we just made
a.log("Hello!") ; Print your message to it with a timestamp.
a.append("console class!") ; Add another message but with no timestamp.
sleep, 2000 ; Wait two seconds before we clear it.
a.clear() ; Clear (empty the view) console.
a.cmdWait("ipconfig") ; Show the 'ipconfig' data in your console.
sleep, 3000 ; Wait three second.
a.destroy() ; Permenantly destroy the "a." console. It'll need to be recreated for further use.
... Please view the demo files for other examples.
Demos
- removed - Please see the Download link at the top (Github has the demos).
Re: Class: Console - Standardized Console GUI with Methods
Posted: 14 Feb 2014, 10:31
by tidbit
Great release I would also like to thank Lexikos as the PrintArray function is based on his ExploreObj() (but pretty much unnoticeable now).
Re: Class: Console - Standardized Console GUI with Methods
Posted: 14 Feb 2014, 22:29
by MasterFocus
Looks promising! I'll definitely keep an eye on this. Thanks guys!
Re: Class: Console - Standardized Console GUI with Methods
Posted: 15 Feb 2014, 11:20
by tidbit
You're welcome
small update 1.1
when using console.log(OBJECT or ARRAY), any keys with strings are now quoted.
; ------------------------------------------------------
; ------------- RETRIEVE CONSOLE'S OUTPUTS -------------
; ------------------------------------------------------
;http://msdn.microsoft.com/en-us/library/cbxxzwb5%28v=VS.85%29.aspx
;http://technet.microsoft.com/en-us/library/ee156605.aspx
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec("ipconfig.exe")
While !objExec.Status ;wait until ipconfig.exe starts
Sleep 100
strLine := objExec.StdOut.ReadAll() ;read the output at once
msgbox % strLine
; ping
objExec := objShell.Exec("cmd /c ping -n 3 -w 1000 www.google.com")
While !objExec.StdOut.AtEndOfStream ;read the output line by line
if InStr(objExec.StdOut.ReadLine(), "Reply") {
Msgbox Reply received.
Break
}
The endless API function calls I had to make back in vanilla to return the consoles stdout buffer to a var,
now reduced to a few lines, as I said to tidbit, its almost not fair, but amazing that it can be done this way.
If you could add a method for this it would be greatly appreciated.
Re: Class: Console - Standardized Console GUI with Methods
Posted: 22 Feb 2014, 18:15
by AfterLemon
Minor Update
STDout to the console is now available.
TWO new methods now support STDout:
StdOutFull -- Wait until CMD stdout is finished and append it all to the console
StdOutStream -- Stream the CMD stdout appended to the console
objExec:=a.objShell.Exec("ipconfig.exe")
While !objExec.StdOut.AtEndOfStream
a.append(objExec.StdOut.ReadLine())
Re: Class: Console - Standardized Console GUI with Methods
Posted: 22 Feb 2014, 21:09
by TLM
awesome
tidbit and I ( mostly tidbit ) tried to figure out how to get the cmd to exec() without the window.
He ended up using the `shell hook event` approach to hide it, it still flashes but seems to work ok.
Still beats a million dllcalls()
Re: Class: Console - Standardized Console GUI with Methods
Posted: 23 Feb 2014, 10:19
by tidbit
aww man. you guys released it before me! I was going to fix some bugs you made before releasing, afterlemon
Mine also has a Break feature. I'll show it to you over irc before merging.
I also added a new function and redid the docs/description page a little.
Re: Class: Console - Standardized Console GUI with Methods
Posted: 24 Feb 2014, 01:27
by hd0202
I think here is a problem in class source lines 9 and 13:
TimeFormat should be FormatTime
Hubert
Re: Class: Console - Standardized Console GUI with Methods
Posted: 24 Feb 2014, 10:20
by tidbit
hd0202:
that is the bug i fixed mentioned above
there were also 2 or 3 other bugs related to timestamps. I have fixed those. Just waiting for afterlemon to show his face on irc. If he doesn't today I'll just post my fixes and additions.
edit:
Update to 1.3
3 new functions:
cmd()
cmdWait()
timeSinceLastCall()
Bug fixes:
timestamp issues
issues with displaying arrays properly (st_printarr())
misc:
generated console names (if the name was left blank) now uses A_Now instead of a random number.
updated the docs a bit.
Re: Class: Console - Standardized Console GUI with Methods
Posted: 26 Feb 2014, 16:12
by ahk7
Nice class. But I prefer mine with a splash of color - I'm just messing around with it a bit by replacing the edit control with a listview, this makes it possible to use "line numbers" and color text for certain types of data using https://github.com/AHK-just-me/Class_LV_Colors
Not sure of LVs are the way to go, a scintilla control might do it OR a simple html control which would allow tables, bullet lists, colors ...
One thing I'd also like to see is a resizable window but haven't worked on that yet.
Re: Class: Console - Standardized Console GUI with Methods
Posted: 26 Feb 2014, 16:36
by AfterLemon
I like the idea of having it handle in a way that looks a little bit nicer, but the sacrifices you're making are too much in my opinion.
Take a look at the overall size of the project. Nearly 600 lines, and many of the methods must still be extended. As well things like Console.Pull() will fail and or cause unreliability due to their slow looping data dump.
LOVE the idea, that's for sure.
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 01 Mar 2014, 14:43
by tidbit
Updated to 1.5! - Major release
-----
A new Command Bar has been added!
The TV parameter/effect has been removed.
many updates and bug fixes.
.Eval() (a simple, not a full featured eval)
many command bar commands.
other stuff.
Woohoo!
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 06 Mar 2014, 18:05
by tidbit
1.7
now uses an html (mshtml) control
line numbers
colors
themeable (html/css)
catch
color
other stuff
bug fixes
more fixes
enjoy!
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 06 Mar 2014, 18:40
by cyruz
Hi guys, thanks for the nice work. Just a request... This class, most probably, will be put in the Lib folder, so it would be nice to have description and documentation inside the class file itself. Of course anyone can do it by himself, so no real need...
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 06 Mar 2014, 19:38
by tidbit
I had that originally, but that adds another ~150 lines.
Until AHK has support for classes in the lib (or does it already? maybe it has a different name structure?), I don't see it being useful. Currently I just copy/paste it at the bottom of my script. since you can't name the file Console.ahk and AHK recognizes it like it does functions.
I guess there is always the use of #include, but that has issues. for some users (like me) simply doing "#include console.ahk" gives an error. I need an absolute path. I find it simpler to just copy/paste instead of fetch the full path every time.
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 06 Mar 2014, 20:23
by joedf
very interesting
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 07 Mar 2014, 10:08
by cyruz
tidbit wrote:I had that originally, but that adds another ~150 lines.
Until AHK has support for classes in the lib (or does it already? maybe it has a different name structure?), I don't see it being useful. Currently I just copy/paste it at the bottom of my script. since you can't name the file Console.ahk and AHK recognizes it like it does functions.
I guess there is always the use of #include, but that has issues. for some users (like me) simply doing "#include console.ahk" gives an error. I need an absolute path. I find it simpler to just copy/paste instead of fetch the full path every time.
I'm using the "#Include <Console>" approach, I find it very convenient.
Now that joedf is here and because I didn't dig deeper in the code, may I ask one of you what are the main differences between Console and LibCon?
Re: [Class] Console - Standardized Console GUI with Methods
Posted: 07 Mar 2014, 10:36
by AfterLemon
(Not much experience with LibCon, it fails to start due to VarSetCapacity not implemented)
From a not-so-extensive look-over of LibCon, I see that while it has many of the features you would expect a console to have, it is not necessarily built for debugging.
Class_Console is built with the debugging of issues in mind. .Catch() allows you to monitor execution automatically (this feature is something I've wanted since starting AHK 5 years ago), .Debug() allows you to view the script logs, and to the extent possible, everything is self-contained, as small and efficient as possible, and dedicated to finding and fixing the problems in your other scripts.
I'd like to see this as an #Include simply for the efficiency of fixing any script any time. We'll see what we can do.