diff --git a/libcanvas/CanvasExportStore.py b/libcanvas/CanvasExportStore.py index 012c97b..fb2ab9a 100644 --- a/libcanvas/CanvasExportStore.py +++ b/libcanvas/CanvasExportStore.py @@ -166,7 +166,7 @@ class CanvasExportStore(): def exportTextBuffer(self, canvasMap, canvasSize): outBuffer = "" for canvasRow in range(canvasSize[1]): - canvasLastColours = [15, 1] + canvasLastColours = [15, -1] for canvasCol in range(canvasSize[0]): canvasColColours = canvasMap[canvasRow][canvasCol][0:2] canvasColText = canvasMap[canvasRow][canvasCol][3] @@ -176,12 +176,9 @@ class CanvasExportStore(): and (canvasColColours[1] != canvasLastColours[1]): if (canvasColColours[0] == -1) \ and (canvasColColours[1] == -1): - outBuffer += "\u0003 " + outBuffer += "\u000f" elif canvasColColours[1] == -1: outBuffer += "\u0003\u0003{}".format(canvasColColours[0]) - elif (canvasColColours[0] == canvasLastColours[1]) \ - and (canvasColColours[1] == canvasLastColours[0]): - outBuffer += "\u0016" else: outBuffer += "\u0003{},{}".format(canvasColColours[0], canvasColColours[1]) canvasLastColours = canvasColColours @@ -192,7 +189,10 @@ class CanvasExportStore(): outBuffer += "\u0003{},{}".format(canvasLastColours[0], canvasColColours[1]) canvasLastColours[1] = canvasColColours[1] elif canvasColColours[0] != canvasLastColours[0]: - outBuffer += "\u0003{}".format(canvasColColours[0]) + if canvasColColours[0] == -1: + outBuffer += "\u000f" + else: + outBuffer += "\u0003{}".format(canvasColColours[0]) canvasLastColours[0] = canvasColColours[0] outBuffer += canvasColText outBuffer += "\n" diff --git a/libcanvas/CanvasImportStore.py b/libcanvas/CanvasImportStore.py index 6e62e65..cfd8179 100644 --- a/libcanvas/CanvasImportStore.py +++ b/libcanvas/CanvasImportStore.py @@ -24,7 +24,7 @@ class CanvasImportStore(): # {{{ importAnsiBuffer(self, inBuffer, encoding="cp437", width=None) def importAnsiBuffer(self, inBuffer, encoding="cp437", width=None): - curBg, curBgAnsi, curBoldAnsi, curFg, curFgAnsi = 1, 30, False, 15, 37 + curBg, curBgAnsi, curBoldAnsi, curFg, curFgAnsi = -1, 30, False, 15, 37 done, outMap, outMaxCols = False, [[]], 0 inBufferData = inBuffer.decode(encoding) inBufferChar, inBufferCharMax = 0, len(inBufferData) @@ -40,7 +40,7 @@ class CanvasImportStore(): newBg, newFg = -1, -1 for ansiCode in [int(c) for c in m[1][:-1].split(";")]: if ansiCode == 0: - curBgAnsi, curBoldAnsi, curFgAnsi, newBg, newFg = 30, False, 37, 1, 15 + curBgAnsi, curBoldAnsi, curFgAnsi, newBg, newFg = 30, False, 37, -1, 15 elif ansiCode == 1: curBoldAnsi, newFg = True, AnsiFgBoldToMiRCARTColours[curFgAnsi] elif ansiCode == 2: @@ -69,7 +69,7 @@ class CanvasImportStore(): or ((len(outMap) == 1) and len(outMap[0])): for numRow in range(len(outMap)): for numCol in range(len(outMap[numRow]), outMaxCols): - outMap[numRow].append([curFg, curBg, self._CellState.CS_NONE, " "]) + outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "]) self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap return (True, None) else: @@ -95,7 +95,7 @@ class CanvasImportStore(): def importTextBuffer(self, inFile): inLine, outMap, outMaxCols = inFile.readline(), [], 0 while inLine: - inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, 1), len(inLine); outMap.append([]); + inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, -1), len(inLine); outMap.append([]); while inCurCol < inMaxCol: inChar = inLine[inCurCol] if inChar in set("\r\n"): @@ -110,14 +110,14 @@ class CanvasImportStore(): elif (m[2] != None) and (m[3] == None): inCurColours = (int(m[2]), int(inCurColours[1])) else: - inCurColours = (15, 1) + inCurColours = (15, -1) inCurCol += len(m[0]) else: - inCurColours = (15, 1); inCurCol += 1; + inCurColours = (15, -1); inCurCol += 1; elif inChar == "\u0006": inCellState = self._flipCellStateBit(self._CellState.CS_ITALIC, inCellState); inCurCol += 1; elif inChar == "\u000f": - inCellState |= self._CellState.CS_NONE; inCurColours = (15, 1); inCurCol += 1; + inCellState |= self._CellState.CS_NONE; inCurColours = (15, -1); inCurCol += 1; elif inChar == "\u0016": inCurColours = (inCurColours[1], inCurColours[0]); inCurCol += 1; elif inChar == "\u001f": @@ -127,6 +127,9 @@ class CanvasImportStore(): inLine, outMaxCols = inFile.readline(), max(outMaxCols, len(outMap[-1])) if (len(outMap) > 1) \ or ((len(outMap) == 1) and len(outMap[0])): + for numRow in range(len(outMap)): + for numCol in range(len(outMap[numRow]), outMaxCols): + outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "]) self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap return (True, None) else: