diff --git a/lib-ruby/io/console.rb b/lib-ruby/io/console.rb new file mode 100644 index 000000000..d7b2d9e88 --- /dev/null +++ b/lib-ruby/io/console.rb @@ -0,0 +1,82 @@ +class IO + # Indexes for termios list. + IFLAG = 0 + OFLAG = 1 + CFLAG = 2 + LFLAG = 3 + ISPEED = 4 + OSPEED = 5 + CC = 6 + include Topaz::TermIOConstants + + # def raw + # end + + def raw!(&block) + mode = Topaz.tcgetattr(fileno) + mode[IFLAG] = mode[IFLAG] & ~(IGNBRK | BRKINT | PARMRK | ISTRIP | ICRNL | + IXON) + mode[OFLAG] = mode[OFLAG] & ~(OPOST) + mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB) + mode[CFLAG] = mode[CFLAG] | CS8 + mode[LFLAG] = mode[LFLAG] & ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON | ISIG | + IEXTEN) + Topaz.tcsetattr(fileno, TCSANOW, mode) + if block + begin + block[] + ensure + cooked! + end + end + end + + # def cooked + # end + + def cooked! + mode = Topaz.tcgetattr(fileno) + mode[IFLAG] = mode[IFLAG] | (BRKINT | ISTRIP | ICRNL | IXON) + mode[OFLAG] = mode[OFLAG] | OPOST + mode[LFLAG] = mode[LFLAG] | (ECHO | ECHOE | ECHOK | ECHONL | ICANON | ISIG | + IEXTEN) + Topaz.tcsetattr(fileno, TCSANOW, mode) + end + + # def getch + # end + + # def echo= + # end + + # def echo + # end + + # def echo? + # end + + # def noecho + # end + + # def winsize + # end + + # def winsize= + # end + + # def iflush + # end + + # def oflush + # end + + # def ioflush + # end + + # def self.console + # end + + # module Readable + # alias getch getc + # end +end diff --git a/lib-ruby/io/wait.rb b/lib-ruby/io/wait.rb new file mode 100644 index 000000000..e69de29bb diff --git a/topaz/modules/topaz.py b/topaz/modules/topaz.py index 935377ffc..a6b4edee0 100644 --- a/topaz/modules/topaz.py +++ b/topaz/modules/topaz.py @@ -4,6 +4,7 @@ from rpython.rlib.rarithmetic import intmask from rpython.rlib.rtermios import tcsetattr, tcgetattr, all_constants +from topaz.error import error_for_oserror from topaz.module import ModuleDef from topaz.objects.classobject import W_ClassObject @@ -14,8 +15,9 @@ class Topaz(object): @moduledef.setup_module def setup_module(space, w_mod): space.set_const(w_mod, "FIXNUM_MAX", space.newint(sys.maxint)) - w_termioconsts = space.newclass("TermIOConstants", None) - for name, value in all_constants: + w_termioconsts = space.newmodule("TermIOConstants", None) + space.set_const(w_mod, "TermIOConstants", w_termioconsts) + for name, value in all_constants.iteritems(): space.set_const(w_termioconsts, name, space.newint(value)) @moduledef.function("intmask") @@ -62,7 +64,7 @@ def method_tcsetattr(self, space, fd, when, mode_w): try: tcsetattr(fd, when, mode) except OSError as e: - raise space.error_for_oserror(e) + raise error_for_oserror(space, e) return self @moduledef.function("tcgetattr", fd="int") @@ -70,7 +72,7 @@ def method_tcsetattr(self, space, fd): try: mode = tcgetattr(fd) except OSError as e: - raise space.error_for_oserror(e) + raise error_for_oserror(space, e) mode_w = [ space.newint(mode[0]), # iflag space.newint(mode[1]), # oflag @@ -78,6 +80,6 @@ def method_tcsetattr(self, space, fd): space.newint(mode[3]), # lflag space.newint(mode[4]), # ispeed space.newint(mode[5]), # ospeed - space.newarray([space.newstr_fromstr(cc) in mode[6]]) + space.newarray([space.newstr_fromstr(cc) for cc in mode[6]]) ] return space.newarray(mode_w) diff --git a/topaz/objects/ioobject.py b/topaz/objects/ioobject.py index c8008dcd3..2c14fa575 100644 --- a/topaz/objects/ioobject.py +++ b/topaz/objects/ioobject.py @@ -1,7 +1,6 @@ import os from rpython.rlib.rpoll import POLLIN -from rpython.rlib.rtermios import tcsetattr from topaz.coerce import Coerce from topaz.error import error_for_oserror @@ -293,6 +292,3 @@ def method_ready(self, space): except PollError: return space.w_nil return space.newbool(len(retval) > 0) - - @classdef.method("raw!") - def method_raw_bang(self, space):