module Ripl::Rocket::Shell
Public Instance Methods
loop_eval(input)
click to toggle source
Calls superclass method
# File lib/ripl/rocket.rb, line 59 def loop_eval(input) Ripl::Rocket.reset_output_height super end
print_result(result)
click to toggle source
Calls superclass method
# File lib/ripl/rocket.rb, line 64 def print_result(result) return if @error_raised if config[:rocket_mode] # get important data screen_length = `tput cols`.to_i screen_height = `tput lines`.to_i last_line_without_prompt = @input.split("\n").last || '' offset = (last_line_without_prompt.display_size + prompt.display_size ) % screen_length.to_i output_length = result.inspect.display_size rocket_length = config[:rocket_prompt].display_size stdout_height = Ripl::Rocket.output_height color_config = config[:rocket_color] color_code = !color_config || color_config.to_s[/^[\d;]+$/] ? color_config : Ripl::Rocket::COLORS[color_config.to_sym] colored_rocket = color_code ? "\e[#{ color_code }m#{ config[:rocket_prompt] }\e[0;0m" : config[:rocket_prompt] # auto rocket mode: only display rocket if line has enough space left line_too_long = screen_length <= offset + rocket_length + output_length height_too_long = stdout_height >= screen_height if !(config[:rocket_mode] == :auto && ( line_too_long || height_too_long ) ) if !height_too_long print TPUT[:sc] + # save cursor position TPUT[:cuu1]*stdout_height + # move cursor upwards to the original input line TPUT[:cuf1]*offset + # move cursor rightwards to the original input offset colored_rocket + # draw rocket prompt format_result(result).sub( /^#{result_prompt}/, '' ) + # draw result (without prompt) TPUT[:rc] + # restore cursor position ( config[:rocket_mode] != :auto && line_too_long ? "\n" : '') # add a line for always-rocket mode else # too much stdout, but in "always rocket mode" puts colored_rocket + # draw rocket prompt format_result(result).sub( /^#{result_prompt}/, '' ) # draw result (without prompt) end return end end # else: no rocket ;) super end