Skip to content

EN02_Default_Text

HAYAMA_Kaoru edited this page Oct 11, 2023 · 1 revision

A default text can be stored at startup.

package main

import (
	"context"
	"fmt"

	"github.com/nyaosorg/go-readline-ny"
)

func main() {
	var editor readline.Editor

	editor.Default = "previous value"
	editor.Cursor = 2

	text, err := editor.ReadLine(context.Background())
	if err != nil {
		fmt.Printf("ERR=%s\n", err.Error())
	} else {
		fmt.Printf("TEXT=%s\n", text)
	}
}

When you run this, the "previous value" will be entered as the default value, and the cursor will blink at the second character counting from 0, or the third character counting from 1.

image