Modified the json format and colon color

master
David Volovskiy 2025-04-20 15:02:19 -04:00
parent 441980f45a
commit dff1259813
1 changed files with 22 additions and 27 deletions

View File

@ -115,31 +115,26 @@ let loadJson = function() {
const vals = getVal(now, location); const vals = getVal(now, location);
//vals.steps = null; // For testing; uncomment to see the steps not appear //vals.steps = null; // For testing; uncomment to see the steps not appear
//location.location = null; // For testing, if null, the time becomes an struct to take up sun's struct //location.location = null; // For testing, if null, the time becomes an struct to take up sun's struct
let raw; const hasLoc = location.location !== null;
let raw = {
if (location.location !== null) { time: hasLoc
raw = { ? vals.time
time: vals.time, : {
dt: vals.date,
sun: {
rise: vals.rise,
set: vals.set,
},
"batt_%": vals.batt_pct,
};
} else {
raw = {
time: {
hr: getHr(now.getHours())[0], hr: getHr(now.getHours())[0],
min: now.getMinutes(), min: now.getMinutes(),
}, },
dt: vals.date, dt: vals.date,
"batt_%": vals.batt_pct, "batt_%": vals.batt_pct,
}; };
if (vals.steps != null) {
raw.steps = vals.steps;
}
if (hasLoc) {
raw.sun = {
rise: vals.rise,
set: vals.set,
};
} }
if (vals.steps != null) raw.steps = vals.steps;
jsonText = JSON.stringify(raw, null, 2); jsonText = JSON.stringify(raw, null, 2);
lines = jsonText.split("\n"); lines = jsonText.split("\n");
}; };
@ -190,10 +185,10 @@ let redraw = function() {
// Key // Key
g.setColor(clrs.keys); g.setColor(clrs.keys);
g.drawString(indent + `"${key}"`, numWidth, y); const keyText = indent + `"${key}": `
const keyWidth = g.stringWidth(indent + `"${key}"`); g.drawString(keyText, numWidth, y);
const keyWidth = g.stringWidth(keyText);
const valueX = numWidth + keyWidth; const valueX = numWidth + keyWidth;
const valueText = ": " + value;
// Value color // Value color
if (value.startsWith('"')) { if (value.startsWith('"')) {
@ -203,7 +198,7 @@ let redraw = function() {
} else { } else {
g.setColor(clrs.ints); g.setColor(clrs.ints);
} }
g.drawString(valueText, valueX, y); g.drawString(value, valueX, y);
valuePositions.push({ valuePositions.push({
key, key,