write will write a rune to the terminal at the position of the cursor, and increment the cursor position
(runes ...MeasuredRune)
| 402 | |
| 403 | // write will write a rune to the terminal at the position of the cursor, and increment the cursor position |
| 404 | func (buffer *Buffer) write(runes ...MeasuredRune) { |
| 405 | |
| 406 | // scroll to bottom on input |
| 407 | buffer.scrollLinesFromBottom = 0 |
| 408 | |
| 409 | for _, r := range runes { |
| 410 | |
| 411 | line := buffer.getCurrentLine() |
| 412 | |
| 413 | if buffer.modes.ReplaceMode { |
| 414 | |
| 415 | if buffer.CursorColumn() >= buffer.Width() { |
| 416 | if buffer.modes.AutoWrap { |
| 417 | buffer.cursorPosition.Line++ |
| 418 | buffer.cursorPosition.Col = 0 |
| 419 | line = buffer.getCurrentLine() |
| 420 | |
| 421 | } else { |
| 422 | // no more room on line and wrapping is disabled |
| 423 | return |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | for int(buffer.CursorColumn()) >= len(line.cells) { |
| 428 | line.append(buffer.defaultCell(int(buffer.CursorColumn()) == len(line.cells))) |
| 429 | } |
| 430 | line.cells[buffer.cursorPosition.Col].attr = buffer.cursorAttr |
| 431 | line.cells[buffer.cursorPosition.Col].setRune(r) |
| 432 | buffer.incrementCursorPosition() |
| 433 | continue |
| 434 | } |
| 435 | |
| 436 | if buffer.CursorColumn() >= buffer.Width() { // if we're after the line, move to next |
| 437 | |
| 438 | if buffer.modes.AutoWrap { |
| 439 | |
| 440 | buffer.newLineEx(true) |
| 441 | |
| 442 | newLine := buffer.getCurrentLine() |
| 443 | if len(newLine.cells) == 0 { |
| 444 | newLine.append(buffer.defaultCell(true)) |
| 445 | } |
| 446 | cell := &newLine.cells[0] |
| 447 | cell.setRune(r) |
| 448 | cell.attr = buffer.cursorAttr |
| 449 | |
| 450 | } else { |
| 451 | // no more room on line and wrapping is disabled |
| 452 | return |
| 453 | } |
| 454 | |
| 455 | } else { |
| 456 | |
| 457 | for int(buffer.CursorColumn()) >= len(line.cells) { |
| 458 | line.append(buffer.defaultCell(int(buffer.CursorColumn()) == len(line.cells))) |
| 459 | } |
| 460 | |
| 461 | cell := &line.cells[buffer.CursorColumn()] |