Module: Ruco::Editor::Colors

Included in:
Ruco::EditorArea
Defined in:
lib/ruco/editor/colors.rb

Constant Summary collapse

DEFAULT_THEME =
File.expand_path('../../../../spec/fixtures/railscasts.tmTheme',__FILE__)
STYLING_TIMEOUT =
4

Instance Method Summary collapse

Instance Method Details

#style_mapObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruco/editor/colors.rb', line 9

def style_map
  $ruco_screen && $ruco_screen.options[:foreground] = theme.foreground
  $ruco_screen && $ruco_screen.options[:background] = theme.background
  map = super

  return map if @colors_took_too_long or not @options[:language]

  # disable colors if syntax-parsing takes too long
  begin
    syntax = Timeout.timeout(STYLING_TIMEOUT) do
      syntax_info[@window.visible_lines]
    end
  rescue Timeout::Error
    # this takes too long, just go on without styles
    STDERR.puts "Styling takes too long, go on without me!"
    @colors_took_too_long = true
    return map
  end

  if syntax
    add_syntax_highlighting_to_style_map(map, syntax)

    # add selection a second time so it stays on top
    @window.add_selection_styles(map, @selection) if @selection
  end

  map
end