Bladeren bron

[tmp] WIP borken displaying diff

B Thibault 9 jaren geleden
bovenliggende
commit
d1b4e61977

+ 0 - 8
include/curseOutput.hh

@@ -128,17 +128,9 @@ class CurseOutput
         unsigned int write(const int &x, const int &y, JSonElement *item, unsigned int maxWidth, const OutputFlag);
         virtual unsigned int write(const int &x, const int &y, const std::string &item, const size_t len, unsigned int maxWidth, const OutputFlag) =0;
         virtual unsigned int write(const int &x, const int &y, const char item, unsigned int maxWidth, const OutputFlag) =0;
-        /*
-        virtual bool writeKey(const std::string &key, const size_t keylen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag, unsigned int extraLen =0) =0;
-        */
         virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag) =0;
         virtual bool writeKey(const std::string &key, const size_t keylen, const std::string &after, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);
 
-        /*
-        virtual bool writeContainer(t_Cursor &, const t_Cursor &maxSize, const JSonContainer *) =0;
-        virtual bool writeContent(t_Cursor &cursor, const t_Cursor &maxSize, std::list<JSonElement *> * obj) =0;
-        */
-
         /**
          * prompt for user input, and return it
          * @throws noInputException if user use a kill-key (to exit buffer)

+ 5 - 4
include/curseSplitOutput.hh

@@ -17,8 +17,8 @@ typedef struct
     std::list<const JSonElement*> searchResults;
     unsigned int scrollTop;
     t_Cursor cursor;
-    std::stack<const JSonElement *> parentsIterators;
-    bool selectFound, selectIsLast, inAddOrDeletion;
+    std::stack<JSonContainer::const_iterator> parentsIterators;
+    bool selectFound, selectIsLast;
 } t_subWindow;
 
 class CurseSplitOutput: public CurseOutput
@@ -35,9 +35,10 @@ class CurseSplitOutput: public CurseOutput
         void checkSelection(const JSonElement *item);
 
         bool redraw();
-        bool redraw(const t_Cursor &screenSize, JSonElement *);
+        bool redraw(const t_Cursor &screenSize, JSonContainer::const_iterator, bool isRoot =false);
+        bool redraw(const t_Cursor &screenSize, JSonElement *, bool isRoot =false);
 
-        bool writeContainer(const t_Cursor &maxSize, const JSonContainer *);
+        bool writeContainer(const t_Cursor &maxSize, JSonContainer *);
         bool writeContent(const t_Cursor &maxSize, std::list<JSonElement*> *_item);
         bool writeKey(const std::string &key, const size_t keylen, const t_Cursor &maxSize, OutputFlag flags, unsigned int extraLen =0);
         bool writeKey(const std::string &key, const size_t keylen, const std::string &after, const size_t afterlen, t_Cursor &cursor, const t_Cursor &maxWidth, OutputFlag);

+ 15 - 0
include/levenshteinMatrice.hpp

@@ -144,6 +144,21 @@ class LevenshteinMatrice: public LevenshteinMatrice_base
             delete []subMatrice;
         };
 
+        void addRoot(const JSonContainer *a, const JSonContainer *b)
+        {
+            if (levenRelativeDist < LEVENSHTEIN_SENSIBILITY)
+            {
+                operations[a] = eLevenshteinOperator::add;
+                operations[b] = eLevenshteinOperator::add;
+            }
+            else
+            {
+                operations[a] = operations[b] = levenRelativeDist < 1.f ? eLevenshteinOperator::mod : eLevenshteinOperator::equ;
+                equivalences[a] = b;
+                equivalences[b] = a;
+            }
+        }
+
         std::map<const JSonElement*, const JSonElement *> getEquivalences() const;
 
         size_t result() const;

+ 101 - 46
src/curseSplitOutput.cpp

@@ -198,13 +198,6 @@ void CurseSplitOutput::checkSelection(const JSonElement *item)
 {
     t_subWindow &w = subWindows.at(workingWin);
 
-    if (diffMatrice->getEquivalence(item))
-    {
-        if (w.inAddOrDeletion)
-            throw CurseSplitOutput::reachNext();
-    }
-    else
-        w.inAddOrDeletion = true;
     if (!w.selectFound)
     {
         if (w.selection == item)
@@ -316,6 +309,7 @@ bool CurseSplitOutput::jumpToNextSearch()
 bool CurseSplitOutput::redraw()
 {
     const t_Cursor screenSize = getScreenSize();
+    short writingDone = (1 << nbInputs) -1;
 
     workingWin = 0;
     for (t_subWindow &w : subWindows)
@@ -327,51 +321,59 @@ bool CurseSplitOutput::redraw()
         wclear(w.innerWin);
         writeTopLine(w.fileName,
                 workingWin == selectedWin ? OutputFlag::SPECIAL_ACTIVEINPUTNAME : OutputFlag::SPECIAL_INPUTNAME);
+        w.parentsIterators = std::stack<JSonContainer::const_iterator>();
         ++workingWin;
     }
-    workingWin = 0;
-    for (t_subWindow &w : subWindows)
+    while (writingDone)
     {
-        bool result;
-
-        w.inAddOrDeletion = false;
-        try {
-            //TODO JSonElement by JSonElement instead of file per file
-            result = redraw(screenSize, w.root);
-        }
-        catch (SelectionOutOfRange &e)
+        workingWin = 0;
+        for (t_subWindow &w : subWindows)
         {
-            return false;
-        }
-        catch (CurseSplitOutput::reachNext &)
-        {
-            ++workingWin;
-            continue;
-        }
-        if (!result)
-        {
-            if (!w.selectFound)
+            bool result;
+
+            if ((writingDone & (1 << workingWin)) == 0)
+                continue;
+            try {
+                if (w.parentsIterators.empty())
+                    result = redraw(screenSize, w.root, true);
+                else
+                    result = redraw(screenSize, w.parentsIterators.top(), true);
+            }
+            catch (SelectionOutOfRange &e)
             {
-                w.scrollTop++;
                 return false;
             }
+            catch (CurseSplitOutput::reachNext &)
+            {
+                ++workingWin;
+                continue;
+            }
+            if (!result)
+            {
+                if (!w.selectFound)
+                {
+                    w.scrollTop++;
+                    return false;
+                }
+                if (!w.select_down)
+                    w.selectIsLast = true;
+            }
             if (!w.select_down)
-                w.selectIsLast = true;
-        }
-        if (!w.select_down)
-        {
-            const JSonContainer *pselect = dynamic_cast<const JSonContainer*>(w.selection);
-            if (pselect && !pselect->empty())
-                w.select_down = *(pselect->cbegin());
-            else
             {
-                const JSonElement *next = w.selection->findNext();
-                w.select_down = next ? next : w.selection;
+                const JSonContainer *pselect = dynamic_cast<const JSonContainer*>(w.selection);
+                if (pselect && !pselect->empty())
+                    w.select_down = *(pselect->cbegin());
+                else
+                {
+                    const JSonElement *next = w.selection->findNext();
+                    w.select_down = next ? next : w.selection;
+                }
             }
+            if (!w.select_up)
+                w.select_up = subWindows.at(workingWin).selection;
+            writingDone &= ~(1 << workingWin);
+            ++workingWin;
         }
-        if (!w.select_up)
-            w.select_up = subWindows.at(workingWin).selection;
-        ++workingWin;
     }
     for (t_subWindow &w : subWindows)
     {
@@ -380,7 +382,7 @@ bool CurseSplitOutput::redraw()
     return true;
 }
 
-bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, const JSonContainer *item)
+bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, JSonContainer *item)
 {
     char childDelimiter[2];
     t_subWindow &w = subWindows.at(workingWin);
@@ -400,8 +402,8 @@ bool CurseSplitOutput::writeContainer(const t_Cursor &maxSize, const JSonContain
     {
         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)
-                return false;
-        w.parentsIterators.push(item);
+            return false;
+        w.parentsIterators.push(item->cbegin());
         if (!writeContent(maxSize, (std::list<JSonElement *> *)item))
         {
             w.parentsIterators.pop();
@@ -525,19 +527,72 @@ bool CurseSplitOutput::writeKey(const std::string &key, const size_t keylen, con
     return (cursor.second < w.scrollTop || (cursor.second - w.scrollTop) <= maxWidth.second);
 }
 
-bool CurseSplitOutput::redraw(const t_Cursor &maxSize, JSonElement *item)
+bool CurseSplitOutput::redraw(const t_Cursor &maxSize, JSonContainer::const_iterator item, bool isRoot)
+{
+    t_subWindow &w = subWindows.at(workingWin);
+    static short dirty =0;
+    JSonContainer *parent;
+    JSonContainer::const_iterator next = item;
+
+    if (dirty && !isRoot)
+        throw CurseSplitOutput::reachNext();
+    dirty = 1;
+    next++;
+    w.parentsIterators.pop();
+    if (w.parentsIterators.size() <= 1)
+        parent = (JSonContainer *) w.root;
+    else
+        parent = (JSonContainer *) (*(w.parentsIterators.top()));
+    if (item != parent->cend())
+        w.parentsIterators.push(next);
+    else
+    {
+        //TODO close brackets
+        return true;
+    }
+    checkSelection(*item);
+    if (dynamic_cast<const JSonContainer*>(*item))
+    {
+        if (!writeContainer(maxSize, (JSonContainer*) (*item)))
+        {
+            dirty = 0;
+            return false;
+        }
+        dirty = 0;
+    }
+    else
+    {
+        w.cursor.second += CurseOutput::write(w.cursor.first, w.cursor.second, *item, maxSize.first, CurseSplitOutput::getFlag(*item));
+        dirty = 0;
+        if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1)
+            return false;
+    }
+    return true;
+}
+
+bool CurseSplitOutput::redraw(const t_Cursor &maxSize, JSonElement *item, bool isRoot)
 {
+    static short dirty =0;
+
+    if (dirty && !isRoot)
+        throw CurseSplitOutput::reachNext();
+    dirty = 1;
     checkSelection(item);
     if (dynamic_cast<const JSonContainer*>(item))
     {
-        if (!writeContainer(maxSize, (const JSonContainer *) item))
+        if (!writeContainer(maxSize, (JSonContainer *) item))
+        {
+            dirty = 0;
             return false;
+        }
+        dirty = 0;
     }
     else
     {
         t_subWindow &w = subWindows.at(workingWin);
 
         w.cursor.second += CurseOutput::write(w.cursor.first, w.cursor.second, item, maxSize.first, CurseSplitOutput::getFlag(item));
+        dirty = 0;
         if (w.cursor.second > w.scrollTop && (w.cursor.second - w.scrollTop) > maxSize.second -1)
             return false;
     }

+ 9 - 4
src/levenshtein.cpp

@@ -55,11 +55,16 @@ LevenshteinMatrice_base *LevenshteinMatrice_base::Builder::build(const JSonEleme
         const JSonContainer::const_iterator aBegin = ((const JSonContainer*)a)->cbegin();
         const JSonContainer::const_iterator bBegin = ((const JSonContainer*)b)->cbegin();
 
+        LevenshteinMatrice *result = nullptr;
+
         if (lenA < UCHAR_MAX && lenB < UCHAR_MAX)
-            return LevenshteinMatrice::build<unsigned char>(aBegin, bBegin, lenA, lenB);
-        if (lenA < USHRT_MAX && lenB < USHRT_MAX)
-            return LevenshteinMatrice::build<unsigned short>(aBegin, bBegin, lenA, lenB);
-        return LevenshteinMatrice::build<unsigned int>(aBegin, bBegin, lenA, lenB);
+            result = LevenshteinMatrice::build<unsigned char>(aBegin, bBegin, lenA, lenB);
+        else if (lenA < USHRT_MAX && lenB < USHRT_MAX)
+            result = LevenshteinMatrice::build<unsigned short>(aBegin, bBegin, lenA, lenB);
+        else
+            result = LevenshteinMatrice::build<unsigned int>(aBegin, bBegin, lenA, lenB);
+        result->addRoot((const JSonContainer *)a, (const JSonContainer *)b);
+        return result;
     }
     else if (aIsContainer)
     {

+ 1 - 0
test/testDiffItemEq.1.json

@@ -0,0 +1 @@
+true

+ 1 - 0
test/testDiffItemEq.2.json

@@ -0,0 +1 @@
+true

+ 1 - 0
test/testDiffItemEq.3.json

@@ -0,0 +1 @@
+false