chzyer / readline

Readline is a pure go(golang) implementation for GNU-Readline kind library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using readline with a hardware serial console (minitel)

tgirod opened this issue · comments

I'm trying to run an application using readline that talks to a hardware serial console (a venerable Minitel 1B), which appears as /dev/ttyUSB0. Here is a program that partially works.

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/chzyer/readline"
)

func main() {
	ttyName := os.Args[1]
	tty, err := os.OpenFile(ttyName, os.O_RDWR, os.ModeDevice)
	if err != nil {
		panic(err)
	}
	defer tty.Close()

	cfg := readline.Config{
		Prompt: "> ",
		Stdin:  tty,
		Stdout: tty,
		Stderr: tty,
	}
	rl, err := readline.NewEx(&cfg)
	if err != nil {
		panic(err)
	}

	for {
		line, err := rl.Readline()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(line)
	}
}

The prompt works fine, I can type a line and get the result. However:

  1. Whenever I read a line, the line I've just typed (including the prompt) is printed back to the screen before a new prompt is displayed
  2. Minitel is a strange beast, and function keys such as backspace and arrows are not sent as regular codes. Is there a way to instruct readline of those peculiarities ? Or should I encapsulate my tty and reimplement Read and Write in order to convert those ?

thanks for your attention!