Example #1
0
func visibleLine() []rune {
	width := display.LineWidth()

	if len(currentLine) <= width {
		return currentLine
	}
	if len(currentLine) <= width+currentScroll {
		return currentLine[currentScroll:]
	}
	return currentLine[currentScroll : width+currentScroll]
}
Example #2
0
func CursorAtEnd() {
	width := display.LineWidth()
	cursor = len(currentLine)
	if len(currentLine) < width {
		currentScroll = 0
	} else {
		currentScroll = len(currentLine) - width
	}
	display.ShowLine(visibleLine())
	updateCursor()
}
Example #3
0
func CursorRight() {
	width := display.LineWidth()
	if cursor < len(currentLine) {
		cursor++
	}
	if cursor > width+currentScroll {
		// LogS(fmt.Sprintf("-- %d", cursor))
		currentScroll++
		display.ShowLine(visibleLine())
	}
	updateCursor()
}
Example #4
0
func AddRune(r rune) {
	// Log([]rune(fmt.Sprintf("%d, %d", len(currentLine), cursor)))
	if len(currentLine) <= cursor {
		currentLine = append(currentLine, r)
		cursor++
		checkScrollRight()
		return
	}
	copyLine := make([]rune, len(currentLine))
	copy(copyLine, currentLine)
	currentLine = append(append(copyLine[:cursor], r),
		currentLine[cursor:]...)
	if cursor-currentScroll >= display.LineWidth() {
		checkScrollRight()
	}
	cursor++
}
Example #5
0
func Backspace() {
	if cursor == 0 {
		return
	}
	width := display.LineWidth()
	if cursor-currentScroll <= 0 && currentScroll != 0 {
		currentScroll -= width
		updateCursor()
	}
	if len(currentLine) <= cursor {
		currentLine = currentLine[:cursor-1]
		cursor--
	} else {
		currentLine = append(currentLine[:cursor-1], currentLine[cursor:]...)
		cursor--
	}

	if cursor == width {
		currentScroll = 0
		updateCursor()
	}
}
Example #6
0
func checkScrollRight() {
	width := display.LineWidth()
	if len(currentLine)-currentScroll > width {
		currentScroll++
	}
}