LoginSignup
5
5

More than 5 years have passed since last update.

mruby-io-consoleちょこっと書いた

Last updated at Posted at 2016-07-19

mruby-io-console

CRubyにあるio/consoleというライブラリがあって、この機能をmrubyでも使えるかなあと思って作ってみました。

自分でもio/consoleが何かわかってなかったので、学習のためにも書いてみました。

これでIO#rawIO#cookedIO#noechoIO#winsizeがmrubyでも使えるようになります。

なかでも使いみちがありそうなのはIO#rawIO#noechoで、

IO#rawはコンソールから一文字ずつ読みこむようなアプリケーションを作りたい場合に使えます。

$stdin.raw do
  # この中での$stdinはrawモードになる
  while true
    ch = $stdin.getc
    print ch
  end
end

IO#noechoはパスワード入力時に入力文字を隠したい時に使えます。

password = $stdin.noecho { $stdin.gets }

まだ全てのメソッドが揃ったわけではないし自分の手元のmacマシンでしか動作確認してないデス。。。
PRお待ちしております。

リンク

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5