diff options
Diffstat (limited to 'dragon/console.rb')
| -rw-r--r-- | dragon/console.rb | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/dragon/console.rb b/dragon/console.rb index acacfd2..32deb15 100644 --- a/dragon/console.rb +++ b/dragon/console.rb @@ -13,11 +13,12 @@ module GTK :last_command_errored, :last_command, :error_color, :shown_at, :header_color, :archived_log, :last_log_lines, :last_log_lines_count, :suppress_left_arrow_behavior, :command_set_at, - :toast_ids, - :font_style + :toast_ids, :bottom, + :font_style, :menu def initialize @font_style = FontStyle.new(font: 'font.ttf', size_enum: -1, line_height: 1.1) + @menu = Menu.new self @disabled = false @log_offset = 0 @visible = false @@ -26,6 +27,7 @@ module GTK @log = [ 'Console ready.' ] @max_log_lines = 1000 # I guess...? @max_history = 1000 # I guess...? + @log_invocation_count = 0 @command_history = [] @command_history_index = -1 @nonhistory_input = '' @@ -76,6 +78,7 @@ module GTK end def addsprite obj + @log_invocation_count += 1 obj[:id] ||= "id_#{obj[:path]}_#{Time.now.to_i}".to_sym if @last_line_log_index && @@ -103,6 +106,7 @@ module GTK def addtext obj @last_log_lines_count ||= 1 + @log_invocation_count += 1 str = obj.to_s @@ -288,18 +292,17 @@ S @last_command_errored = false rescue Exception => e string_e = "#{e}" + puts "* EXCEPTION: #{e}" + log "* EXCEPTION: #{e}" @last_command_errored = true if (string_e.include? "wrong number of arguments") method_name = (string_e.split ":")[0].gsub "'", "" - results = Kernel.docs_search method_name - if !results.include "* DOCS: No results found." + results = (Kernel.docs_search method_name).strip + if !results.include? "* DOCS: No results found." puts results log results end end - - puts "#{e}" - log "#{e}" end end end @@ -311,6 +314,10 @@ S (args.inputs.keyboard.key_up.b && args.inputs.keyboard.key_up.control) end + def scroll_to_bottom + @log_offset = 0 + end + def scroll_up_full @log_offset += lines_on_one_page @log_offset = @log.size if @log_offset > @log.size @@ -424,6 +431,10 @@ S @command_history_index -= 1 self.current_input_str = @command_history[@command_history_index].dup end + elsif args.inputs.keyboard.key_down.left + prompt.move_cursor_left + elsif args.inputs.keyboard.key_down.right + prompt.move_cursor_right elsif inputs_scroll_up_full? args scroll_up_full elsif inputs_scroll_down_full? args @@ -450,7 +461,7 @@ S def write_primitive_and_return_offset(args, left, y, str, archived: false) if str.is_a?(Hash) padding = 10 - args.outputs.reserved << [left + 10, y - padding * 1.66, str[:w], str[:h], str[:path]].sprite + args.outputs.reserved << [left + 10, y + 5, str[:w], str[:h], str[:path]].sprite return str[:h] + padding else write_line args, left, y, str, archived: archived @@ -465,25 +476,25 @@ S args.outputs.reserved << font_style.label(x: left.shift_right(10), y: y, text: str, color: color) end + def should_tick? + return false if !@toggled_at + return false if slide_progress == 0 + return false if @disabled + return visible? + end + def render args return if !@toggled_at + return if slide_progress == 0 - if visible? - percent = @toggled_at.global_ease(@animation_duration, :flip, :quint, :flip) - else - percent = @toggled_at.global_ease(@animation_duration, :flip, :quint) - end - - return if percent == 0 - - bottom = top - (h * percent) - args.outputs.reserved << [left, bottom, w, h, *@background_color.mult_alpha(percent)].solid - args.outputs.reserved << [right.shift_left(110), bottom.shift_up(630), 100, 100, @logo, 0, (80.0 * percent).to_i].sprite + @bottom = top - (h * slide_progress) + args.outputs.reserved << [left, @bottom, w, h, *@background_color.mult_alpha(slide_progress)].solid + args.outputs.reserved << [right.shift_left(110), @bottom.shift_up(630), 100, 100, @logo, 0, (80.0 * slide_progress).to_i].sprite - y = bottom + 2 # just give us a little padding at the bottom. + y = @bottom + 2 # just give us a little padding at the bottom. prompt.render args, x: left.shift_right(10), y: y y += line_height_px * 1.5 - args.outputs.reserved << line(y: y, color: @text_color.mult_alpha(percent)) + args.outputs.reserved << line(y: y, color: @text_color.mult_alpha(slide_progress)) y += line_height_px.to_f / 2.0 ((@log.size - @log_offset) - 1).downto(0) do |idx| @@ -492,8 +503,8 @@ S break if y > top end - # past log seperator - args.outputs.reserved << line(y: y + line_height_px.half, color: @text_color.mult_alpha(0.25 * percent)) + # past log separator + args.outputs.reserved << line(y: y + line_height_px.half, color: @text_color.mult_alpha(0.25 * slide_progress)) y += line_height_px @@ -504,29 +515,6 @@ S end render_log_offset args - render_help args, top if percent == 1 - end - - def render_help args, top - [ - "* Prompt Commands: ", - "You can type any of the following ", - "commands in the command prompt. ", - "** docs: Provides API docs. ", - "** $gtk: Accesses the global runtime.", - "* Shortcut Keys: ", - "** full page up: ctrl + b ", - "** full page down: ctrl + f ", - "** half page up: ctrl + u ", - "** half page down: ctrl + d ", - "** clear prompt: ctrl + g ", - "** up arrow: next command ", - "** down arrow: prev command ", - ].each_with_index do |s, i| - args.outputs.reserved << [args.grid.right - 10, - top - 100 - line_height_px * i * 0.8, - s, -3, 2, 180, 180, 180].label - end end def render_log_offset args @@ -582,9 +570,17 @@ S begin return if @disabled render args - calc args process_inputs args + return unless should_tick? + calc args + prompt.tick + menu.tick args rescue Exception => e + begin + puts "#{e}" + puts "* FATAL: The GTK::Console console threw an unhandled exception and has been reset. You should report this exception (along with reproduction steps) to DragonRuby." + rescue + end @disabled = true $stdout.puts e $stdout.puts "* FATAL: The GTK::Console console threw an unhandled exception and has been reset. You should report this exception (along with reproduction steps) to DragonRuby." @@ -680,12 +676,11 @@ S end def include_header_marker? log_entry - return false if log_entry.include? "NOTIFY:" - return false if log_entry.include? "INFO:" - return true if log_entry.include? "DOCS:" - (log_entry.start_with? "* ") || - (log_entry.start_with? "** ") || - (log_entry.start_with? "*** ") + return false if (log_entry.strip.include? ".rb") + (log_entry.start_with? "* ") || + (log_entry.start_with? "** ") || + (log_entry.start_with? "*** ") || + (log_entry.start_with? "**** ") end def color_for_log_entry(log_entry) @@ -697,7 +692,7 @@ S @text_color.mult_alpha(0.5) elsif include_header_marker? log_entry @header_color - elsif log_entry.start_with?("====") || log_entry.include?("app") && !log_entry.include?("apple") + elsif log_entry.start_with?("====") @header_color else @text_color @@ -722,5 +717,15 @@ S @prompt.clear :console_silent_eval end + + def slide_progress + return 0 if !@toggled_at + if visible? + @slide_progress = @toggled_at.global_ease(@animation_duration, :flip, :quint, :flip) + else + @slide_progress = @toggled_at.global_ease(@animation_duration, :flip, :quint) + end + @slide_progress + end end end |
