Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using readline with a hardware serial console (minitel) #185

Open
tgirod opened this issue Jan 13, 2020 · 0 comments
Open

using readline with a hardware serial console (minitel) #185

tgirod opened this issue Jan 13, 2020 · 0 comments

Comments

@tgirod
Copy link

tgirod commented Jan 13, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant