Skip to content

Commit

Permalink
Move Rubinius::Terminal constant to kernel, wire up IO#tty? to suppor…
Browse files Browse the repository at this point in the history
…t it.

Environment::set_rubinius_constants() is now gone, as it is not needed.
  • Loading branch information
drbrain committed Aug 28, 2008
1 parent d58394d commit c11533d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 29 deletions.
4 changes: 1 addition & 3 deletions kernel/common/io.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1339,16 +1339,14 @@ def to_io
self self
end end


alias_method :prim_tty?, :tty?

## ##
# Returns true if ios is associated with a terminal device (tty), false otherwise. # Returns true if ios is associated with a terminal device (tty), false otherwise.
# #
# File.new("testfile").isatty #=> false # File.new("testfile").isatty #=> false
# File.new("/dev/tty").isatty #=> true # File.new("/dev/tty").isatty #=> true
def tty? def tty?
raise IOError, "closed stream" if closed? raise IOError, "closed stream" if closed?
prim_tty? Platform::POSIX.isatty(@descriptor) == 1
end end


alias_method :isatty, :tty? alias_method :isatty, :tty?
Expand Down
7 changes: 7 additions & 0 deletions kernel/delta/io.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ class IO::BidirectionalPipe
undef_method method undef_method method
end end
end end

# Re-setup all the stdio channels, to pull in new ivars

STDOUT.setup
STDIN.setup
STDERR.setup

6 changes: 6 additions & 0 deletions kernel/delta/rubinius.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
# depends on: io.rb

module Rubinius
Terminal = STDIN.tty?
end

8 changes: 1 addition & 7 deletions kernel/loader.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,11 +1,5 @@
# Contained first is the system startup code. # Contained first is the system startup code.


# Re-setup all the stdio channels, to pull in new ivars

STDOUT.setup
STDIN.setup
STDERR.setup

begin begin
ENV = EnvironmentVariables.new ENV = EnvironmentVariables.new


Expand Down Expand Up @@ -110,7 +104,7 @@
puts RBS_USAGE puts RBS_USAGE
exit 1 exit 1
when "-v" when "-v"
puts "rubinius #{RBX_VERSION} (ruby #{RUBY_VERSION} compatible) (#{Rubinius::BUILDREV[0..8]}) (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" puts "rubinius #{Rubinius::RBX_VERSION} (ruby #{RUBY_VERSION} compatible) (#{Rubinius::BUILDREV[0..8]}) (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
$VERBOSE = true $VERBOSE = true
exit 0 if ARGV.empty? exit 0 if ARGV.empty?
when "-w" when "-w"
Expand Down
3 changes: 2 additions & 1 deletion kernel/platform/posix.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ module Platform::POSIX
attach_function 'clearerr', [:pointer], :void attach_function 'clearerr', [:pointer], :void
attach_function 'fseek', [:pointer, :int, :int], :int attach_function 'fseek', [:pointer, :int, :int], :int
attach_function 'ftell', [:pointer], :int attach_function 'ftell', [:pointer], :int
attach_function 'lseek', [:int, :int, :int], :int attach_function 'lseek', [:int, :int, :int], :int
attach_function 'isatty', [:int], :int


# reading # reading
attach_function 'fread', [:string, :size_t, :size_t, :pointer], :size_t attach_function 'fread', [:string, :size_t, :size_t, :pointer], :size_t
Expand Down
11 changes: 7 additions & 4 deletions rakelib/configure.rake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ file 'lib/rbconfig.rb' do
write_rbconfig write_rbconfig
end end


file 'kernel/bootstrap/rubinius_config.rb' => 'rakelib/configuration.rb' do |task, args| file 'kernel/bootstrap/rubinius_config.rb' =>
%w[rakelib/configuration.rb rakelib/configure.rake] do |task, args|
open task.name, 'w' do |io| open task.name, 'w' do |io|
io << <<-EOF io << <<-EOF
#-- #--
# This file was generated from rakelib/configur.rake # This file was generated from rakelib/configure.rake
#++ #++
module Rubinius module Rubinius
Expand All @@ -20,15 +21,17 @@ module Rubinius
RBA_PATH = #{RBX_RBA_PATH.inspect} RBA_PATH = #{RBX_RBA_PATH.inspect}
RBX_VERSION = #{RBX_VERSION.inspect} RBX_VERSION = #{RBX_VERSION.inspect}
end end
EOF EOF
end end
end end


file 'kernel/bootstrap/ruby_config.rb' => 'rakelib/configuration.rb' do |task, args| file 'kernel/bootstrap/ruby_config.rb' =>
%w[rakelib/configuration.rb rakelib/configure.rake] do |task, args|
open task.name, 'w' do |io| open task.name, 'w' do |io|
io << <<-EOF io << <<-EOF
#-- #--
# This file was generated from rakelib/configur.rake # This file was generated from rakelib/configure.rake
#++ #++
PLATFORM = #{RBX_HOST.inspect} PLATFORM = #{RBX_HOST.inspect}
Expand Down
1 change: 0 additions & 1 deletion vm/drivers/cli.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ int main(int argc, char** argv) {
} }


std::string root = std::string(e); std::string root = std::string(e);
env.set_rubinius_constants();


std::cout << "Loading platform.conf: " << root << "\n"; std::cout << "Loading platform.conf: " << root << "\n";
env.load_platform_conf(root); env.load_platform_conf(root);
Expand Down
12 changes: 0 additions & 12 deletions vm/environment.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -97,16 +97,4 @@ namespace rubinius {
} }
} }


/*
* HACK hook this up to a config file
*/
void Environment::set_rubinius_constants() {
Module* rubinius = GO(rubinius).get();

if(isatty(fileno(stdin))) {
rubinius->set_const(state, "Terminal", Qtrue);
} else {
rubinius->set_const(state, "Terminal", Qfalse);
}
}
} }
2 changes: 1 addition & 1 deletion vm/environment.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace rubinius {
void load_directory(std::string dir); void load_directory(std::string dir);
void load_platform_conf(std::string dir); void load_platform_conf(std::string dir);
void run_file(std::string path); void run_file(std::string path);
void set_rubinius_constants();
}; };

} }


#endif #endif

0 comments on commit c11533d

Please sign in to comment.