Class: Redcar::FilterCommand::ShowText

Inherits:
OutputFormat show all
Defined in:
lib/filter_command/formats/show.rb

Overview

An output format for displaying command output to the user in a specially-formatted way. Supported Formats:

  • Show as HTML: Displays command output in a new browser tab or window

  • Show as Popup: Displays command output in a text popup under the cursor in the current document

  • Show as HTML Popup: Displays command output in a popup under the cursor in the current document using HTML markup

  • Open as URL: Opens the command output as a URL in a new browser tab or window

Instance Method Summary collapse

Methods inherited from OutputFormat

#edit_tab_focussed?, formats, #missing_edit_tab, #newline, supported_types, #tab, #type

Instance Method Details

#format(text, type) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/filter_command/formats/show.rb', line 14

def format text, type
  name = "Command Output"
  case type
  when "Show as HTML"
    output = java.io.File.create_temp_file("output","html")
    output.delete_on_exit
    path = output.get_absolute_path
    File.open(path,'w') {|f| f.puts(text)}
    url = File.expand_path(path)
    Redcar::HtmlView::DisplayWebContent.new(name,url,false).run
  when "Open as URL"
    Redcar::HtmlView::DisplayWebContent.new(name,text.strip,false).run
  when "Show as HTML Popup"
    if edit_tab_focussed?
      Redcar::Application::Dialog.popup_html(text,:below_cursor)
    else
      missing_edit_tab type
    end
  when "Show as Popup"
    if edit_tab_focussed?
      Redcar::Application::Dialog.popup_text(name,text,:below_cursor)
    else
      missing_edit_tab type
    end
  when "Show as Tooltip"
    Redcar::Application::Dialog.tool_tip(text,:cursor)
  end
end