Skip to content

Commit

Permalink
I have yet to find the reason for the crash on reverseIndex reported …
Browse files Browse the repository at this point in the history
…on bug #256, adding some logging rather than a crash, hoping to find out why
  • Loading branch information
migueldeicaza committed Feb 10, 2023
1 parent 71bc772 commit 550a805
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
28 changes: 23 additions & 5 deletions Sources/SwiftTerm/CircularList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,29 @@ class CircularList<T> {
self.count -= count
}

func shiftElements (start: Int, count: Int, offset: Int)
func shiftElements (start: Int, count: Int, offset: Int) -> Bool
{
precondition (count > 0)
precondition (start >= 0)
precondition(start < self.count)
precondition (start+offset > 0)
func dumpState (_ msg: String) -> Bool {
print ("Assertion at start=\(start) count=\(count) offset=\(offset): \(msg)")
return false
}

if count < 0 {
return dumpState ("count < 0")
}
if start < 0 {
return dumpState ("start < 0")
}
if start >= self.count {
return dumpState ("start >= self.count")
}
if start+offset <= 0 {
return dumpState ("start+offset <= 0")
}
// precondition (count > 0)
// precondition (start >= 0)
// precondition (start < self.count)
// precondition (start+offset > 0)
if offset > 0 {
for i in (0..<count).reversed() {
self [start + i + offset] = self [start + i]
Expand All @@ -186,6 +203,7 @@ class CircularList<T> {
self [start + i + offset] = self [start + i]
}
}
return true
}

var isFull: Bool {
Expand Down
9 changes: 7 additions & 2 deletions Sources/SwiftTerm/Terminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4678,7 +4678,9 @@ open class Terminal {
// scrollback, instead we can just shift them in-place.
let scrollRegionHeight = bottomRow - topRow + 1 /*as it's zero-based*/
if scrollRegionHeight > 1 {
buffer.lines.shiftElements (start: topRow + 1, count: scrollRegionHeight - 1, offset: -1)
if !buffer.lines.shiftElements (start: topRow + 1, count: scrollRegionHeight - 1, offset: -1) {
print ("Assertion on scroll, state was: bottomRow=\(bottomRow) topRow=\(topRow) yDisp=\(buffer.yDisp) linesTop=\(buffer.linesTop) isAlternate=\(buffers.isAlternateBuffer)")
}
}
buffer.lines [bottomRow] = BufferLine (from: newLine)
}
Expand Down Expand Up @@ -4980,13 +4982,16 @@ open class Terminal {

func reverseIndex ()
{
let buffer = self.buffer
restrictCursor()
if buffer.y == buffer.scrollTop {
// possibly move the code below to term.reverseScroll()
// test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
// blankLine(true) is xterm/linux behavior
let scrollRegionHeight = buffer.scrollBottom - buffer.scrollTop
buffer.lines.shiftElements (start: buffer.y + buffer.yBase, count: scrollRegionHeight, offset: 1)
if !buffer.lines.shiftElements (start: buffer.y + buffer.yBase, count: scrollRegionHeight, offset: 1) {
print ("Assertion on reverseIndex, state was: y=\(buffer.y) scrollTop=\(buffer.scrollTop) yDisp=\(buffer.yDisp) linesTop=\(buffer.linesTop) isAlternate=\(buffers.isAlternateBuffer)")
}
buffer.lines [buffer.y + buffer.yBase] = buffer.getBlankLine (attribute: eraseAttr ())
updateRange (startLine: buffer.scrollTop, endLine: buffer.scrollBottom)
} else if buffer.y > 0 {
Expand Down

0 comments on commit 550a805

Please sign in to comment.