ruby / ruby/reline

Reline emits extra escape sequences when stdin/stdout/stderr are not TTY

Open
#886 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
311
Forks
99
Avg merge
6d 4h
Merged PRs (30d)
1

Description

Reline 0.6.0 from Ruby 3.4.7 (same with reline 0.6.3 the last release):

$ echo 'my input' > in
$ ruby -rreadline -e 'p Readline; p [STDIN,STDOUT,STDERR].map(&:tty?); p Readline.readline("> ", true)' < in |& ruby -e 'p STDIN.read'            
"Reline\n[false, false, false]\n> \e[?25l\e[1G\e[K\e[1G\e[0m> \e[0m\e[?25h\e[3G\e[?25l\e[1G\e[K\e[?25h\e[1G> my input\r\n\e[1G\"my input\"\n"

Even though STDIN, STDOUT, STDERR are all not TTY, terminal escape sequences are still included.
This causes issues for e.g. this program using Readline.readline because it's supposed to work well both if TTY or not. If not TTY, it expects no escape sequences.
That works with Readline from readline-ext but not Reline (as-is at least).

TERM=dumb doesn't help, it outputs many extra things (#660):

$ TERM=dumb ruby -rreadline -e 'p Readline; p [STDIN,STDOUT,STDERR].map(&:tty?); p Readline.readline("> ", true)' < in |& ruby -e 'p STDIN.read' 
"Reline\n[false, false, false]\n> > mmymy my imy inmy inpmy inpumy input> my input\r\n\"my input\"\n"

readline-ext for comparison works fine:

$ gem i readline-ext  
$ ruby -rreadline -e 'p Readline; p [STDIN,STDOUT,STDERR].map(&:tty?); p Readline.readline("> ", true)' < in |& ruby -e 'p STDIN.read'
"Readline\n[false, false, false]\n> my input\n\"my input\"\n"

Is there a way to achieve the same with Reline?

Related: https://github.com/ruby/reline/issues/644

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported Readline.readline reproduction using redirected stdin, stdout, and stderr, then compare its output with readline-ext. Review the linked TruffleRuby can-we-fold-yet test and expected.txt to define the non-TTY result. Done means Reline emits no terminal escape sequences when all three streams are not TTYs, while preserving interactive behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.