A
Andrew Seidel
Hello,
I'm trying to make a customized pager utility that can process
file-contents piped in from the command line, equally well as a list of
provided file names.
e.g. cat testfile | my_util.rb or my_util.rb testfile
I'm having trouble using the pipe to get the file contents and still be
able to use STDIN in a non-blocking way for a shell-style interactive
menu.
For the menu, I'm using Highline::SystemExtensions: e.g.:
while (mychar = get_character) && (mychar.chr != "q")
if (mychar.chr == "x") then
filter_all_but_selected
end
end
... and that works only for the case where there is no input pipe,
instead filename(s) I get from ARGV.
Here's what I've tried to get the pipe read before begining the menu,
but thid hammers the rest of my script and my highline menu doesn't
work:
def fill_pipe
# capture piped input
flags = STDIN.fcntl(Fcntl::F_GETFL, 0)
flags |= Fcntl::O_NONBLOCK
STDIN.fcntl(Fcntl::F_SETFL, flags)
begin
input_pipe = STDIN.readlines
$working_pipe.concat(input_pipe)
# puts "Input pipe: #{$input_pipe}"
rescue Errno::EAGAIN
puts "ERROR: no input piped nor file name provided"
display_help
end # end what kind of input
end # end fill_pipe
STDIN.close_read doesn't do the trick to reset things -- ideas how I
can have it both ways? Thanks! Andrew.
I'm trying to make a customized pager utility that can process
file-contents piped in from the command line, equally well as a list of
provided file names.
e.g. cat testfile | my_util.rb or my_util.rb testfile
I'm having trouble using the pipe to get the file contents and still be
able to use STDIN in a non-blocking way for a shell-style interactive
menu.
For the menu, I'm using Highline::SystemExtensions: e.g.:
while (mychar = get_character) && (mychar.chr != "q")
if (mychar.chr == "x") then
filter_all_but_selected
end
end
... and that works only for the case where there is no input pipe,
instead filename(s) I get from ARGV.
Here's what I've tried to get the pipe read before begining the menu,
but thid hammers the rest of my script and my highline menu doesn't
work:
def fill_pipe
# capture piped input
flags = STDIN.fcntl(Fcntl::F_GETFL, 0)
flags |= Fcntl::O_NONBLOCK
STDIN.fcntl(Fcntl::F_SETFL, flags)
begin
input_pipe = STDIN.readlines
$working_pipe.concat(input_pipe)
# puts "Input pipe: #{$input_pipe}"
rescue Errno::EAGAIN
puts "ERROR: no input piped nor file name provided"
display_help
end # end what kind of input
end # end fill_pipe
STDIN.close_read doesn't do the trick to reset things -- ideas how I
can have it both ways? Thanks! Andrew.