mirror of https://github.com/liamg/aminal.git
started work on new buffer
This commit is contained in:
parent
cc2aa87e5d
commit
89b8002d48
|
@ -6,48 +6,49 @@ import (
|
||||||
|
|
||||||
type Buffer struct {
|
type Buffer struct {
|
||||||
lines []line
|
lines []line
|
||||||
x int
|
x uint16
|
||||||
y int
|
y uint16
|
||||||
columnCount int
|
columnCount uint16
|
||||||
lineCount int
|
viewHeight uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuffer creates a new terminal buffer
|
// NewBuffer creates a new terminal buffer
|
||||||
func NewBuffer(columns int) *Buffer {
|
func NewBuffer() *Buffer {
|
||||||
return &Buffer{
|
return &Buffer{
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
lines: []line{},
|
lines: []line{},
|
||||||
columnCount: columns,
|
columnCount: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Column returns cursor column
|
// Column returns cursor column
|
||||||
func (buffer *Buffer) Column() int {
|
func (buffer *Buffer) Column() uint16 {
|
||||||
return buffer.x
|
return buffer.x
|
||||||
}
|
}
|
||||||
|
|
||||||
// Line returns cursor line
|
// Line returns cursor line
|
||||||
func (buffer *Buffer) Line() int {
|
func (buffer *Buffer) Line() uint16 {
|
||||||
return buffer.y
|
return buffer.y
|
||||||
}
|
}
|
||||||
|
|
||||||
// Width returns the width of the buffer in columns
|
// Width returns the width of the buffer in columns
|
||||||
func (buffer *Buffer) Width() int {
|
func (buffer *Buffer) Width() uint16 {
|
||||||
return buffer.columnCount
|
return buffer.columnCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write will write a rune to the terminal at the position of the cursor, and increment the cursor position
|
// 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) {
|
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())
|
buffer.lines = append(buffer.lines, newLine())
|
||||||
}
|
}
|
||||||
line := &buffer.lines[buffer.Line()]
|
line := &buffer.lines[buffer.Line()]
|
||||||
for buffer.Column() >= len(line.cells) {
|
for int(buffer.Column()) >= len(line.cells) {
|
||||||
line.cells = append(line.cells, newCell())
|
line.cells = append(line.cells, newCell())
|
||||||
}
|
}
|
||||||
cell := line.cells[buffer.Column()]
|
cell := line.cells[buffer.Column()]
|
||||||
cell.setRune(r)
|
cell.setRune(r)
|
||||||
|
buffer.incrementCursorPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *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() {
|
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())
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (buffer *Buffer) SetSize(cols int, lines int) {
|
func (buffer *Buffer) Resize(cols int, lines int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue