Add link to Rust implementation by Tim Morgan.
[jackhill/mal.git] / crystal / readline.cr
CommitLineData
85c1b0c0 1# Note:
2# Crystal already has "readline" library.
3# I implemented a subset of it again for practice.
4
5@[Link("readline")]
6lib LibReadline
7 fun readline(prompt : UInt8*) : UInt8*
8 fun add_history(line : UInt8*)
9end
10
fdf28b76 11def my_readline(prompt = "")
12 line = LibReadline.readline(prompt)
13 if line
14 LibReadline.add_history(line)
15 String.new(line)
16 else
17 nil
85c1b0c0 18 end
fdf28b76 19ensure
20 LibC.free(line as Void*) if line
2c436e30 21end