+ bool editingNode = false;
+
+ while (true) {
+ c = GetChar();
+
+ if (c == KEY_CTRL_C)
+ break;
+
+ if (editingNode) {
+ if (node->data == (size_t)NULL) {
+ node->data = (size_t)NEWARR(char, 16);
+ strLen = 0;
+ }
+ if (isNewline(c)) {
+ editingNode = false;
+ }
+ else {
+ char * str = (char *)node->data;
+
+ if (isBackspace(c)) {
+ str[strLen-1] = '\0';
+ strLen--;
+ }
+ else if (strLen < 16 - 1) {
+ str[strLen] = c;
+ str[strLen+1] = '\0';
+ strLen++;
+ }
+ }
+ }
+ else {
+ if (node == NULL) {
+ /**/ if (c == 'i') { node = JSONNodeNew(JSONNodeKind_Int); editingNode = true; }
+ else if (c == 's') { node = JSONNodeNew(JSONNodeKind_Str); editingNode = true; }
+ else if (c == 'o') { node = JSONNodeNew(JSONNodeKind_Obj); }
+ else if (c == 'a') { node = JSONNodeNew(JSONNodeKind_Arr); }
+ g_DrawNode = g_CurrNode = result = node;
+ }
+ else if (node->kind == JSONNodeKind_Int) {
+ /**/ if (c == 'h') { if (node->prev != NULL) g_CurrNode = node = node->prev; }
+ else if (c == 'l') { if (node->next != NULL) g_CurrNode = node = node->next; }
+ else if (c == 'k') { if (node->parent != NULL) g_CurrNode = node = node->parent; }
+ else if (c == 'j') { if (node->firstChild != NULL) g_CurrNode = node = node->firstChild; }
+ else if (c == ' ') { if (JSONNodeEditable(node)) editingNode = true; }
+ else if (isBackspace(c)) { g_CurrNode = node = JSONNodeRemove(node); }
+ }
+ else if (node->kind == JSONNodeKind_Str) {
+ /**/ if (c == 'h') { if (node->prev != NULL) g_CurrNode = node = node->prev; }
+ else if (c == 'l') { if (node->next != NULL) g_CurrNode = node = node->next; }
+ else if (c == 'k') { if (node->parent != NULL) g_CurrNode = node = node->parent; }
+ else if (c == 'j') { if (node->firstChild != NULL) g_CurrNode = node = node->firstChild; }
+ else if (c == ' ') { if (JSONNodeEditable(node)) editingNode = true; }
+ else if (isBackspace(c)) { g_CurrNode = node = JSONNodeRemove(node); }
+ }
+ else if (node->kind == JSONNodeKind_Obj) {
+ /**/ if (c == 'i') { node = JSONNodePush(node, JSONNodePush(JSONNodeNew(JSONNodeKind_Str), JSONNodeNew(JSONNodeKind_Int))->parent); editingNode = true; }
+ else if (c == 's') { node = JSONNodePush(node, JSONNodePush(JSONNodeNew(JSONNodeKind_Str), JSONNodeNew(JSONNodeKind_Str))->parent); editingNode = true; }
+ else if (c == 'o') { node = JSONNodePush(node, JSONNodePush(JSONNodeNew(JSONNodeKind_Str), JSONNodeNew(JSONNodeKind_Obj))->parent); editingNode = true; }
+ else if (c == 'a') { node = JSONNodePush(node, JSONNodePush(JSONNodeNew(JSONNodeKind_Str), JSONNodeNew(JSONNodeKind_Arr))->parent); editingNode = true; }
+
+ else if (c == 'h') { if (node->prev != NULL) g_CurrNode = node = node->prev; }
+ else if (c == 'l') { if (node->next != NULL) g_CurrNode = node = node->next; }
+ else if (c == 'k') { if (node->parent != NULL) g_CurrNode = node = node->parent; }
+ else if (c == 'j') { if (node->firstChild != NULL) g_CurrNode = node = node->firstChild; }
+ else if (isBackspace(c)) { node = JSONNodeRemove(node); }
+
+ g_CurrNode = node;
+ }
+ else if (node->kind == JSONNodeKind_Arr) {
+ /**/ if (c == 'i') { node = JSONNodePush(node, JSONNodeNew(JSONNodeKind_Int)); editingNode = true; }
+ else if (c == 's') { node = JSONNodePush(node, JSONNodeNew(JSONNodeKind_Str)); editingNode = true; }
+ else if (c == 'o') { node = JSONNodePush(node, JSONNodeNew(JSONNodeKind_Obj)); }
+ else if (c == 'a') { node = JSONNodePush(node, JSONNodeNew(JSONNodeKind_Arr)); }
+
+ else if (c == 'h') { if (node->prev != NULL) g_CurrNode = node = node->prev; }
+ else if (c == 'l') { if (node->next != NULL) g_CurrNode = node = node->next; }
+ else if (c == 'k') { if (node->parent != NULL) g_CurrNode = node = node->parent; }
+ else if (c == 'j') { if (node->firstChild != NULL) g_CurrNode = node = node->firstChild; }
+ else if (isBackspace(c)) { node = JSONNodeRemove(node); }
+
+ g_CurrNode = node;
+ }