Skip to content

Unexpected behaviour when sending SIGINT to long prompts #157

@adamroyjones

Description

@adamroyjones

I'm running Debian (sid) with Alacritty as my terminal emulator. (I can also reproduce the issue below with Gnome Terminal.)

If I call the Prompt method with a long string and then send a SIGINT, the program will exit (with a status code of 1) instead of cancelling the prompt. This example reproduces it:

package main

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/peterh/liner"
)

func main() {
	l := liner.NewLiner()
	cols := int(reflect.ValueOf(l).Elem().FieldByName("columns").Int())
	var err error

	// Ctrl-C resets the prompt, as expected.
	_, err = l.Prompt(genString(cols - 10))
	fmt.Printf("err: %v\n", err)

	// This kills the program when hitting Ctrl-C, exiting with a status code of 1.
	_, err = l.Prompt(genString(cols - 9))
	fmt.Printf("err: %v\n", err)
}

func genString(n int) string {
	var s strings.Builder
	for i := 0; i < n; i++ {
		s.WriteString("a")
	}
	return s.String()
}

The issue is the call here to the ReadLine method from bufio. (This is reached from this region.)

I'm not (immediately) sure what the right fix would be. You've no doubt thought a lot more about these kinds of questions than I have—what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions