Class: GTK::Console

Inherits:
Object show all
Includes:
ConsoleDeprecated
Defined in:
dragon/console.rb,
dragon/console_menu.rb,
dragon/console_color.rb,
dragon/console_prompt.rb,
dragon/console_font_style.rb

Defined Under Namespace

Classes: Color, FontStyle, Menu, Prompt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConsole

Returns a new instance of Console.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'dragon/console.rb', line 22

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
  @toast_ids = []
  @archived_log = []
  @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 = ''
  @logo = 'console-logo.png'
  @history_fname = 'console_history.txt'
  @background_color = Color.new [0, 0, 0, 224]
  @text_color = Color.new [255, 255, 255]
  @error_color = Color.new [200, 50, 50]
  @header_color = Color.new [100, 200, 220]
  @animation_duration = 1.seconds
  @shown_at = -1
  load_history
end

Instance Attribute Details

#animation_durationObject

Returns the value of attribute animation_duration


13
14
15
# File 'dragon/console.rb', line 13

def animation_duration
  @animation_duration
end

#archived_logObject

Returns the value of attribute archived_log


13
14
15
# File 'dragon/console.rb', line 13

def archived_log
  @archived_log
end

#background_colorObject

Returns the value of attribute background_color


13
14
15
# File 'dragon/console.rb', line 13

def background_color
  @background_color
end

#bottomObject

Returns the value of attribute bottom


13
14
15
# File 'dragon/console.rb', line 13

def bottom
  @bottom
end

#command_set_atObject

Returns the value of attribute command_set_at


13
14
15
# File 'dragon/console.rb', line 13

def command_set_at
  @command_set_at
end

#error_colorObject

Returns the value of attribute error_color


13
14
15
# File 'dragon/console.rb', line 13

def error_color
  @error_color
end

#font_styleObject

Returns the value of attribute font_style


13
14
15
# File 'dragon/console.rb', line 13

def font_style
  @font_style
end

#header_colorObject

Returns the value of attribute header_color


13
14
15
# File 'dragon/console.rb', line 13

def header_color
  @header_color
end

#last_commandObject

Returns the value of attribute last_command


13
14
15
# File 'dragon/console.rb', line 13

def last_command
  @last_command
end

#last_command_erroredObject

Returns the value of attribute last_command_errored


13
14
15
# File 'dragon/console.rb', line 13

def last_command_errored
  @last_command_errored
end

#last_log_linesObject

Returns the value of attribute last_log_lines


13
14
15
# File 'dragon/console.rb', line 13

def last_log_lines
  @last_log_lines
end

#last_log_lines_countObject

Returns the value of attribute last_log_lines_count


13
14
15
# File 'dragon/console.rb', line 13

def last_log_lines_count
  @last_log_lines_count
end

#logObject

Returns the value of attribute log


13
14
15
# File 'dragon/console.rb', line 13

def log
  @log
end

#logoObject

Returns the value of attribute logo


13
14
15
# File 'dragon/console.rb', line 13

def 
  @logo
end

#max_historyObject

Returns the value of attribute max_history


13
14
15
# File 'dragon/console.rb', line 13

def max_history
  @max_history
end

#max_log_linesObject

Returns the value of attribute max_log_lines


13
14
15
# File 'dragon/console.rb', line 13

def max_log_lines
  @max_log_lines
end

Returns the value of attribute menu


13
14
15
# File 'dragon/console.rb', line 13

def menu
  @menu
end

#show_reasonObject

Returns the value of attribute show_reason


13
14
15
# File 'dragon/console.rb', line 13

def show_reason
  @show_reason
end

#shown_atObject

Returns the value of attribute shown_at


13
14
15
# File 'dragon/console.rb', line 13

def shown_at
  @shown_at
end

#suppress_left_arrow_behaviorObject

Returns the value of attribute suppress_left_arrow_behavior


13
14
15
# File 'dragon/console.rb', line 13

def suppress_left_arrow_behavior
  @suppress_left_arrow_behavior
end

#text_colorObject

Returns the value of attribute text_color


13
14
15
# File 'dragon/console.rb', line 13

def text_color
  @text_color
end

#toast_idsObject

Returns the value of attribute toast_ids


13
14
15
# File 'dragon/console.rb', line 13

def toast_ids
  @toast_ids
end

Instance Method Details

#add_primitive(obj) ⇒ Object


101
102
103
104
105
106
107
108
# File 'dragon/console.rb', line 101

def add_primitive obj
  if obj.is_a? Hash
    add_sprite obj
  else
    add_text obj
  end
  nil
end

#add_sprite(obj) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'dragon/console.rb', line 83

def add_sprite obj
  @log_invocation_count += 1
  obj[:id] ||= "id_#{obj[:path]}_#{Time.now.to_i}".to_sym

  if @last_line_log_index &&
     @last_sprite_line.is_a?(Hash) &&
     @last_sprite_line[:id] == obj[:id]

    @log[@last_line_log_index] = obj
    return
  end

  @log << obj
  @last_line_log_index = @log.length - 1
  @last_sprite_line = obj
  nil
end

#add_text(obj) ⇒ Object


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'dragon/console.rb', line 110

def add_text obj
  @last_log_lines_count ||= 1
  @log_invocation_count += 1

  str = obj.to_s

  log_lines = []

  str.each_line do |s|
    s.wrapped_lines(self.console_text_width).each do |l|
      log_lines << l
    end
  end

  if log_lines == @last_log_lines
    @last_log_lines_count += 1
    new_log_line_with_count = @last_log_lines.last + " (#{@last_log_lines_count})"
    if log_lines.length > 1
      @log = @log[0..-(@log.length - log_lines.length)] + log_lines[0..-2] + [new_log_line_with_count]
    else
      @log = @log[0..-2] + [new_log_line_with_count]
    end
    return
  end

  log_lines.each do |l|
    @log.shift if @log.length > @max_log_lines
    @log << l
  end

  @last_log_lines_count = 1
  @last_log_lines = log_lines
  nil
end

#calc(args) ⇒ Object


591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'dragon/console.rb', line 591

def calc args
  if visible? &&
     @show_reason == :toast &&
     @toasted_at &&
     @toasted_at.elapsed?(@toast_duration, Kernel.global_tick_count)
    hide
  end

  if !$gtk.paused? && visible? && (show_reason == :exception || show_reason == :exception_on_load)
    hide
  end

  if $gtk.files_reloaded.length > 0
    clear_toast
    @toast_ids.clear
  end
end

#clear_toastObject


185
186
187
188
# File 'dragon/console.rb', line 185

def clear_toast
  @toasted_at = nil
  @toast_duration = 0
end

#closeObject


181
182
183
# File 'dragon/console.rb', line 181

def close
  hide
end

#console_text_widthObject


48
49
50
# File 'dragon/console.rb', line 48

def console_text_width
  @console_text_width ||= ($gtk.logical_width - 20).idiv(font_style.letter_size.x)
end

#console_toggle_key_down?(args) ⇒ Boolean

Returns:

  • (Boolean)

270
271
272
# File 'dragon/console.rb', line 270

def console_toggle_key_down? args
  args.inputs.keyboard.key_down.any? console_toggle_keys
end

#console_toggle_keysObject


259
260
261
262
263
264
265
266
267
268
# File 'dragon/console.rb', line 259

def console_toggle_keys
  [
    :backtick!,
    :tilde!,
    :superscript_two!,
    :section_sign!,
    :ordinal_indicator!,
    :circumflex!,
  ]
end

#currently_toasting?Boolean

Returns:

  • (Boolean)

195
196
197
198
199
200
201
# File 'dragon/console.rb', line 195

def currently_toasting?
  return false if hidden?
  return false unless @show_reason == :toast
  return false unless @toasted_at
  return false if @toasted_at.elapsed?(5.seconds, Kernel.global_tick_count)
  return true
end

#defaults_set_command_extendedObject


634
635
636
637
638
639
640
641
# File 'dragon/console.rb', line 634

def defaults_set_command_extended
  {
    command: "puts 'Hello World'",
    histories: [],
    show_reason: nil,
    force: false
  }
end

#disableObject


75
76
77
# File 'dragon/console.rb', line 75

def disable
  @disabled = true
end

#enableObject


79
80
81
# File 'dragon/console.rb', line 79

def enable
  @disabled = false
end

#error_markersObject


575
576
577
# File 'dragon/console.rb', line 575

def error_markers
  ["exception:", "error:", "undefined method", "failed", "syntax", "deprecated"]
end

#eval_the_set_commandObject


304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'dragon/console.rb', line 304

def eval_the_set_command
  cmd = current_input_str.strip
  if cmd.length != 0
    @log_offset = 0
    prompt.clear

    @command_history.pop while @command_history.length >= @max_history
    @command_history.unshift cmd
    @command_history_index = -1
    @nonhistory_input = ''

    if cmd == 'quit' || cmd == ':wq' || cmd == ':q!' || cmd == ':q' || cmd == ':wqa'
      $gtk.request_quit
    else
      puts "-> #{cmd}"
      begin
        @last_command = cmd
        Kernel.eval("$results = (#{cmd})")
        if $results.nil?
          puts "=> nil"
        elsif $results == :console_silent_eval
        else
          puts "=> #{$results}"
        end
        @last_command_errored = false
      rescue Exception => e
        try_search_docs e
        puts  "* EXCEPTION: #{e}"
      end
    end
  end
end

#hidden?Boolean

Returns:

  • (Boolean)

149
150
151
# File 'dragon/console.rb', line 149

def hidden?
  !@visible
end

#hideObject


168
169
170
171
172
173
174
175
176
177
178
179
# File 'dragon/console.rb', line 168

def hide
  if visible?
    toggle
    @archived_log += @log
    if @archived_log.length > @max_log_lines
      @archived_log = @archived_log.drop(@archived_log.length - @max_log_lines)
    end
    @log.clear
    @show_reason = nil
    clear_toast
  end
end

#include_any_words?(text, words) ⇒ Boolean

Returns:

  • (Boolean)

583
584
585
# File 'dragon/console.rb', line 583

def include_any_words? text, words
  words.any? { |w| text.downcase.include?(w) && !text.downcase.include?(":#{w}") }
end

#include_error_marker?(text) ⇒ Boolean

Returns:

  • (Boolean)

571
572
573
# File 'dragon/console.rb', line 571

def include_error_marker? text
  include_any_words?(text.gsub('OutputsDeprecated', ''), error_markers)
end

#include_subdued_markers?(text) ⇒ Boolean

Returns:

  • (Boolean)

579
580
581
# File 'dragon/console.rb', line 579

def include_subdued_markers? text
  include_any_words? text, subdued_markers
end

#inputs_clear_command?(args) ⇒ Boolean

Returns:

  • (Boolean)

378
379
380
381
# File 'dragon/console.rb', line 378

def inputs_clear_command? args
  return false if @disabled
  args.inputs.keyboard.escape || args.inputs.keyboard.ctrl_g
end

#inputs_scroll_down_full?(args) ⇒ Boolean

Returns:

  • (Boolean)

362
363
364
365
366
# File 'dragon/console.rb', line 362

def inputs_scroll_down_full? args
  return false if @disabled
  args.inputs.keyboard.key_down.pagedown ||
    (args.inputs.keyboard.key_up.f && args.inputs.keyboard.key_up.control)
end

#inputs_scroll_down_half?(args) ⇒ Boolean

Returns:

  • (Boolean)

373
374
375
376
# File 'dragon/console.rb', line 373

def inputs_scroll_down_half? args
  return false if @disabled
  args.inputs.keyboard.ctrl_d
end

#inputs_scroll_up_full?(args) ⇒ Boolean

Returns:

  • (Boolean)

337
338
339
340
341
# File 'dragon/console.rb', line 337

def inputs_scroll_up_full? args
  return false if @disabled
  args.inputs.keyboard.key_down.pageup ||
    (args.inputs.keyboard.key_up.b && args.inputs.keyboard.key_up.control)
end

#inputs_scroll_up_half?(args) ⇒ Boolean

Returns:

  • (Boolean)

352
353
354
355
# File 'dragon/console.rb', line 352

def inputs_scroll_up_half? args
  return false if @disabled
  args.inputs.keyboard.ctrl_u
end

#load_historyObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'dragon/console.rb', line 56

def load_history
  @command_history.clear
  str = $gtk.ffi_file.read @history_fname
  return if str.nil?  # no history to load.

  str.chomp!("\n")  # Don't let endlines at the end cause extra blank line.
  str.chomp!("\r")
  str.each_line { |s|
    s.chomp!("\n")
    s.chomp!("\r")
    if s.length > 0
      @command_history.unshift s
      break if @command_history.length >= @max_history
    end
  }

  @command_history.uniq!
end

