## editing sandboxes after they've been created scenario clicking-on-a-sandbox-moves-it-to-editor [ trace-until 100/app # trace too long assume-screen 40/width, 10/height # run something 1:address:array:character <- new [add 2, 2] assume-console [ press F4 ] 2:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data screen-should-contain [ . run (F4) . . . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. .0 x. .add 2, 2 . .4 . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . . . ] # click somewhere on the sandbox assume-console [ left-click 3, 0 ] run [ event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] # it pops back into editor screen-should-contain [ . run (F4) . .add 2, 2 . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . . . . . . . . . . . ] # cursor should be in the right place assume-console [ type [0] ] run [ event-loop screen:address:screen, console:address:console, 2:address:programming-environment-data ] screen-should-contain [ . run (F4) . .0add 2, 2 . .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . . . . . . . . . . . ] ] after [ # below editor? pop appropriate sandbox contents back into sandbox editor provided it's empty { sandbox-left-margin:number <- get *current-sandbox, left:offset click-column:number <- get t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? empty-sandbox-editor?:boolean <- empty-editor? current-sandbox break-unless empty-sandbox-editor? # don't clobber existing contents # identify the sandbox to edit and remove it from the sandbox list sandbox:address:sandbox-data <- extract-sandbox env, click-row break-unless sandbox text:address:array:character <- get *sandbox, data:offset current-sandbox <- insert-text current-sandbox, text *env <- put *env, render-from:offset, -1 hide-screen screen screen <- render-sandbox-side screen, env screen <- update-cursor screen, current-sandbox, env show-screen screen loop +next-event:label } ] def empty-editor? editor:address:editor-data -> result:boolean [ local-scope load-ingredients head:address:duplex-list:character <- get *editor, data:offset first:address:duplex-list:character <- next head result <- not first ] def extract-sandbox env:address:programming-environment-data, click-row:number -> result:address:sandbox-data, env:address:programming-environment-data [ local-scope load-ingredients curr-sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *curr-sandbox, starting-row-on-screen:offset in-editor?:boolean <- lesser-than click-row, start return-if in-editor?, 0 first-sandbox?:boolean <- equal click-row, start { # first sandbox? pop break-unless first-sandbox? next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset *en
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#define TAGS \
const char *tags[] = { "1", "2", "3", "4", "5", NULL };

#define DEFMODE			dotile /* dofloat */
#define FONT			"fixed"
#define BGCOLOR			"#666699"
#define FGCOLOR			"#eeeeee"
#define BORDERCOLOR		"#9999CC"
#define MODKEY			Mod1Mask
#define MASTERW			60 /* percent */

#define KEYS \
static Key key[] = { \
	/* modifier			key		function	arguments */ \
	{ MODKEY|ShiftMask,		XK_Return,	spawn,		{ .cmd = "exec xterm" } }, \
	{ MODKEY,			XK_Tab,		focusnext,	{ 0 } }, \
	{ MODKEY|ShiftMask,		XK_Tab,		focusprev,	{ 0 } }, \
	{ MODKEY,			XK_Return,	zoom,		{ 0 } }, \
	{ MODKEY,			XK_m,		togglemax,	{ 0 } }, \
	{ MODKEY|ShiftMask,		XK_1,		tag,		{ .i = 0 } }, \
	{ MODKEY|ShiftMask,		XK_2,		tag,		{ .i = 1 } }, \
	{ MODKEY|ShiftMask,		XK_3,		tag,		{ .i = 2 } }, \
	{ MODKEY|ShiftMask,		XK_4,		tag,		{ .i = 3 } }, \
	{ MODKEY|ShiftMask,		XK_5,		tag,		{ .i = 4 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_1,		toggletag,	{ .i = 0 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_2,		toggletag,	{ .i = 1 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_3,		toggletag,	{ .i = 2 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_4,		toggletag,	{ .i = 3 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_5,		toggletag,	{ .i = 4 } }, \
	{ MODKEY|ShiftMask,		XK_c,		killclient,	{ 0 } }, \
	{ MODKEY,			XK_space,	togglemode,	{ 0 } }, \
	{ MODKEY,			XK_1,		view,		{ .i = 0 } }, \
	{ MODKEY,			XK_2,		view,		{ .i = 1 } }, \
	{ MODKEY,			XK_3,		view,		{ .i = 2 } }, \
	{ MODKEY,			XK_4,		view,		{ .i = 3 } }, \
	{ MODKEY,			XK_5,		view,		{ .i = 4 } }, \
	{ MODKEY|ControlMask,		XK_1,		toggleview,	{ .i = 0 } }, \
	{ MODKEY|ControlMask,		XK_2,		toggleview,	{ .i = 1 } }, \
	{ MODKEY|ControlMask,		XK_3,		toggleview,	{ .i = 2 } }, \
	{ MODKEY|ControlMask,		XK_4,		toggleview,	{ .i = 3 } }, \