Skip to content
Browse files

* terminfo.c (TermInfo.ctermid): defined.

* lib/terminfo.rb, sample/resize: use TermInfo.ctermid instead of
  "/dev/tty".


git-svn-id: svn://svn.a-k-r.org/akr/ruby-terminfo/trunk@641 0ecacc03-ac1b-0410-941d-e442c79421a6
  • Loading branch information...
1 parent 1fa2a4f commit 419d20876f0b9260ace3da6383f7f8c2896bb57f @akr committed May 30, 2007
Showing with 30 additions and 2 deletions.
  1. +7 −0 ChangeLog
  2. +2 −0 extconf.rb
  3. +1 −1 lib/terminfo.rb
  4. +1 −1 sample/resize
  5. +19 −0 terminfo.c
View
7 ChangeLog
@@ -1,3 +1,10 @@
+2007-05-30 Tanaka Akira <akr@fsij.org>
+
+ * terminfo.c (TermInfo.ctermid): defined.
+
+ * lib/terminfo.rb, sample/resize: use TermInfo.ctermid instead of
+ "/dev/tty".
+
2007-05-29 Tanaka Akira <akr@fsij.org>
* sample/resize: new sample program.
View
2 extconf.rb
@@ -41,6 +41,8 @@
have_header("curses.h")
have_header("term.h")
+have_func("ctermid", "stdio.h")
+
has_setupterm = true
if have_library("ncurses", "setupterm")
have_header("ncurses.h")
View
2 lib/terminfo.rb
@@ -33,7 +33,7 @@
class TermInfo
def TermInfo.default_object
unless defined? @default_terminfo
- io = File.open("/dev/tty", File::RDWR|File::NOCTTY)
+ io = File.open(TermInfo.ctermid, File::RDWR|File::NOCTTY)
io.sync = true
@default_terminfo = TermInfo.new(ENV['TERM'], io)
end
View
2 sample/resize
@@ -29,7 +29,7 @@ def noecho_raw(io)
}
end
-tty = File.open("/dev/tty", "r+")
+tty = File.open(TermInfo.ctermid, "r+")
tty.sync = true
str = nil
View
19 terminfo.c
@@ -331,6 +331,23 @@ rt_tiocswinsz(VALUE self, VALUE io, VALUE row, VALUE col)
#endif
}
+/*
+ * TermInfo.ctermid
+ *
+ * TermInfo.ctermid returns a pathname for the current controling terminal,
+ * such as "/dev/tty".
+ */
+static VALUE
+rt_ctermid(VALUE self)
+{
+#ifdef HAVE_CTERMID
+ char buf[L_ctermid];
+ return rb_str_new2(ctermid(buf));
+#else
+ return rb_str_new2("/dev/tty");
+#endif
+}
+
void
Init_terminfo()
{
@@ -351,4 +368,6 @@ Init_terminfo()
rb_define_module_function(cTermInfo, "tiocgwinsz", rt_tiocgwinsz, 1);
rb_define_module_function(cTermInfo, "tiocswinsz", rt_tiocswinsz, 3);
+
+ rb_define_module_function(cTermInfo, "ctermid", rt_ctermid, 0);
}

0 comments on commit 419d208

Please sign in to comment.
Something went wrong with that request. Please try again.