turbo-editors/turbo-corepublic Fork 0
v1.0.2
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

📦 Turbo Core f3ade8d · on v1.0.2 · k33g · 11h ago
example_test.go · 66 lines · 1.3 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package buffer_test

import (
	"fmt"

	"rickub.com/turbo-editors/turbo-core/buffer"
)

// Typing into a buffer and reading the result back.
func ExampleBuffer_Insert() {
	b := buffer.New()
	b.Insert("package main")
	b.InsertNewlineAndIndent()
	b.Insert("\nfunc main() {}")

	fmt.Println(b.Text())
	// Output:
	// package main
	//
	// func main() {}
}

// A run of typed characters is one undo step, not one per keystroke.
func ExampleBuffer_Undo() {
	b := buffer.NewFromString("var ")
	b.MoveBufferEnd()
	for _, r := range "count" {
		b.InsertRune(r)
	}
	fmt.Println(b.Text())

	b.Undo()
	fmt.Println(b.Text())
	// Output:
	// var count
	// var
}

// Selecting a span and replacing it in one go.
func ExampleBuffer_SelectedText() {
	b := buffer.NewFromString("hello world")
	b.SetCursor(buffer.Position{Line: 0, Col: 6})
	b.StartSelection()
	b.Extend(b.MoveLineEnd)

	fmt.Println(b.SelectedText())

	b.Insert("gophers")
	fmt.Println(b.Text())
	// Output:
	// world
	// hello gophers
}

// Tabs occupy several screen columns, so rune columns and screen columns are
// not the same thing.
func ExampleBuffer_DisplayColumn() {
	b := buffer.NewFromString("\tif err != nil {")
	b.SetTabWidth(4)

	fmt.Println(b.DisplayColumn(0, 1)) // just after the tab
	fmt.Println(b.RuneColumn(0, 4))    // back from the screen column
	// Output:
	// 4
	// 1
}