Hack is a lightweight notebook and/or code development addon.
Hack makes it easy to manage a large collection of notes/scripts and share them with other Hack users. Pages containing Lua code can be run and/or flagged to auto-run on startup; they can call other pages, passing arguments and receiving return values. This lets Hack serve as an in-game file system for Lua scripts.
OPTIONAL:
Hack includes several example pages. They are easily deleted from within Hack, or you can prevent them from ever being loaded by deleting HackExamples.lua from the Hack folder.
Hack itself is lightweight (<60KB), but it includes a library for highlighting/indenting Lua code (FAIAP) which will add some additional memory usage and garbage generation. It's not a big deal, but if you just use Hack as a notebook and never edit Lua code, feel free to delete Indent.lua from the Hack directory.
IMPORT:
Hack's example pages include scripts to import pages from Tinypad, Nefpad, WowLua, and LuaSlinger. LuaSlinger supports triggering pages by events, and the importer shows how easily you can wire up the same functionality in Hack.
If you have another notepad addon you want to pull pages from, lemme know.
USAGE:
/hack -- toggle Hack UI /hack <hack name> -- run a Hack page by name
The UI is mostly self-explanatory (mouse over buttons to see what they do), but a few things deserve special mention:
1. To run the current page as Lua code, click the 'play' button at the top of edit window (this one) or hit SHIFT+TAB from the editor.
2. To make a page run automatically when Hack loads, click the 'play' button next to it's name in the list window. This makes Hack useful for little tweaks that don't warrant a full-blown addon. For instance, I hate the mail font. It's easy to fix, but I don't want to write a whole addon for two lines of code, so I type the lines into a Hack page and flag it to execute. Done.
NOTES:
* Pages are saved as you type and there is no undo, so be careful. If you really screw up a page, you can hit the Revert button, which will give you back the page as it was when you first opened it.
* The list frame and edit frame are resizable. Just grab the little handle in the bottom right corner.
* You can double-click a page name to rename it (in addition to using the rename button).
* Page search is case insensitive. You use a subset of regex search patterns (^$.*-+?).
* Autorun pages run in the order they appear, so you can control their execution order by moving them up and down the list.
EXAMPLES:
I included example pages to show how I use Hack. You can delete these quickly via the books tab. To speed Hack's loading, remove HackExamples.lua from the addon folder.
The "lib:" pages contain library code I find useful in many scripts. To facilitate the use of libraries, Hack contains one built-in function Hack.Require, which can be used to make sure a page you are dependent on is loaded, while preventing it from being loaded more than once.
The arg processing examples show how you can execute a page by name, optionally passing arguments and/or receiving return values.
The "timer lib" examples show how to use "lib: timer".
The "cmd:" examples add new slash commands to the game.
The "ui:" examples are various minor tweaks to the UI.
The "hack:" examples are bits of code I used to write Hack. Saves you a lot of reloading to develop with a tool like this.
FEEDBACK:
I'd love to get feedback about Hack. What you like, what you don't like, what you'd like to see in future versions (keeping in mind that my intention is to keep it as small as possible).
Cheers,
Eric Tetz
<erictetz@gmail.com>
Change Log - Hack
1.2.2 Cosmetic changes (removed background texture, added grips to window corners, etc.)
1.2.1 Fixed bug in indent library.
1.2 Syntax highlighting can now be toggled on/off on a per page basis, or can be permanently disabled by deleting Indent.lua from the Hack folder. This required some fixes to the library, so Hack is no longer compatible with vanilla FAIAP.
1.1.2 Syntax highlighting no longer optional (until I can work out some bugs in the library which prevent it from being enabled/disabled on the fly).
1.1 Added "Send" button, fixed bug in Quest Query example, add/removed/improved a few examples.
1.0.6 Fixed error in Snap which caused edit window to disappear; changed ESC behavior (now clears focus from edit box). Bigger changes coming... *dun dun dun*
1.0.5 Updated to WotLK compatible, including a few necessary changes to the example pages (Quest Query and 'lib: event' in particular)
1.0.4 Update event lib and LuaSlinger importer
1.0.3 Added importers for other notebook addons, made Hack.lua WotLK compatible (Hack.xml will have to wait for release), various minor polish tweaks.
1.0.2 Added support for All Indents and Purposes
1.0.1 Update SavedVariables in TOC
Optional Files - Hack
Sorry, there are currently no optional files available.
Originally posted by Mud Yeah, I finally capitulated. Current version has ESC to escape focus.
Thanks for the heads up. I'll take a look at the end of the week. My machine overhead and FRIED, so new stuff's on the way. Hopefully my old hard disk is OK....
The whole overheating thing sucks, I know, my computer has overheating problems, and I really need to get a fan or some such installed in there, thankfully it hasn't fried yet (though if it does, that'd give me an excuse to convince my fiance of the need to get a new one..)
I do think that the escape to clear focus will be useful, theres been a number of times while editing that I wished I could be editing, clear the focus and answer something someone asked on guild without having to close the hack window.
And for me personally, I like the books, like someone else posted, I can have a book for notes, one for code and so on, its just useful to me. I do think that having the book page have an autorun toggle would be a nice solution to the problem of being on one book but having the other books not load their autoruns. Came here looking to see if there was a new version for that exact reason, because I have was testing timers in my book, would reload for my mod, but then my books code would error because timer (which is on autorun on mine) wasn't loaded. Would be nice to be able to set individual books (if you are staying with books) to run their autoruns.
seebs wrote: Mostly, though, I think it's just consistency with everything else.
Yeah, I finally capitulated. Current version has ESC to escape focus.
Quote:
seebs wrote: The /qq page seems to have a bug [...]
Thanks for the heads up. I'll take a look at the end of the week. My machine overhead and FRIED, so new stuff's on the way. Hopefully my old hard disk is OK....
The /qq page seems to have a bug; if it is set to run when loaded, right-clicking names in chat starts a tell to them instead of popping up the usual menu.
Specifically, it looks like the problem is SetItemRef() -- it is defined as taking an argument called mousebutton, but then calls the original function with the argument button. Since that's a nil, no mouse button is defined, so the original thinks it's a left click, not a right click.
Originally posted by Mud *lol* It's not a pain to clear focus -- you just hit ESC. This just also happens to close the edit window, too. I can buy the argument that ESC should only clear focus (the first time) because that's established convention, but I can't buy the inconvenience argument.
I very often want to clear focus but not close the window. So not having an easy way to do this is arguably inconvenient.
Mostly, though, I think it's just consistency with everything else.
Originally posted by Mud *lol* It's not a pain to clear focus -- you just hit ESC. This just also happens to close the edit window, too. I can buy the argument that ESC should only clear focus (the first time) because that's established convention, but I can't buy the inconvenience argument.
I think what was probably meant there was that having ESC clear focus and close the window is inconvenient because it requires you to reopen the window if clearing focus was all you were looking to do and you wanted the window to stay open. I know I've had that frustration. Convention being what it is, I'm in the habit of hitting escape to clear focus when I'm done typing, in case I happen to want to do something else (like chat with guildies or w/e) while I look over what I've got so far.
Quote:
Originally posted by Mud
Quote:
Originally posted by Nefarion If I were coding it, I'd make a "global" tab, and a "local" tab in place of the tabs that are there now, each displaying its respective list.
That's a great idea. Would simplify the implementation, which always makes me happy.
I'm all for this idea, as long as "respective list" refers to a list of pages. If there are going to be "global books" and "local books", the interface would get messy. But if there are now going to be, in essence, a single "global book" and a single "local book" and a tab for each, that works for me.
Originally posted by Nefarion
[b]But then once the frame gets manual focus, the problem is back, where clearing focus is a total pain.
*lol* It's not a pain to clear focus -- you just hit ESC. This just also happens to close the edit window, too. I can buy the argument that ESC should only clear focus (the first time) because that's established convention, but I can't buy the inconvenience argument.
Originally posted by Mud I think the best compromise is to lose the auto-focus (which I'm happy to do, since it involves removing code ^_^), but keep the ESC behavior. Your thoughts?
But then once the frame gets manual focus, the problem is back, where clearing focus is a total pain. Personally, I'm in favor of double-escape: first one clears focus, second closes the window. (The how all the other frames in the default UI are anyway.)
And regarding the book think, it would be annoying for people that already have books. But it sure would make things a lot cleaner.
Edit: Hack broke. I un-stuck the edit frame, and when I reloaded, it refused to open up. I can't seem to find anything in the code to fix it.
Doh. Stupid oversight in Hack.Snap() Will be fixed today. If it happens to anybody else, just do "/run HackDB.snap = true" and reload to get your edit window back.
Quote:
I personally see 0 use for books other than as pseudo-profiles. The feature itself seems pointless
Yeah, it was one of those things that fell out of the existing implementation with so little effort,that I just went ahead and added it. Of course, it required me to use Blizzard's TAB library, which has prebuilt graphics that didn't match my border, so I had to thicken the bottom border of my windows, etc. every choice has ramifications.
What if you the 'autorun' button was available in the book window, such that you could enable/disable entire books. Would that make it a useful as an organizational feature?
Quote:
If I were coding it, I'd make a "global" tab, and a "local" tab in place of the tabs that are there now, each displaying its respective list.
That's a great idea. Would simplify the implementation, which always makes me happy.
Unfortunately, it's a breaking change for people who already have multiple books. I can just merge them when loading the new version, but I wonder how many people that would piss off?
Originally posted by Mud Still, I'm already up to nearly 50K bare naked, whereas Nefpad is a mere 28K. I'm start to feel self-conscious about it... what are your thoughts on the matter?
My thoughts? I didn't even know Nefpad was 28k. It wouldn't have bothered me if it were 1000k. Static memory numbers don't affect anything, and the numbers you're dealing with aren't even nearly high enough to annoy the OCD bunch that need a uselessly light UI.
Go ahead and add code. Stop worrying about its size. Functionality, ease of coding, and true performance impact are what matter.
Edit: Hack broke. I un-stuck the edit frame, and when I reloaded, it refused to open up. I can't seem to find anything in the code to fix it.
Edit: Yeah, it appears the HackEditFrame is somehow going off-screen when I reload, if it isn't attached to the list frame. I had to manually reposition it with HackEditFrame:ClearAllPoints(), ... .
Quote:
Originally posted by Mud Thoughts?
I personally see 0 use for books other than as pseudo-profiles. The feature itself seems pointless, other than to manage local-only books. If I were coding it, I'd make a "global" tab, and a "local" tab in place of the tabs that are there now, each displaying its respective list.
The behavior I take issue with is that only the "current" book is checked for autorun scripts on startup.
Alas, this is true. A related problem is that there is no (easy) way to run pages from books other than the currently selected one. This is mostly because I hadn't quite settled on what those secondary books were really for. I've been letting it percolate in my brain for a bit.
I'll think out loud for a second here, so I can get some feedback before making any changes.
Initially 'books' were going to be 'profiles', in which case it makes sense for only the selected one to run (with the index of the selected book stored per-character; currently it's not). I can easily make autorun iterate through all books, but then they couldn't be used as profiles (as John Carmack said, "The cost of adding a feature isn't just the time it takes to code it. The cost also includes the addition of an obstacle to future expansion.")
I need to figure out some way of letting you enable some scripts only for certain toons. I don't think the traditional profile approach -- where each profile has a totally separate data -- suits Hack, because you really want to share pages (probably the majority) between profiles.
Ideally, you'd be able to toggle individual pages as "private" or "public" (or local/global, me/everyone, etc.) so that private pages are seen only by your character and public pages are shared between all characters. I put a lot of thought into that, but it's a nightmare to implement if you want to maintain the pages as an ordered list. Any clever ideas in that regard would be helpful.
I suppose I could just totally ditch the idea of supporting profiles directly, and you just maintain a Hack page which runs player-specific pages on startup. Something like:
Code:
local profile = {
Mud = { 'sheep watching hack', },
Rhodes = { 'shapeshifting hack', 'tanking hack', 'some other hack' },
}
for page in pairs(profile[UnitName'player'] or {}) do
Hack.Run(page)
end
Another option might be to have one character-specific book (which cannot be deleted), with all other books global.
Thoughts?
Anyway, don't want to make any decisions right now (massive sleep deprivation). I'll take a fresh look in the morning.
I have either a bug report or a gripe, depending on whether or not the following behavior was intentional.
I have set up three books, one for notes, one for scripts I write, and one the example book that comes with the mod. The example book is unmodified.
The behavior I take issue with is that only the "current" book is checked for autorun scripts on startup. So if I am looking at the examples book and I reload ui, autorun scripts in my scripts book do not fire. If I switch to my scripts book and try to execute one of them, it works fine. But if I reload ui at that point, my scripts do fire but they complain about functions defined in the examples book, which never fired. Worse still, if I happen to be looking at my notes book when I reload, nothing fires!
For the short term, I have moved all my notes and scripts into one book, and everything seems to be working fine. But it would help me out immensely if all books would autorun scripts on startup.
I'm with seebs. The standard I've always seen/used is that for frames with keyboard focus, ESC clears focus; for frames without focus, ESC closes the frame. I'd rather lose auto focus (because when I open a page I don't always want to make edits) and have to hit ESC multiple times. I think even the non-technical will "get" the double/triple ESC thing because the rest of WoW works that way.
If I may make an additional suggestion: If you're going to add a code/text toggle to prevent FAIAP from running on text pages, the run button should also be disabled for text pages.
And if I may pick one item off your list: I'd like line numbers, but with an option to disable them for code and/or text pages.
BTW, fantastic mod, I just finished importing all my TinyPad and LuaSlinger data.
I'm usually fine with hitting escape twice to close a window.
UI design, rule 1: The principle of least astonishment. What behavior will least surprise a user? Mess around with other interfaces in the game, such as the mail window. Open the mail window, start typing a name, then see what happens when you hit escape. It takes two clicks to make the window go away; the first just drops focus.
Nefarion said: One little tick: The input page uses auto-focus, which is fine, but there's no simple way to clear the focus, since pressing escape just closes the page.
Thanks for the feedback. This is exactly the kinda stuff I want.
My rational for auto-focus was to require the fewest mouse clicks for the most common usage case. I assume when you click a page, you intend to edit it, so I put the cursor there, so you don't need to click twice every time you want to edit a page. That extra click is annoying if you're copying and pasting between pages.
My rational for ESC dismissing the page was similar. If ESC clears the focus first, you'd have to hit ESC three times to fully dismiss Hack from an open page. Also, 'clearing focus' is kinda subtle, and I thought it would feel glitchy to users if they hit ESC to get Hack off their screen and nothing happens (because they didn't notice the cursor disappearing from the edit box).
Of course, as you point out, this creates a problem if you just want to view information while continuing to play WoW. You can clear the focus, but it's not obvious how and requires several clicks.
I think the best compromise is to lose the auto-focus (which I'm happy to do, since it involves removing code ^_^), but keep the ESC behavior. Your thoughts?
Quote:
Nefarion said: I find it a little annoying for For All Indents and Purposes to be applied to normal text pages. Any plans on adding a button to quickly disable it on individual pages?
Yeah, that annoys me, too. I think I'll go ahead and add that button (code/plain toggle).
There are plenty of features I'd like to add, of course, but I've been really reluctant to add anything that didn't seem nonessential. I originally wasn't even going to have more than one book, but then I figured out a way to do it with very little additional code. Still, I'm already up to nearly 50K bare naked, whereas Nefpad is a mere 28K. I'm start to feel self-conscious about it... what are your thoughts on the matter? If I were to give myself another, say, 30K to work with, would people reject Hack as bloatware?
A few things in the back of my head, if I was willing to give myself a bit more RAM (in no particular order)
Cloning pages/books.
Line numbers and/or ability to jump to specific lines (annoying when you get a script error for something on line 34 when there are no line numbers *lol*).
Send pages to other Hack users.
Highlighting of search text within pages
More sophisticated profile management. so that a book could contain both public and private page (i.e. global and character specific)
Ability to run pages in other books, or flag an entire book for execution.
Originally posted by Mud BTW: porting to 3.x appears to be pretty trivial, at least for our kinda app. I ported LuaSlinger for you (quick job, not thoroughly tested).
Thanks Mud. I posted it over on LuaSlinger's download page, with a link here and a note strongly suggesting people switch to Hack instead. Keep up the good work.