Skip to content

Commit e6d17b9

Browse files
committed
formating json
have to put some order in separators
1 parent 06eaf3f commit e6d17b9

File tree

10 files changed

+144
-46
lines changed

10 files changed

+144
-46
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoMenu library
2-
version=4.14.1
2+
version=4.15.0
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=Generic menu/interactivity system

src/itemsTemplates.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace Menu {
146146
for(idx_t i=0;i<sz();i++)
147147
if (((menuValue<T>*)&operator[](i))->target()==target()) return i;
148148
#ifdef MENU_DEBUG
149-
MENU_DEBUG_OUT.print(F("value out of range "));
149+
MENU_DEBUG_OUT.print("value out of range ");
150150
MENU_DEBUG_OUT.println(target());MENU_DEBUG_OUT.flush();
151151
assert(false);
152152
#endif
@@ -157,7 +157,7 @@ namespace Menu {
157157
#ifdef MENU_DEBUG
158158
if (!(i>=0&&i<sz())){
159159
print_P(MENU_DEBUG_OUT,getText());
160-
MENU_DEBUG_OUT.print(F(" : value out of range "));
160+
MENU_DEBUG_OUT.print(" : value out of range ");
161161
MENU_DEBUG_OUT.println(i);
162162
}
163163
assert(i>=0&&i<sz());

src/menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ result Menu::inaction(menuOut& o,idleEvent) {
1515

1616
result Menu::maxDepthError(menuOut& o,idleEvent e) {
1717
trace(MENU_DEBUG_OUT<<"maxDepthError"<<endl);
18-
o.print(F("Error: maxDepth reached!\n\rincrease maxDepth on your scketch."));
18+
o.print("Error: maxDepth reached!\n\rincrease maxDepth on your scketch.");
1919
return proceed;
2020
}
2121

src/menuIO/esp8266Out.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//#include <Hash.h>
1313
//#include <FS.h>
1414
#include <vector>
15+
#include "xmlFmt.h"
1516

1617
using namespace std;
1718

src/menuIO/jsonFmt.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,36 @@
33
#include "jsonFmt.h"
44

55
namespace Menu {
6+
#ifdef MENU_DEBUG
7+
int partIndent=0;
8+
const char* partName(menuOut::fmtParts part) {
9+
switch (part){
10+
case menuOut::fmtPanel: return "fmtPanel";
11+
case menuOut::fmtTitle: return "fmtTitle";
12+
case menuOut::fmtBody: return "fmtBody";
13+
case menuOut::fmtOp: return "fmtOp";
14+
case menuOut::fmtIdx: return "fmtIdx";
15+
case menuOut::fmtCursor: return "fmtCursor";
16+
case menuOut::fmtOpBody: return "fmtOpBody";
17+
case menuOut::fmtPreview: return "fmtPreview";
18+
case menuOut::fmtPrompt: return "fmtPrompt";
19+
case menuOut::fmtField: return "fmtField";
20+
case menuOut::fmtToggle: return "fmtToggle";
21+
case menuOut::fmtSelect: return "fmtSelect";
22+
case menuOut::fmtChoose: return "fmtChoose";
23+
case menuOut::fmtUnit: return "fmtUnit";
24+
case menuOut::fmtTextField: return "fmtTextField";
25+
default: return "???";
26+
}
27+
}
28+
void printIndent() {
29+
for(int n=0;n<partIndent;n++) MENU_DEBUG_OUT<<" ";
30+
}
31+
#endif
32+
int cursorCtrl=0;
633
void jsonOptions(menuOut& o,navNode &nav,menuNode& node,idx_t idx) {
7-
o<<"\"options\":[";
34+
o<<"\",options\":[";
35+
// o<<node.sz();
836
for(idx_t n=0;n<node.sz();n++)
937
o<<(n?",":"")<<"\""<<node[n]<<"\"";
1038
o<<"]";

src/menuIO/jsonFmt.h

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
namespace Menu {
1212

13+
#ifdef MENU_DEBUG
14+
extern int partIndent;
15+
const char* partName(menuOut::fmtParts part);
16+
void printIndent();
17+
#endif
18+
19+
extern int cursorCtrl;
20+
1321
void jsonOptions(menuOut& o,navNode &nav,menuNode& node,idx_t idx);
1422

1523
//wraps a webserver output and writes xml to it
@@ -24,49 +32,48 @@
2432
else T::operator<<("}");
2533
break;
2634
case menuOut::fmtTitle:
27-
if (start) T::operator<<("\"title\":");
28-
else T::operator<<(",");
35+
if (start) T::operator<<("\"title\":{");
36+
else T::operator<<("},\n");
2937
break;
3038
case menuOut::fmtBody:
3139
if (start) {
3240
*this<<"\"sel\":\""<<nav.sel<<"\",";
33-
*this<<"\"items\": [";
34-
} else T::operator<<("],"); break;
41+
*this<<"\"items\":[\n";
42+
} else T::operator<<("\n]\n"); break;
3543
case menuOut::fmtUnit:
36-
*this<<(start?"\"unit\":":",");
44+
*this<<(start?"\"unit\":\"":"\"");
3745
break;
3846
case menuOut::fmtOp:
3947
if (start) {
40-
*this<<"{"
41-
<<"\"op\":"
42-
<<"\"idx\":\""<<idx<<"\","
43-
<<"\"enabled\":"<<target.enabled<<"\",";
44-
} else T::operator<<("}");
48+
if (idx>0) *this<<",\n";
49+
else "\n";
50+
*this<<"{\"idx\":\""<<idx<<"\","
51+
<<"\"enabled\":\""<<target.enabled<<"\",";
52+
} else *this<<("}");
4553
break;
4654
case menuOut::fmtToggle:
4755
if (start) {
48-
*this<<"\"tog\":[";
56+
*this<<",\"value\":\"";
57+
} else {
58+
*this<<"\",";
4959
jsonOptions(*this,nav,*(menuNode*)&target,idx);
50-
*this<<"],\"value\":";
51-
} else *this<<",";
60+
// *this<<",";
61+
}
5262
break;
5363
case menuOut::fmtPrompt:
5464
if (start) {
55-
*this<<"\"tog\":";
56-
jsonOptions(*this,nav,*(menuNode*)&target,idx);
57-
*this<<",\"value\":";
65+
*this<<"\"prompt\":\"";
5866
} else {
59-
*this<<",";
60-
*this<<"\"name\":"<<target.typeName();
61-
*this<<",";
6267
*this<<"\"";
68+
if (target.has(_asPad))
69+
*this<<",\"pad\":[";
6370
};
6471
break;
6572
case menuOut::fmtSelect:
6673
if (start) {
67-
*this<<"\"select\":";
74+
*this<<",\"type\":\"select\"";
6875
jsonOptions(*this,nav,*(menuNode*)&target,idx);
69-
} else *this<<",";
76+
} else *this<<"";
7077
break;
7178
case menuOut::fmtChoose:
7279
if (start) {
@@ -77,43 +84,71 @@
7784
break;
7885
case menuOut::fmtField:
7986
if (start) {
80-
*this<<"\"field\":{\"high\":\"";
81-
target.printHigh(*this);
82-
*this<<"\",\"low\":\"";
87+
*this<<",\"field\":\"";
88+
} else {
89+
*this<<"\",\"range\":{\"low\":\"";
8390
target.printLow(*this);
91+
*this<<"\",\"high\":\"";
92+
target.printHigh(*this);
8493
*this<<"\",\"step\":\"";
8594
target.printStep(*this);
8695
*this<<"\",\"tune\":\"";
8796
target.printTune(*this);
8897
*this<<"\"}";
89-
} else *this<<",";
98+
*this<<",";
99+
}
90100
break;
91101
case menuOut::fmtTextField:
92-
if (start) *this<<"\"value\":";
93-
else *this<<",";
102+
if (start) *this<<",\"text\":\"";
103+
else *this<<"\"\n";
94104
break;
95105
case menuOut::fmtIdx:
96-
if (start) *this<<"\"idx\":";
97-
else *this<<",";
106+
// if (start) *this<<"\"idx\":";
107+
// else *this<<",";
98108
break;
99109
case menuOut::fmtCursor:
100-
if (start) *this<<"\"cursor\":";
101-
else *this<<",";
110+
if (start) *this<<"\"cursor\":\"";
111+
else *this<<"\",";
112+
break;
113+
case menuOut::fmtCursorOpen:
114+
if (start) *this<<"\"selStart\":\"";
115+
else *this<<"\",";
116+
break;
117+
case menuOut::fmtCursorClose:
118+
if (start) *this<<",\"selEnd\":\"";
119+
else *this<<"\"";
102120
break;
103121
case menuOut::fmtOpBody:
104-
if (start) *this<<"\"body\":";
105-
else *this<<",";
122+
if (start) {
123+
// *this<<"\"body\":{";
124+
// if (target.has(_asPad)) *this<<"\"pad\":[";
125+
} else {
126+
if (target.has(_asPad)) *this<<"]";
127+
// *this<<"}";
128+
}
106129
break;
107130
case menuOut::fmtPreview:
108131
if (start) *this<<"\"preview\":";
109-
else *this<<",";
132+
else *this<<",\n";
110133
break;
111134
default:break;
112135
}
113136
return proceed;
114137
}
115-
result fmtStart(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {return fmt(true,target,part,nav,idx);}
116-
result fmtEnd(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {return fmt(false,target,part,nav,idx);}
138+
result fmtStart(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {
139+
_trace(printIndent();MENU_DEBUG_OUT<<">"<<partName(part)<<" "<<idx<<" "<<target<<endl);
140+
#ifdef MENU_DEBUG
141+
partIndent++;
142+
#endif
143+
return fmt(true,target,part,nav,idx);
144+
}
145+
result fmtEnd(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {
146+
#ifdef MENU_DEBUG
147+
partIndent--;
148+
#endif
149+
_trace(printIndent();MENU_DEBUG_OUT<<"<"<<partName(part)<<endl);
150+
return fmt(false,target,part,nav,idx);
151+
}
117152
};
118153
}//namespace
119154
#endif

src/menuIO/xmlFmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
else *this<<"]]></idx>";
136136
break;
137137
case menuOut::fmtCursor:
138+
case menuOut::fmtCursorOpen:
139+
case menuOut::fmtCursorClose:
138140
if (start) *this<<"<cur><![CDATA[";
139141
else *this<<"]]></cur>";
140142
break;

src/menuIo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,15 @@ Used menuOut::printMenu(navNode &nav,idx_t panelNr) {
401401
#endif
402402
//------> cursorStart
403403
#ifdef MENU_FMT_WRAPS
404-
fmtStart(p,fmtCursor,nav,i);
404+
fmtStart(p,fmtCursorOpen,nav,i);
405+
// fmtStart(p,fmtCursor,nav,i);
405406
#endif
406407
if (asPad&&selected) print("[");
407408
else drawCursor(ist,selected,p.enabled,ed,panelNr);//assuming only one character
408409
//<------ cursorEnd
409410
#ifdef MENU_FMT_WRAPS
410-
fmtEnd(p,fmtCursor,nav,i);
411+
fmtEnd(p,fmtCursorOpen,nav,i);
412+
// fmtEnd(p,fmtCursor,nav,i);
411413
#endif
412414
len--;
413415
//---->opBodyStart
@@ -419,11 +421,13 @@ Used menuOut::printMenu(navNode &nav,idx_t panelNr) {
419421
if (len>0) {
420422
if (asPad) {
421423
#ifdef MENU_FMT_WRAPS
422-
fmtStart(p,fmtCursor,nav,i);
424+
// fmtStart(p,fmtCursor,nav,i);
425+
fmtStart(p,fmtCursorClose,nav,i);
423426
#endif
424427
print(selected?"]":"");
425428
#ifdef MENU_FMT_WRAPS
426-
fmtEnd(p,fmtCursor,nav,i);
429+
fmtEnd(p,fmtCursorClose,nav,i);
430+
// fmtEnd(p,fmtCursor,nav,i);
427431
#endif
428432
len--;
429433
}
@@ -457,6 +461,7 @@ Used menuOut::printMenu(navNode &nav,idx_t panelNr) {
457461
#ifdef MENU_FMT_WRAPS
458462
fmtEnd(*nav.target,fmtPanel,nav,-1);
459463
#endif
464+
trace(MENU_DEBUG_OUT<<"ENDING menuOut::printMenu(navNode &nav,idx_t panelNr)"<<endl);
460465
return 0;
461466
}
462467

src/menuIo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
fmtPanel,fmtTitle,fmtBody,fmtOp,
6565
fmtIdx,fmtCursor,fmtOpBody,fmtPreview,
6666
fmtPrompt,fmtField,fmtToggle,fmtSelect,
67-
fmtChoose,fmtUnit,fmtTextField
67+
fmtChoose,fmtUnit,fmtTextField,fmtCursorOpen,fmtCursorClose
6868
};
6969
menuNode* drawn=NULL;
7070
bool pageScroll=false;

test.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"output":"",
3+
"menu":{
4+
"title":{"prompt":"Zeit/Datum einstellen"},
5+
"sel":"0","items":[
6+
{"idx":"0","enabled":"1","cursor":">","prompt":"",
7+
"pad":[
8+
{"idx":"0","enabled":"1","cursor":" ","prompt":"" ,"field":"1","range":{"low":"1","high":"31","step":"1","tune":"0"},"unit":"/"},
9+
{"idx":"1","enabled":"1","cursor":" ","prompt":"" ,"field":"1","range":{"low":"1","high":"12","step":"1","tune":"0"},"unit":"/"},
10+
{"idx":"2","enabled":"1","cursor":" ","prompt":"" ,"field":"2000","range":{"low":"2000","high":"2100","step":"10","tune":"1"},"unit":""}
11+
]
12+
},
13+
{"idx":"1","enabled":"1","cursor":" ","prompt":"",
14+
"pad":[
15+
{"idx":"0","enabled":"1","cursor":" ","prompt":"" ,"field":"0","range":{"low":"0","high":"23","step":"1","tune":"0"},"unit":":"},
16+
{"idx":"1","enabled":"1","cursor":" ","prompt":"" ,"field":"6","range":{"low":"0","high":"59","step":"10","tune":"1"},"unit":":"},
17+
{"idx":"2","enabled":"1","cursor":" ","prompt":"" ,"field":"33","range":{"low":"0","high":"59","step":"10","tune":"1"},"unit":""}
18+
]
19+
},
20+
{"idx":"2","enabled":"1","cursor":" ","prompt":"GMT" ,"field":"-1","range":{"low":"-11","high":"12","step":"1","tune":"0"},"unit":""},
21+
{"idx":"3","enabled":"1","cursor":" ","prompt":"Sommerzeit:""tog":["options":[2]],"value":An,},
22+
{"idx":"4","enabled":"1","cursor":" ","prompt":"benutze NTP"},
23+
{"idx":"5","enabled":"1","cursor":" ","prompt":"Speichern"},
24+
{"idx":"6","enabled":"1","cursor":" ","prompt":"Zurück"}
25+
]
26+
}
27+
}

0 commit comments

Comments
 (0)