Crystal: Readline.readline alters prompt text (badly) when window cols under certain width

Created on 2 Jun 2018  路  2Comments  路  Source: crystal-lang/crystal

Ok this is ... a weird one, but i have code to reproduce it. The following code should produce this output:

cols: 136

1
12
123
1234
12345
123456
1234567
123456789
1234567890
12345678901
123456789012
1234567890123
123456789012345

The number after cols changes to display the number of columns being displayed in your terminal. For me it screws it up in a slightly different way at each width below 136 columns. Noting that the number of columns can be much wider than the width of the prompt text. For example a prompt with a max width of 15 columns is borked on an 80 column width window:

cols: 80

1
12
123
1234
12345
123456
1234567
123456789
1234567890
12345678901
3456789012       <----- borked line
1234567890123
12345678901234
123456789012345

Test Setup

crystal 0.23.1_3 and 0.24.2_1
mac os 10.13.4 (17E199)
happens in iTerm 2 and Terminal.app

Test Script

save this as a crystal file and run with crystal run my_file.cr
the loop waits for your input so run, observe, resize window, hit enter, observe, resize window, hit enter, observe etc...

require "readline"

message = "1
12
123
1234
12345
123456
1234567
123456789
1234567890
12345678901
123456789012
1234567890123
12345678901234
123456789012345"

while (true)
  cols = `tput cols`
  input = Readline.readline("cols: #{cols}\n#{message}").to_s
end
refactor stdlib

Most helpful comment

Readline should be moved to a shard. I think nobody in the core team knows readline.

All 2 comments

Readline should be moved to a shard. I think nobody in the core team knows readline.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  3Comments

lbguilherme picture lbguilherme  路  3Comments

cjgajard picture cjgajard  路  3Comments

Sija picture Sija  路  3Comments

relonger picture relonger  路  3Comments