From 89b8002d48b3e6d06e068e975fe1f28c124e2064 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Sun, 5 Aug 2018 22:34:51 +0100 Subject: [PATCH] started work on new buffer --- buffer/buffer.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/buffer/buffer.go b/buffer/buffer.go index 1eb5274..56cd86e 100644 --- a/buffer/buffer.go +++ b/buffer/buffer.go @@ -6,48 +6,49 @@ import ( type Buffer struct { lines []line - x int - y int - columnCount int - lineCount int + x uint16 + y uint16 + columnCount uint16 + viewHeight uint16 } // NewBuffer creates a new terminal buffer -func NewBuffer(columns int) *Buffer { +func NewBuffer() *Buffer { return &Buffer{ x: 0, y: 0, lines: []line{}, - columnCount: columns, + columnCount: 0, } } // Column returns cursor column -func (buffer *Buffer) Column() int { +func (buffer *Buffer) Column() uint16 { return buffer.x } // Line returns cursor line -func (buffer *Buffer) Line() int { +func (buffer *Buffer) Line() uint16 { return buffer.y } // Width returns the width of the buffer in columns -func (buffer *Buffer) Width() int { +func (buffer *Buffer) Width() uint16 { return buffer.columnCount } // Write will write a rune to the terminal at the position of the cursor, and increment the cursor position func (buffer *Buffer) Write(r rune) { - for buffer.Line() >= len(buffer.lines) { + for int(buffer.Line()) >= len(buffer.lines) { buffer.lines = append(buffer.lines, newLine()) } line := &buffer.lines[buffer.Line()] - for buffer.Column() >= len(line.cells) { + for int(buffer.Column()) >= len(line.cells) { line.cells = append(line.cells, newCell()) } cell := line.cells[buffer.Column()] cell.setRune(r) + buffer.incrementCursorPosition() } func (buffer *Buffer) incrementCursorPosition() { @@ -60,7 +61,7 @@ func (buffer *Buffer) incrementCursorPosition() { } } -func (buffer *Buffer) SetPosition(col int, line int) error { +func (buffer *Buffer) SetPosition(col uint16, line uint16) error { if buffer.x >= buffer.Width() { return fmt.Errorf("Cannot set cursor position: column %d is outside of the current buffer width (%d columns)", col, buffer.Width()) } @@ -69,6 +70,6 @@ func (buffer *Buffer) SetPosition(col int, line int) error { return nil } -func (buffer *Buffer) SetSize(cols int, lines int) { +func (buffer *Buffer) Resize(cols int, lines int) { }