|
@@ -8,7 +8,6 @@
|
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
#include <curses.h>
|
|
#include <curses.h>
|
|
|
-
|
|
|
|
|
#include "searchPattern.hh"
|
|
#include "searchPattern.hh"
|
|
|
#include "curseSplitOutput.hh"
|
|
#include "curseSplitOutput.hh"
|
|
|
#include "jsonObject.hh"
|
|
#include "jsonObject.hh"
|
|
@@ -42,7 +41,7 @@ CurseSplitOutput::~CurseSplitOutput()
|
|
|
void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::deque<JSonElement*> &roots)
|
|
void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::deque<JSonElement*> &roots)
|
|
|
{
|
|
{
|
|
|
nbInputs = inputName.size();
|
|
nbInputs = inputName.size();
|
|
|
- const t_Cursor screenSize = getScreenSize();
|
|
|
|
|
|
|
+ screenSize = getScreenSize();
|
|
|
selectedWin = 0;
|
|
selectedWin = 0;
|
|
|
destroyAllSubWin();
|
|
destroyAllSubWin();
|
|
|
subWindows.clear();
|
|
subWindows.clear();
|
|
@@ -370,15 +369,15 @@ bool CurseSplitOutput::jumpToNextSearch()
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const Optional<bool> CurseSplitOutput::redrawOneItemToWorkingWin(t_subWindow &w, const t_Cursor &screenSize)
|
|
|
|
|
|
|
+const Optional<bool> CurseSplitOutput::redrawOneItemToWorkingWin(t_subWindow &w)
|
|
|
{
|
|
{
|
|
|
bool result;
|
|
bool result;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
if (w.parentsIterators.empty())
|
|
if (w.parentsIterators.empty())
|
|
|
- result = redraw(w, screenSize, w.root);
|
|
|
|
|
|
|
+ result = redraw(w, w.root);
|
|
|
else
|
|
else
|
|
|
- result = redraw(w, screenSize, w.parentsIterators.top());
|
|
|
|
|
|
|
+ result = redraw(w, w.parentsIterators.top());
|
|
|
}
|
|
}
|
|
|
catch (SelectionOutOfRange &e)
|
|
catch (SelectionOutOfRange &e)
|
|
|
{
|
|
{
|
|
@@ -419,6 +418,7 @@ void CurseSplitOutput::onResizeHandler(const t_Cursor &screenSize)
|
|
|
size_t i =0;
|
|
size_t i =0;
|
|
|
destroyAllSubWin();
|
|
destroyAllSubWin();
|
|
|
clear();
|
|
clear();
|
|
|
|
|
+ this->screenSize = t_Cursor(screenSize);
|
|
|
|
|
|
|
|
for (t_subWindow &subwin: subWindows)
|
|
for (t_subWindow &subwin: subWindows)
|
|
|
{
|
|
{
|
|
@@ -432,7 +432,6 @@ void CurseSplitOutput::onResizeHandler(const t_Cursor &screenSize)
|
|
|
|
|
|
|
|
bool CurseSplitOutput::redraw()
|
|
bool CurseSplitOutput::redraw()
|
|
|
{
|
|
{
|
|
|
- const t_Cursor screenSize = getScreenSize();
|
|
|
|
|
short writingDone = (1 << nbInputs) -1;
|
|
short writingDone = (1 << nbInputs) -1;
|
|
|
|
|
|
|
|
workingWin = 0;
|
|
workingWin = 0;
|
|
@@ -463,7 +462,7 @@ bool CurseSplitOutput::redraw()
|
|
|
|
|
|
|
|
do
|
|
do
|
|
|
{
|
|
{
|
|
|
- const Optional<bool> wrote = redrawOneItemToWorkingWin(w, screenSize);
|
|
|
|
|
|
|
+ const Optional<bool> wrote = redrawOneItemToWorkingWin(w);
|
|
|
|
|
|
|
|
if (wrote.absent())
|
|
if (wrote.absent())
|
|
|
return false;
|
|
return false;
|
|
@@ -496,7 +495,7 @@ bool CurseSplitOutput::redraw()
|
|
|
{
|
|
{
|
|
|
if ((writingDone & (1 << workingWin)))
|
|
if ((writingDone & (1 << workingWin)))
|
|
|
{
|
|
{
|
|
|
- const Optional<bool> wrote = redrawOneItemToWorkingWin(w, screenSize);
|
|
|
|
|
|
|
+ const Optional<bool> wrote = redrawOneItemToWorkingWin(w);
|
|
|
|
|
|
|
|
if (wrote.absent())
|
|
if (wrote.absent())
|
|
|
return false;
|
|
return false;
|
|
@@ -511,7 +510,7 @@ bool CurseSplitOutput::redraw()
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, JSonContainer *item, bool opening)
|
|
|
|
|
|
|
+bool CurseSplitOutput::writeContainer(JSonContainer *item, bool opening)
|
|
|
{
|
|
{
|
|
|
char childDelimiter[2];
|
|
char childDelimiter[2];
|
|
|
t_subWindow &w = subWindows.at(workingWin);
|
|
t_subWindow &w = subWindows.at(workingWin);
|
|
@@ -524,27 +523,27 @@ bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, JSonContainer *it
|
|
|
if (!opening) // Display close brackets
|
|
if (!opening) // Display close brackets
|
|
|
{
|
|
{
|
|
|
w.cursor.first -= INDENT_LEVEL;
|
|
w.cursor.first -= INDENT_LEVEL;
|
|
|
- w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[1], maxSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
|
|
+ w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[1], screenSize.first, CurseSplitOutput::getFlag(item));
|
|
|
}
|
|
}
|
|
|
else if (collapsed.find((const JSonContainer *)item) != collapsed.end()) // inline collapsed
|
|
else if (collapsed.find((const JSonContainer *)item) != collapsed.end()) // inline collapsed
|
|
|
{
|
|
{
|
|
|
std::string ss;
|
|
std::string ss;
|
|
|
ss.append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
|
|
ss.append(&childDelimiter[0], 1).append(" ... ").append(&childDelimiter[1], 1);
|
|
|
- w.cursor.second += write(w.cursor.first, w.cursor.second, ss, 7, maxSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
|
|
+ w.cursor.second += write(w.cursor.first, w.cursor.second, ss, 7, screenSize.first, CurseSplitOutput::getFlag(item));
|
|
|
}
|
|
}
|
|
|
else // Display open brackets
|
|
else // Display open brackets
|
|
|
{
|
|
{
|
|
|
- w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[0], maxSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
- if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1)
|
|
|
|
|
|
|
+ w.cursor.second += write(w.cursor.first, w.cursor.second, childDelimiter[0], screenSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
+ if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1)
|
|
|
return false;
|
|
return false;
|
|
|
w.parentsIterators.push(std::pair<int, JSonContainer *>(-1, item));
|
|
w.parentsIterators.push(std::pair<int, JSonContainer *>(-1, item));
|
|
|
w.cursor.first += INDENT_LEVEL;
|
|
w.cursor.first += INDENT_LEVEL;
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- return (w.cursor.second < w.scrollTop || (w.cursor.second - w.scrollTop) <= maxSize.second -1);
|
|
|
|
|
|
|
+ return (w.cursor.second < w.scrollTop || (w.cursor.second - w.scrollTop) <= screenSize.second -1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen)
|
|
|
|
|
|
|
+bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, OutputFlag flags, unsigned int extraLen)
|
|
|
{
|
|
{
|
|
|
if (w.cursor.second <= w.scrollTop)
|
|
if (w.cursor.second <= w.scrollTop)
|
|
|
{
|
|
{
|
|
@@ -553,14 +552,14 @@ bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const si
|
|
|
}
|
|
}
|
|
|
char oldType = flags.type();
|
|
char oldType = flags.type();
|
|
|
flags.type(OutputFlag::TYPE_OBJKEY);
|
|
flags.type(OutputFlag::TYPE_OBJKEY);
|
|
|
- w.cursor.second += write(w.cursor.first, w.cursor.second, key, keylen, maxSize.first -extraLen -2, flags);
|
|
|
|
|
|
|
+ w.cursor.second += write(w.cursor.first, w.cursor.second, key, keylen, screenSize.first -extraLen -2, flags);
|
|
|
flags.type(OutputFlag::TYPE_OBJ);
|
|
flags.type(OutputFlag::TYPE_OBJ);
|
|
|
write(": ", flags);
|
|
write(": ", flags);
|
|
|
flags.type(oldType);
|
|
flags.type(oldType);
|
|
|
- return (w.cursor.second < w.scrollTop || (w.cursor.second - w.scrollTop) <= maxSize.second);
|
|
|
|
|
|
|
+ return (w.cursor.second < w.scrollTop || (w.cursor.second - w.scrollTop) <= screenSize.second);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag flags)
|
|
|
|
|
|
|
+bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, OutputFlag flags)
|
|
|
{
|
|
{
|
|
|
if (cursor.second <= w.scrollTop)
|
|
if (cursor.second <= w.scrollTop)
|
|
|
{
|
|
{
|
|
@@ -574,13 +573,13 @@ bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const si
|
|
|
write(": ", flags);
|
|
write(": ", flags);
|
|
|
flags.type(oldType);
|
|
flags.type(oldType);
|
|
|
write(after, flags);
|
|
write(after, flags);
|
|
|
- cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, maxWidth.first);
|
|
|
|
|
- return (cursor.second < w.scrollTop || (cursor.second - w.scrollTop) <= maxWidth.second);
|
|
|
|
|
|
|
+ cursor.second += getNbLines(cursor.first +keylen +2 +afterlen, screenSize.first);
|
|
|
|
|
+ return (cursor.second < w.scrollTop || (cursor.second - w.scrollTop) <= screenSize.second);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag flags)
|
|
|
|
|
|
|
+bool CurseSplitOutput::writeKey(t_subWindow &w, const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, OutputFlag flags)
|
|
|
{
|
|
{
|
|
|
- return writeKey(w, key, keylen, after, after.length(), cursor, maxWidth, flags);
|
|
|
|
|
|
|
+ return writeKey(w, key, keylen, after, after.length(), cursor, flags);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool CurseSplitOutput::isAdded(const JSonElement *e) const
|
|
bool CurseSplitOutput::isAdded(const JSonElement *e) const
|
|
@@ -599,7 +598,7 @@ bool CurseSplitOutput::isAdded(const std::pair<int, JSonContainer *> &item) cons
|
|
|
return isAdded(e);
|
|
return isAdded(e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::redraw(t_subWindow &w, const t_Cursor &maxSize, std::pair<int, JSonContainer *> &item)
|
|
|
|
|
|
|
+bool CurseSplitOutput::redraw(t_subWindow &w, std::pair<int, JSonContainer *> &item)
|
|
|
{
|
|
{
|
|
|
JSonElement *currentItem;
|
|
JSonElement *currentItem;
|
|
|
|
|
|
|
@@ -607,34 +606,34 @@ bool CurseSplitOutput::redraw(t_subWindow &w, const t_Cursor &maxSize, std::pair
|
|
|
if ((unsigned int) item.first == item.second->size())
|
|
if ((unsigned int) item.first == item.second->size())
|
|
|
{
|
|
{
|
|
|
w.parentsIterators.pop();
|
|
w.parentsIterators.pop();
|
|
|
- return writeContainer(maxSize, item.second, false);
|
|
|
|
|
|
|
+ return writeContainer(item.second, false);
|
|
|
}
|
|
}
|
|
|
currentItem = list_at<JSonElement*>(*(item.second), item.first);
|
|
currentItem = list_at<JSonElement*>(*(item.second), item.first);
|
|
|
- return redraw(w, maxSize, currentItem);
|
|
|
|
|
|
|
+ return redraw(w, currentItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::redraw(t_subWindow &w, const t_Cursor &maxSize, JSonElement *item)
|
|
|
|
|
|
|
+bool CurseSplitOutput::redraw(t_subWindow &w, JSonElement *item)
|
|
|
{
|
|
{
|
|
|
checkSelection(item);
|
|
checkSelection(item);
|
|
|
if (dynamic_cast<const JSonContainer*>(item))
|
|
if (dynamic_cast<const JSonContainer*>(item))
|
|
|
{
|
|
{
|
|
|
- if (!writeContainer(maxSize, (JSonContainer *) item))
|
|
|
|
|
|
|
+ if (!writeContainer((JSonContainer *) item))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
else if (dynamic_cast<JSonObjectEntry*>(item))
|
|
else if (dynamic_cast<JSonObjectEntry*>(item))
|
|
|
{
|
|
{
|
|
|
- return writeObjectEntry(w, maxSize, (JSonObjectEntry*) item);
|
|
|
|
|
|
|
+ return writeObjectEntry(w, (JSonObjectEntry*) item);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- w.cursor.second += CurseOutput::write(w.cursor.first, w.cursor.second, item, maxSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
- if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1)
|
|
|
|
|
|
|
+ w.cursor.second += CurseOutput::write(w.cursor.first, w.cursor.second, item, screenSize.first, CurseSplitOutput::getFlag(item));
|
|
|
|
|
+ if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1)
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CurseSplitOutput::writeObjectEntry(t_subWindow &w, const t_Cursor &maxSize, JSonObjectEntry *ent)
|
|
|
|
|
|
|
+bool CurseSplitOutput::writeObjectEntry(t_subWindow &w, JSonObjectEntry *ent)
|
|
|
{
|
|
{
|
|
|
bool isContainer = (dynamic_cast<JSonContainer *>(**ent) != nullptr);
|
|
bool isContainer = (dynamic_cast<JSonContainer *>(**ent) != nullptr);
|
|
|
std::string key = ent->stringify();
|
|
std::string key = ent->stringify();
|
|
@@ -643,36 +642,36 @@ bool CurseSplitOutput::writeObjectEntry(t_subWindow &w, const t_Cursor &maxSize,
|
|
|
{
|
|
{
|
|
|
if (dynamic_cast<JSonObject *>(**ent))
|
|
if (dynamic_cast<JSonObject *>(**ent))
|
|
|
{
|
|
{
|
|
|
- if (!writeKey(w, key, ent->lazystrlen(), "{ ... }", w.cursor, maxSize, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1))
|
|
|
|
|
|
|
+ if (!writeKey(w, key, ent->lazystrlen(), "{ ... }", w.cursor, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- else if (!writeKey(w, key, ent->lazystrlen(), "[ ... ]", w.cursor, maxSize, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1))
|
|
|
|
|
|
|
+ else if (!writeKey(w, key, ent->lazystrlen(), "[ ... ]", w.cursor, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
else if (!isContainer) // inline value
|
|
else if (!isContainer) // inline value
|
|
|
{
|
|
{
|
|
|
JSonElement *eContent = **ent;
|
|
JSonElement *eContent = **ent;
|
|
|
- if (!writeKey(w, key, ent->lazystrlen(), eContent->stringify(), eContent->lazystrlen(), w.cursor, maxSize, getFlag(ent))
|
|
|
|
|
- || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1))
|
|
|
|
|
|
|
+ if (!writeKey(w, key, ent->lazystrlen(), eContent->stringify(), eContent->lazystrlen(), w.cursor, getFlag(ent))
|
|
|
|
|
+ || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
else if (((JSonContainer*)(**ent))->size() == 0) // inline empty
|
|
else if (((JSonContainer*)(**ent))->size() == 0) // inline empty
|
|
|
{
|
|
{
|
|
|
if (dynamic_cast<const JSonObject *>(**ent) )
|
|
if (dynamic_cast<const JSonObject *>(**ent) )
|
|
|
{
|
|
{
|
|
|
- if (!writeKey(w, key, ent->lazystrlen(), "{ }", w.cursor, maxSize, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1))
|
|
|
|
|
|
|
+ if (!writeKey(w, key, ent->lazystrlen(), "{ }", w.cursor, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- else if (!writeKey(w, key, ent->lazystrlen(), "[ ]", w.cursor, maxSize, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1))
|
|
|
|
|
|
|
+ else if (!writeKey(w, key, ent->lazystrlen(), "[ ]", w.cursor, getFlag(ent)) || (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
else // Container
|
|
else // Container
|
|
|
{
|
|
{
|
|
|
- if (!writeKey(w, key, ent->lazystrlen(), maxSize, getFlag(ent)))
|
|
|
|
|
|
|
+ if (!writeKey(w, key, ent->lazystrlen(), getFlag(ent)))
|
|
|
return false;
|
|
return false;
|
|
|
- writeContainer(maxSize, (JSonContainer*)(**ent), true);
|
|
|
|
|
|
|
+ writeContainer((JSonContainer*)(**ent), true);
|
|
|
}
|
|
}
|
|
|
- if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1)
|
|
|
|
|
|
|
+ if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > screenSize.second -1)
|
|
|
return false;
|
|
return false;
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -792,7 +791,6 @@ void CurseSplitOutput::destroyAllSubWin()
|
|
|
|
|
|
|
|
void CurseSplitOutput::writeTopLine(const std::string &buffer, short color) const
|
|
void CurseSplitOutput::writeTopLine(const std::string &buffer, short color) const
|
|
|
{
|
|
{
|
|
|
- const t_Cursor screenSize = getScreenSize();
|
|
|
|
|
const size_t bufsize = buffer.size();
|
|
const size_t bufsize = buffer.size();
|
|
|
WINDOW *currentWin = subWindows.at(workingWin).innerWin;
|
|
WINDOW *currentWin = subWindows.at(workingWin).innerWin;
|
|
|
|
|
|