#mouse_wheel_scroll(args) ⇒ Object


388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'dragon/console.rb', line 388

def mouse_wheel_scroll args
  @inertia ||= 0

  if args.inputs.mouse.wheel && args.inputs.mouse.wheel.y > 0
    @inertia = 1
  elsif args.inputs.mouse.wheel && args.inputs.mouse.wheel.y < 0
    @inertia = -1
  end

  if args.inputs.mouse.click
    @inertia = 0
  end

  return if @inertia == 0

  if @inertia != 0
    @inertia = (@inertia * 0.7)
    if @inertia > 0
      @log_offset -= 1
    elsif @inertia < 0
      @log_offset += 1
    end
  end

  if @inertia.abs < 0.01
    @inertia = 0
  end

  if @log_offset > @log.size
    @log_offset = @log.size
  elsif @log_offset < 0
    @log_offset = 0
  end
end

#open(reason = nil) ⇒ Object


157
158
159
# File 'dragon/console.rb', line 157

def open reason = nil
  show reason
end

#perma_toast(id = nil, messages) ⇒ Object


251
252
253
# File 'dragon/console.rb', line 251

def perma_toast id = nil, messages
  toast_extended id, 600.seconds, *messages
end

#process_inputs(args) ⇒ Object


423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'dragon/console.rb', line 423

def process_inputs args
  if console_toggle_key_down? args
    args.inputs.text.clear
    toggle
  end

  return unless visible?

  args.inputs.text.each { |str| prompt << str }
  args.inputs.text.clear
  mouse_wheel_scroll args

  @log_offset = 0 if @log_offset < 0

  if args.inputs.keyboard.key_down.enter
    eval_the_set_command
  elsif args.inputs.keyboard.key_down.v
    if args.inputs.keyboard.key_down.control || args.inputs.keyboard.key_down.meta
      prompt << $gtk.ffi_misc.getclipboard
    end
  elsif args.inputs.keyboard.key_down.home
    prompt.move_cursor_home
  elsif args.inputs.keyboard.key_down.end
    prompt.move_cursor_end
  elsif args.inputs.keyboard.key_down.up
    if @command_history_index == -1
      @nonhistory_input = current_input_str
    end
    if @command_history_index < (@command_history.length - 1)
      @command_history_index += 1
      self.current_input_str = @command_history[@command_history_index].dup
    end
  elsif args.inputs.keyboard.key_down.down
    if @command_history_index == 0
      @command_history_index = -1
      self.current_input_str = @nonhistory_input
      @nonhistory_input = ''
    elsif @command_history_index > 0
      @command_history_index -= 1
      self.current_input_str = @command_history[@command_history_index].dup
    end
  elsif args.inputs.keyboard.key_down.left
    if args.inputs.keyboard.key_down.control
      prompt.move_cursor_left_word
    else
      prompt.move_cursor_left
    end
  elsif args.inputs.keyboard.key_down.right
    if args.inputs.keyboard.key_down.control
      prompt.move_cursor_right_word
    else
      prompt.move_cursor_right
    end
  elsif inputs_scroll_up_full? args
    scroll_up_full
  elsif inputs_scroll_down_full? args
    scroll_down_full
  elsif inputs_scroll_up_half? args
    scroll_up_half
  elsif inputs_scroll_down_half? args
    scroll_down_half
  elsif inputs_clear_command? args
    prompt.clear
    @command_history_index = -1
    @nonhistory_input = ''
  elsif args.inputs.keyboard.key_down.backspace
    prompt.backspace
  elsif args.inputs.keyboard.key_down.delete
    prompt.delete
  elsif args.inputs.keyboard.key_down.tab
    prompt.autocomplete
  end

  args.inputs.keyboard.key_down.clear
  args.inputs.keyboard.key_up.clear
  args.inputs.keyboard.key_held.clear
end

#ready?Boolean

Returns:

  • (Boolean)

145
146
147
# File 'dragon/console.rb', line 145

def ready?
  visible? && @toggled_at.elapsed?(@animation_duration, Kernel.global_tick_count)
end

#render(args) ⇒ Object


526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'dragon/console.rb', line 526

