64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/ripl/rocket.rb', line 64
def print_result(result)
return if @error_raised
if config[:rocket_mode]
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]
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] + TPUT[:cuu1]*stdout_height + TPUT[:cuf1]*offset + colored_rocket + format_result(result).sub( /^#{result_prompt}/, '' ) + TPUT[:rc] + ( config[:rocket_mode] != :auto && line_too_long ? "\n" : '')
else puts colored_rocket + format_result(result).sub( /^#{result_prompt}/, '' ) end
return
end
end
super
end
|