A fork of Crisp for HARP
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 

21 行
416 B

# Note:
# Crystal already has "readline" library.
# I implemented a subset of it again for practice.
@[Link("readline")]
lib LibReadline
fun readline(prompt : UInt8*) : UInt8*
fun add_history(line : UInt8*)
end
def my_readline(prompt = "")
line = LibReadline.readline(prompt)
if line
LibReadline.add_history(line)
String.new(line)
else
nil
end
ensure
LibC.free(line as Void*) if line
end