Пример #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]
}
Пример #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()
}
Пример #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()
}
Пример #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++
}
Пример #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()
	}
}
Пример #6
0
func checkScrollRight() {
	width := display.LineWidth()
	if len(currentLine)-currentScroll > width {
		currentScroll++
	}
}