【问题标题】:How to get a single character without pressing Enter in Elixir?如何在 Elixir 中不按 Enter 键获取单个字符?
【发布时间】:2017-01-08 16:45:12
【问题描述】:

与 Ruby 的 STDIN#getch 类似。

Elixir 的IO.gets/2 需要回车才能获取角色。有没有办法在 Elixir 中不按 Enter 来获取单个字符?

【问题讨论】:

  • 有一个 Elixir Sips 剧集涵盖了这个 elixirsips.com/episodes/…。不幸的是,它只是订户。我能找到的所有灵丹妙药代码似乎都使用了这个魔法` Port.open({:spawn, "tty_sl -c -e"}, [:binary, :eof])`
  • iex(1)> Port.open({:spawn, "tty_sl -c -e"}, [:binary, :eof]) ** (ErlangError) erlang 错误: :einval :erlang .open_port({:spawn, "tty_sl -c -e"}, [:binary, :eof])

标签: io elixir


【解决方案1】:

每当我尝试用几乎任何语言实现与 stdio 的重要交互时,都会弹出 ncurses。所以我会看看这个 NIF https://github.com/jfreeze/ex_ncurses

【讨论】:

    猜你喜欢
    • 2010-09-15
    • 1970-01-01
    • 2010-12-20
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多