diff --git a/cellbuf/cell.go b/cellbuf/cell.go index f5b14a25..a99a1570 100644 --- a/cellbuf/cell.go +++ b/cellbuf/cell.go @@ -52,15 +52,15 @@ func (c *Cell) Equal(o *Cell) bool { c.Width == o.Width && c.Rune == o.Rune && runesEqual(c.Comb, o.Comb) && - c.Style.Equal(o.Style) && - c.Link.Equal(o.Link) + c.Style.Equal(&o.Style) && + c.Link.Equal(&o.Link) } // Empty returns whether the cell is empty. func (c Cell) Empty() bool { - return c.Rune == 0 && + return c.Width == 0 && + c.Rune == 0 && len(c.Comb) == 0 && - c.Width == 0 && c.Style.Empty() && c.Link.Empty() } @@ -114,8 +114,8 @@ func (h *Link) Reset() { } // Equal returns whether the hyperlink is equal to the other hyperlink. -func (h Link) Equal(o Link) bool { - return h == o +func (h *Link) Equal(o *Link) bool { + return o != nil && h.URL == o.URL && h.URLID == o.URLID } // Empty returns whether the hyperlink is empty. @@ -320,12 +320,12 @@ func (s Style) DiffSequence(o Style) string { } // Equal returns true if the style is equal to the other style. -func (s Style) Equal(o Style) bool { - return colorEqual(s.Fg, o.Fg) && +func (s *Style) Equal(o *Style) bool { + return s.Attrs == o.Attrs && + s.UlStyle == o.UlStyle && + colorEqual(s.Fg, o.Fg) && colorEqual(s.Bg, o.Bg) && - colorEqual(s.Ul, o.Ul) && - s.Attrs == o.Attrs && - s.UlStyle == o.UlStyle + colorEqual(s.Ul, o.Ul) } func colorEqual(c, o ansi.Color) bool { diff --git a/cellbuf/screen.go b/cellbuf/screen.go index 8f2497f0..f6d62aab 100644 --- a/cellbuf/screen.go +++ b/cellbuf/screen.go @@ -63,10 +63,6 @@ func relativeCursorMove(s *Screen, fx, fy, tx, ty int, overwrite, useTabs bool) if cuu := ansi.CursorUp(n); yseq == "" || len(cuu) < len(yseq) { yseq = cuu } - if n == 1 && fy-1 > 0 { - // TODO: Ensure we're not unintentionally scrolling the screen up. - yseq = ansi.ReverseIndex - } } seq.WriteString(yseq) @@ -117,9 +113,9 @@ func relativeCursorMove(s *Screen, fx, fy, tx, ty int, overwrite, useTabs bool) if overwrite && ty >= 0 { for i := 0; i < n; i++ { cell := s.newbuf.Cell(fx+i, ty) - if cell != nil { + if cell != nil && cell.Width > 0 { i += cell.Width - 1 - if !cell.Style.Equal(s.cur.Style) || !cell.Link.Equal(s.cur.Link) { + if !cell.Style.Equal(&s.cur.Style) || !cell.Link.Equal(&s.cur.Link) { overwrite = false break } @@ -130,7 +126,7 @@ func relativeCursorMove(s *Screen, fx, fy, tx, ty int, overwrite, useTabs bool) if overwrite && ty >= 0 { for i := 0; i < n; i++ { cell := s.newbuf.Cell(fx+i, ty) - if cell != nil { + if cell != nil && cell.Width > 0 { ovw += cell.String() i += cell.Width - 1 } else { @@ -623,7 +619,7 @@ func (s *Screen) updatePen(cell *Cell) { link = ConvertLink(link, s.opts.Profile) } - if !style.Equal(s.cur.Style) { + if !style.Equal(&s.cur.Style) { seq := style.DiffSequence(s.cur.Style) if style.Empty() && len(seq) > len(ansi.ResetStyle) { seq = ansi.ResetStyle @@ -631,7 +627,7 @@ func (s *Screen) updatePen(cell *Cell) { s.buf.WriteString(seq) //nolint:errcheck s.cur.Style = style } - if !link.Equal(s.cur.Link) { + if !link.Equal(&s.cur.Link) { s.buf.WriteString(ansi.SetHyperlink(link.URL, link.URLID)) //nolint:errcheck s.cur.Link = link }