def render args
  return if !@toggled_at
  return if slide_progress == 0

  @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.
  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(slide_progress))
  y += line_height_px.to_f / 2.0

  ((@log.size - @log_offset) - 1).downto(0) do |idx|
    offset_after_write = write_primitive_and_return_offset args, left, y, @log[idx]
    y += offset_after_write
    break if y > top
  end

  # 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

  ((@archived_log.size - @log_offset) - 1).downto(0) do |idx|
    offset_after_write = write_primitive_and_return_offset args, left, y, @archived_log[idx], archived: true
    y += offset_after_write
    break if y > top
  end

  render_log_offset args
end

#render_log_offset(args) ⇒ Object


560
561
562
563
564
565
566
567
568
569
# File 'dragon/console.rb', line 560

def render_log_offset args
  return if @log_offset <= 0
  args.outputs.reserved << font_style.label(
    x: right.shift_left(5),
    y: top.shift_down(5 + line_height_px),
    text: "[#{@log_offset}/#{@log.size}]",
    color: @text_color,
    alignment_enum: 2
  )
end

#save_historyObject


52
53
54
# File 'dragon/console.rb', line 52

def save_history
  $gtk.ffi_file.write_root @history_fname, (@command_history.reverse.join "\n")
end

#scroll_down_fullObject


368
369
370
371
# File 'dragon/console.rb', line 368

def scroll_down_full
  @log_offset -= lines_on_one_page
  @log_offset = 0 if @log_offset < 0
end

#scroll_down_halfObject


383
384
385
386
# File 'dragon/console.rb', line 383

def scroll_down_half
  @log_offset -= lines_on_one_page.idiv(2)
  @log_offset = 0 if @log_offset < 0
end

#scroll_to_bottomObject


343
344
345
# File 'dragon/console.rb', line 343

def scroll_to_bottom
  @log_offset = 0
end

#scroll_up_fullObject


347
348
349
350
# File 'dragon/console.rb', line 347

def scroll_up_full
  @log_offset += lines_on_one_page
  @log_offset = @log.size if @log_offset > @log.size
end

#scroll_up_halfObject


357
358
359
360
# File 'dragon/console.rb', line 357

def scroll_up_half
  @log_offset += lines_on_one_page.idiv(2)
  @log_offset = @log.size if @log_offset > @log.size
end

#set_command(command, show_reason = nil) ⇒ Object


659
660
661
662
# File 'dragon/console.rb', line 659

def set_command command, show_reason = nil
  set_command_silent command, show_reason
  show show_reason
end

#set_command_extended(opts) ⇒ Object


643
644
645
646
647
648
649
650
651
# File 'dragon/console.rb', line 643

def set_command_extended opts
  opts = defaults_set_command_extended.merge opts
  @command_history.concat opts[:histories]
  @command_history << opts[:command]  if @command_history[-1] != opts[:command]
  self.current_input_str = opts[:command] if @command_set_at != Kernel.global_tick_count || opts[:force]
  @command_set_at = Kernel.global_tick_count
  @command_history_index = -1
  save_history
end

#set_command_silent(command, show_reason = nil) ⇒ Object


664
665
666
# File 'dragon/console.rb', line 664

def set_command_silent command, show_reason = nil
  set_command_with_history_silent command, [], show_reason
end

#set_command_with_history(command, histories, show_reason = nil) ⇒ Object


653
654
655
656
# File 'dragon/console.rb', line 653

def set_command_with_history command, histories, show_reason = nil
  set_command_with_history_silent command, histories, show_reason
  show show_reason
end

#set_command_with_history_silent(command, histories, show_reason = nil) ⇒ Object


630
631
632
# File 'dragon/console.rb', line 630

def set_command_with_history_silent command, histories, show_reason = nil
  set_command_extended command: command, histories: histories, show_reason: show_reason
end

#set_system_command(command, show_reason = nil) ⇒ Object


668
669
670
671
672
673
674
# File 'dragon/console.rb', line 668

def set_system_command command, show_reason = nil
  if $gtk.platform == "Mac OS X"
    set_command_silent "$gtk.system \"open #{command}\""
  else
    set_command_silent "$gtk.system \"start #{command}\""
  end
end

#should_tick?Boolean

Returns:

  • (Boolean)

519
520
521
522
523
524
# File 'dragon/console.rb', line 519

def should_tick?
  return false if !@toggled_at
  return false if slide_progress == 0
  return false if @disabled
  return visible?
end

#show(reason = nil) ⇒ Object


161
162
163
164
165
# File 'dragon/console.rb', line 161

