lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wednesday 09 February 2011 06:44:35 David Given wrote:
> On 02/09/11 00:37, Rob Kendrick wrote:
> [...]
> 
> > It would be ncurses, but nobody's written a binding for it yet that
> > doesn't make me want to spurt poisonous bile from my nipples.
> 
> You might want to get that looked into...
> 
> I'm quite happy with the curses-based GUI wot I wrote for WordGrinder,
> although it's very simple. To run a dialogue you just do:
> 
> local dialogue = {
> 	title = "Title goes here"
> 	width = Form.Large, -- just smaller than screen
> 	height = 12, -- or absolute value,
> 
> 	-- Arbitrary keybindings
> 	["KEY_RETURN"] = function() return "confirm" end,
> 	["KEY_ENTER"] = "confirm",
> 	["KEY_^C"] = "cancel",
> 
> 	-- Widgets:
> 	Form.Label {
> 		-- bounding box. Negative numbers go from
> 		-- opposite side of dialogue
> 		x1 = 1, y1 = 2,
> 		x2 = -1, y2 = 2,
> 		align = Form.Left,
> 		text = "Hello, world!"
> 	},
> 
> 	Form.TextField {
> 		x1 = 1, y1 = 5,
> 		x2 = -1, y2 = 5,
> 		value = "Initial value of text field"
> 	}
> }
> 
> Then you do:
> 
> local result = Form.Run(dialogue, RedrawScreen)
> 
> RedrawScreen is a function that draws what's behind the dialogue, and it
> returns a value indicating whether the dialogue was confirmed or
> cancelled. Typically I call this in a loop that validates the values the
> user put into the dialogue.
> 
> The whole thing's about 600 lines of code, not including the curses
> drawing routines. Widgets can be customised by overriding methods on the
> widget instantiation. I'm fairly pleased with the general Lua-ness of it.
> 
> There's a bunch of stuff wrong with it, mainly in that it handles
> screens too small for the dialogue rather ungracefully, and of course
> the total lack of documentation, polish, and the fact that it's
> integrated into WordGrinder and intended for dialogues only; I have
> other stuff I want to write using it, and so have vague plans to
> abstract it into a proper library at some point.
> 
> Code here:
> 
> http://wordgrinder.hg.sourceforge.net/hgweb/wordgrinder/wordgrinder/file/f6
> 58d1e8f1f3/src/lua/forms.lua
> 
> Example here (starting at line 100):
> 
> http://wordgrinder.hg.sourceforge.net/hgweb/wordgrinder/wordgrinder/file/f6
> 58d1e8f1f3/src/lua/addons/autosave.lua

Hi David,

If that were GUI instead of Curses, I'd be on it like a squirrel on a tree. 
Everything on there is something you type into, select from, or choose, or a 
property of one of those. It maps well to what's presented to the user. It 
requires a minimum of wizardly incantations.

I don't quite see how it interfaces to nCurses. How does it do that?

You know, it's too bad you don't have some sort of translator that takes code 
destined for your nCurses thing and turns it into some sort of GUI source 
code.

Thanks

SteveT


Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt