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

21 行
416 B

  1. # Note:
  2. # Crystal already has "readline" library.
  3. # I implemented a subset of it again for practice.
  4. @[Link("readline")]
  5. lib LibReadline
  6. fun readline(prompt : UInt8*) : UInt8*
  7. fun add_history(line : UInt8*)
  8. end
  9. def my_readline(prompt = "")
  10. line = LibReadline.readline(prompt)
  11. if line
  12. LibReadline.add_history(line)
  13. String.new(line)
  14. else
  15. nil
  16. end
  17. ensure
  18. LibC.free(line as Void*) if line
  19. end