-
-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io/console extension missing in 1.9 mode Add a trivial io/console using stty, for basic operations to work.
- Loading branch information
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
warn "io/console on JRuby shells out to stty for most operations" | ||
|
||
# attempt to call stty; if failure, fall back on stubbed version | ||
result = begin | ||
`stty -a` | ||
rescue Exception | ||
nil | ||
end | ||
|
||
if !result || $?.exitstatus != 0 || RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/ | ||
# Windows version is always stubbed for now | ||
class IO | ||
def raw(*) | ||
yield self | ||
end | ||
|
||
def raw!(*) | ||
end | ||
|
||
def cooked(*) | ||
yield self | ||
end | ||
|
||
def cooked!(*) | ||
end | ||
|
||
def getch(*) | ||
getc | ||
end | ||
|
||
def echo=(echo) | ||
end | ||
|
||
def echo? | ||
true | ||
end | ||
|
||
def noecho | ||
yield self | ||
end | ||
|
||
def winsize | ||
[25, 80] | ||
end | ||
|
||
def winsize=(size) | ||
end | ||
|
||
def iflush | ||
end | ||
|
||
def oflush | ||
end | ||
|
||
def ioflush | ||
end | ||
end | ||
else | ||
# Non-Windows assumes stty command is available | ||
class IO | ||
def raw(*) | ||
saved = `stty -g` | ||
`stty raw` | ||
yield self | ||
ensure | ||
`stty #{saved}` | ||
end | ||
|
||
def raw!(*) | ||
`stty raw` | ||
end | ||
|
||
def cooked(*) | ||
saved = `stty -g` | ||
`stty cooked` | ||
yield self | ||
ensure | ||
`stty #{saved}` | ||
end | ||
|
||
def cooked!(*) | ||
`stty -raw` | ||
end | ||
|
||
def getch(*) | ||
getc | ||
end | ||
|
||
def echo=(echo) | ||
`stty #{echo ? 'echo' : '-echo'}` | ||
end | ||
|
||
def echo? | ||
(`stty -a` =~ (/ -echo /)) ? false : true | ||
end | ||
|
||
def noecho | ||
saved = `stty -g` | ||
`stty -echo` | ||
yield self | ||
ensure | ||
`stty #{saved}` | ||
end | ||
|
||
def winsize | ||
match = `stty -a`.match(/(\d+) rows; (\d+) columns/) | ||
[match[1].to_i, match[2].to_i] | ||
end | ||
|
||
def winsize=(size) | ||
`stty rows #{size[0]} cols #{size[1]}` | ||
end | ||
|
||
def iflush | ||
end | ||
|
||
def oflush | ||
end | ||
|
||
def ioflush | ||
end | ||
end | ||
end |