Repository navigation
Expand file tree
/
Copy pathjsonFmt.h
More file actions
120 lines (115 loc) · 4.19 KB
/
Copy pathjsonFmt.h
File metadata and controls
120 lines (115 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -*- C++ -*- */
#ifndef RSITE_ARDUINO_MENU_JSONFMT
#define RSITE_ARDUINO_MENU_JSONFMT
#ifdef MENU_FMT_WRAPS
#include "../menu.h"
#include "../items.h"
#include "esp8266Out.h"
namespace Menu {
void jsonOptions(menuOut& o,navNode &nav,menuNode& node,idx_t idx);
//wraps a webserver output and writes xml to it
template<class T>
class jsonFmt:public T {
public:
using T::T;
result fmt(bool start,prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) {
switch(part) {
case menuOut::fmtPanel:
if (start) *this<<"{";
else T::operator<<("}");
break;
case menuOut::fmtTitle:
if (start) T::operator<<("\"title\":");
else T::operator<<(",");
break;
case menuOut::fmtBody:
if (start) {
*this<<"\"sel\":\""<<nav.sel<<"\",";
*this<<"\"items\": [";
} else T::operator<<("],"); break;
case menuOut::fmtUnit:
*this<<(start?"\"unit\":":",");
break;
case menuOut::fmtOp:
if (start) {
*this<<"{"
<<"\"op\":"
<<"\"idx\":\""<<idx<<"\","
<<"\"enabled\":"<<target.enabled<<"\",";
} else T::operator<<("}");
break;
case menuOut::fmtToggle:
if (start) {
*this<<"\"tog\":[";
jsonOptions(*this,nav,*(menuNode*)&target,idx);
*this<<"],\"value\":";
} else *this<<",";
break;
case menuOut::fmtPrompt:
if (start) {
*this<<"\"tog\":";
jsonOptions(*this,nav,*(menuNode*)&target,idx);
*this<<",\"value\":";
} else {
*this<<",";
*this<<"\"name\":"<<target.typeName();
*this<<",";
*this<<"\"";
};
break;
case menuOut::fmtSelect:
if (start) {
*this<<"\"select\":";
jsonOptions(*this,nav,*(menuNode*)&target,idx);
} else *this<<",";
break;
case menuOut::fmtChoose:
if (start) {
*this<<"\"choose\":";
jsonOptions(*this,nav,*(menuNode*)&target,idx);
} else *this<<",";
break;
break;
case menuOut::fmtField:
if (start) {
*this<<"\"field\":{\"high\":\"";
target.printHigh(*this);
*this<<"\",\"low\":\"";
target.printLow(*this);
*this<<"\",\"step\":\"";
target.printStep(*this);
*this<<"\",\"tune\":\"";
target.printTune(*this);
*this<<"\"}";
} else *this<<",";
break;
case menuOut::fmtTextField:
if (start) *this<<"\"value\":";
else *this<<",";
break;
case menuOut::fmtIdx:
if (start) *this<<"\"idx\":";
else *this<<",";
break;
case menuOut::fmtCursor:
if (start) *this<<"\"cursor\":";
else *this<<",";
break;
case menuOut::fmtOpBody:
if (start) *this<<"\"body\":";
else *this<<",";
break;
case menuOut::fmtPreview:
if (start) *this<<"\"preview\":";
else *this<<",";
break;
default:break;
}
return proceed;
}
result fmtStart(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {return fmt(true,target,part,nav,idx);}
result fmtEnd(prompt& target,menuOut::fmtParts part,navNode &nav,idx_t idx=-1) override {return fmt(false,target,part,nav,idx);}
};
}//namespace
#endif
#endif