def show reason = nil
  @shown_at = Kernel.global_tick_count
  @show_reason = reason
  toggle if hidden?
end

#subdued_markersObject


587
588
589
# File 'dragon/console.rb', line 587

def subdued_markers
  ["reloaded", "exported the", "~require~"]
end

#system_commandObject


676
677
678
679
680
681
682
# File 'dragon/console.rb', line 676

def system_command
  if $gtk.platform == "Mac OS X"
    "open"
  else
    "start"
  end
end

#tick(args) ⇒ Object


609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'dragon/console.rb', line 609

def tick args
  begin
    return if @disabled
    render 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."
  end
end

#toast(id = nil, *messages) ⇒ Object


255
256
257
# File 'dragon/console.rb', line 255

def toast id = nil, *messages
  toast_extended id, nil, *messages
end

#toast_extended(id = nil, duration = nil, *messages) ⇒ Object


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'dragon/console.rb', line 203

def toast_extended id = nil, duration = nil, *messages
  if !id.is_a?(Symbol)
    raise <<-S
* ERROR:
args.gtk.console.toast has the following signature:

  def toast id, *messages
  end

The id property uniquely defines the message and must be
a symbol.

After that, you can provide all the objects you want to
look at.

Example:

  args.gtk.console.toast :say_hello,
                        \"Hello world.\",
                        args.state.tick_count

Toast messages autohide after 5 seconds.

If you need to look at something for longer, use
args.gtk.console.perma_toast instead (which you can manually dismiss).

S
  end

  return if currently_toasting?
  return if @toast_ids.include? id
  @toasted_at = Kernel.global_tick_count
  log_once_info :perma_toast_tip, "Use console.perma_toast to show the toast for longer."
  dwim_duration = 5.seconds
  add_text "* toast :#{id}"
  puts "* TOAST: :#{id}"
  messages.each do |message|
    lines = message.to_s.wrapped_lines(self.console_text_width)
    dwim_duration += lines.length.seconds
    add_text "** #{message}"
    puts "** #{message}"
  end
  show :toast
  @toast_duration += duration || dwim_duration
  @toast_ids << id
  set_command "$gtk.console.hide"
end

#toggleObject


190
191
192
193
# File 'dragon/console.rb', line 190

def toggle
  @visible = !@visible
  @toggled_at = Kernel.global_tick_count
end

#try_search_docs(exception) ⇒ Object


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'dragon/console.rb', line 274

def try_search_docs exception
  string_e = "#{exception}"
  @last_command_errored = true

  if (string_e.include? "wrong number of arguments")
    method_name = ((string_e.split ":")[0].gsub "'", "")
    if !(method_name.include? " ")
      results = (Kernel.__docs_search_results__ method_name)
      if !results.include? "* DOCS: No results found."
        puts (results.join "\n")
        puts <<-S
* INFO: #{results.length} matches(s) found in DOCS for ~#{method_name}~ (see above).
You can search the documentation yourself using the following command in the Console:
#+begin_src ruby
  docs_search \"#{method_name}\"
#+end_src
S
        log_once_info :exported_search_results, "The search results above has been seen in logs/puts.txt and docs/search_results.txt."
      end
    end
  end
rescue Exception => se
  puts <<-S
* FATAL: ~GTK::Console#try_search_docs~
There was an exception searching for docs (~GTK::Console#try_search_docs~). You might want to let DragonRuby know about this.
** INNER EXCEPTION
#{se}
S
end

#visible?Boolean

Returns:

  • (Boolean)

153
154
155
# File 'dragon/console.rb', line 153

def visible?
  @visible
end

#write_line(args, left, y, str, archived: false) ⇒ Object


512
513
514
515
516
517
# File 'dragon/console.rb', line 512

def write_line(args, left, y, str, archived: false)
  color = color_for_log_entry(str)
  color = color.mult_alpha(0.5) if archived

  args.outputs.reserved << font_style.label(x: left.shift_right(10), y: y, text: str, color: color)
end

#write_primitive_and_return_offset(args, left, y, str, archived: false) ⇒ Object


501
502
503
504
505
506
507
508
509
510
# File 'dragon/console.rb', line 501

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 + 5, str[:w], str[:h], str[:path]].sprite
    return str[:h] + padding
  else
    write_line args, left, y, str, archived: archived
    return line_height_px
  end
end