📄 01 - getting input one character at a time.rb
字号:
#!/usr/bin/ruby -w# curses_single_char_input.rbrequire 'curses'include Curses# Setup: create a curses screen that doesn't echo its input.init_screennoecho# Cleanup: restore the terminal settings when the program is exited or# killed.trap(0) { echo }while (c = getch) != ?\e do setpos(0,0) addstr("You typed #{c.chr.inspect}")end#---require 'rubygems'require 'highline/import'while (c = ask('') { |q| q.character = true; q.echo = false }) != "\e" do print "You typed #{c.inspect}"end#---class HighLine public :get_characterendinput = HighLine.newwhile (c = input.get_character) != ?\e do puts "You typed #{c.chr.inspect}"end#---require 'Win32API'def getch @getch ||= Win32API.new('crtdll', '_getch', [], 'L') @getch.callendwhile (c = getch) != ?\e puts "You typed #{c.chr.inspect}"end#---def getch state = `stty -g` begin `stty raw -echo cbreak` $stdin.getc ensure `stty #{state}` endendwhile (c = getch) != ?\e puts "You typed #{c.chr.inspect}"end#---
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -