/// next reads the next rune from the bufferred reader. Returns the rune(0) if
        /// an error occurs (or io.EOF is returned).
        private char Next()
        {
            var(ch, size, err) = _buf.ReadRune();
            if (err)
            {
                // advance for error reporting
                _srcPos.Column++;
                _srcPos.Offset += size;
                _lastCharLen    = size;
                return(EOF);
            }

            if (ch == GoBuffer.RuneError && size == 1)
            {
                _srcPos.Column++;
                _srcPos.Offset += size;
                _lastCharLen    = size;
                Err("illegal UTF-8 encoding");
                return(ch);
            }

            // remember last position
            _prevPos = _srcPos;

            _srcPos.Column++;
            _lastCharLen    = size;
            _srcPos.Offset += size;

            if (ch == '\n')
            {
                _srcPos.Line++;
                _lastLineLen   = _srcPos.Column;
                _srcPos.Column = 0;
            }

            // If we see a null character with data left, then that is an error
            if (ch == '\x00' && _buf.Len() > 0)
            {
                Err("unexpected null character (0x00)");
                return(EOF);
            }

            // debug
            // fmt.Printf("ch: %q, offset:column: %d:%d\n", ch, s.srcPos.Offset, s.srcPos.Column)
            return(ch);
        }
        /// diff compares a and b.
        void Diff(string aname, string bname, slice <byte> a, slice <byte> b)
        {
            var buf = new GoBuffer(); // holding long error message

            // compare lengths
            if (a.Length != b.Length)
            {
                buf.WriteString($"\nlength changed: len({aname}) = {a.Length},"
                                + " len({bname}) = {b.Length}");
            }

            // compare contents
            var line = 1;
            var offs = 1;

            for (var i = 0; i < a.Length && i < b.Length; i++)
            {
                var ch = a[i];
                if (ch != b[i])
                {
                    buf.WriteString(string.Format("\n{0}:{1}:{2}: {3}", aname, line, i - offs + 1,
                                                  LineAt(a, offs)));
                    buf.WriteString(string.Format("\n{0}:{1}:{2}: {3}", bname, line, i - offs + 1,
                                                  LineAt(b, offs)));
                    buf.WriteString("\n\n");
                    break;
                }
                if (ch == '\n')
                {
                    line++;
                    offs = i + 1;
                }
            }

            if (buf.Len() > 0)
            {
                throw new IOException(buf.ToString());
            }
        }
 // Update the cell width.
 private void UpdateWidth()
 {
     cell.width += Utf8.RuneCount(buf.Bytes().Slice(pos, buf.Len()).ToArray());
     pos         = buf.Len();
 }