ruco 0.2.0.beta → 0.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require File.expand_path('spec/spec_helper')
3
3
  describe Ruco::Screen do
4
4
  describe :curses_style do
5
5
  it "is 'normal' for nothing" do
6
- Ruco::Screen.curses_style(:normal).should == 256
6
+ Ruco::Screen.curses_style(:normal).should == Curses::A_NORMAL
7
7
  end
8
8
 
9
9
  it "is red for red" do
@@ -12,7 +12,7 @@ describe Ruco::Screen do
12
12
  end
13
13
 
14
14
  it "is reverse for reverse" do
15
- Ruco::Screen.curses_style(:reverse).should == 512
15
+ Ruco::Screen.curses_style(:reverse).should == Curses::A_REVERSE
16
16
  end
17
17
 
18
18
  it "raises on unknown style" do
@@ -20,42 +20,5 @@ describe Ruco::Screen do
20
20
  Ruco::Screen.curses_style(:foo)
21
21
  }.should raise_error
22
22
  end
23
-
24
- describe 'without colors' do
25
- before do
26
- Ruco::Screen.class_eval '@@styles = {}' # clear cache
27
- $ruco_colors = false
28
- end
29
-
30
- after do
31
- $ruco_colors = true
32
- end
33
-
34
- it "is 'normal' for normal" do
35
- Ruco::Screen.curses_style(:normal).should == Curses::A_NORMAL
36
- end
37
-
38
- it "is reverse for reverse" do
39
- Ruco::Screen.curses_style(:reverse).should == Curses::A_REVERSE
40
- end
41
-
42
- it "is normal for unknown style" do
43
- Ruco::Screen.curses_style(:foo).should == Curses::A_NORMAL
44
- end
45
- end
46
- end
47
-
48
- describe :html_to_terminal_color do
49
- # http://www.mudpedia.org/wiki/Xterm_256_colors
50
- [
51
- ['#ff0000', 196],
52
- ['#00ff00', 46],
53
- ['#0000ff', 21],
54
- ['#ffffff', 231]
55
- ].each do |html,term|
56
- it "converts #{html} to #{term}" do
57
- Ruco::Screen.html_to_terminal_color(html).should == term
58
- end
59
- end
60
23
  end
61
24
  end
@@ -1,12 +1,8 @@
1
1
  $LOAD_PATH.unshift 'lib'
2
- $ruco_colors = true
3
-
4
2
  require 'ruco'
5
3
  require 'timeout'
6
- require 'tempfile'
7
-
8
- silence_warnings{ Ruco::Editor::Colors::DEFAULT_THEME = 'spec/fixtures/test.tmTheme' }
9
4
 
5
+ require 'tempfile'
10
6
  class Tempfile
11
7
  def self.string_as_file(data)
12
8
  result = nil
@@ -25,4 +21,4 @@ class Time
25
21
  yield
26
22
  Time.now.to_f - t
27
23
  end
28
- end
24
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31098193
4
+ hash: 62196359
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
10
  - beta
11
- version: 0.2.0.beta
11
+ - 2
12
+ version: 0.2.0.beta2
12
13
  platform: ruby
13
14
  authors:
14
15
  - Michael Grosser
@@ -16,11 +17,11 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-09-23 00:00:00 +02:00
20
+ date: 2011-09-24 00:00:00 +02:00
20
21
  default_executable: ruco
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ">="
@@ -31,12 +32,12 @@ dependencies:
31
32
  - 9
32
33
  - 8
33
34
  version: 0.9.8
34
- requirement: *id001
35
35
  type: :runtime
36
36
  name: clipboard
37
+ version_requirements: *id001
37
38
  prerelease: false
38
39
  - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ">="
@@ -45,12 +46,12 @@ dependencies:
45
46
  segments:
46
47
  - 0
47
48
  version: "0"
48
- requirement: *id002
49
49
  type: :runtime
50
50
  name: ultraviolet1x
51
+ version_requirements: *id002
51
52
  prerelease: false
52
53
  - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
56
57
  - - ">="
@@ -59,9 +60,9 @@ dependencies:
59
60
  segments:
60
61
  - 0
61
62
  version: "0"
62
- requirement: *id003
63
63
  type: :runtime
64
64
  name: language_sniffer
65
+ version_requirements: *id003
65
66
  prerelease: false
66
67
  description:
67
68
  email: michael@grosser.it
@@ -80,7 +81,6 @@ files:
80
81
  - bin/ruco
81
82
  - lib/ruco.rb
82
83
  - lib/ruco/application.rb
83
- - lib/ruco/array_processor.rb
84
84
  - lib/ruco/command_bar.rb
85
85
  - lib/ruco/core_ext/array.rb
86
86
  - lib/ruco/core_ext/file.rb
@@ -89,7 +89,6 @@ files:
89
89
  - lib/ruco/core_ext/range.rb
90
90
  - lib/ruco/core_ext/string.rb
91
91
  - lib/ruco/editor.rb
92
- - lib/ruco/editor/colors.rb
93
92
  - lib/ruco/editor/history.rb
94
93
  - lib/ruco/editor/line_numbers.rb
95
94
  - lib/ruco/editor_area.rb
@@ -102,19 +101,12 @@ files:
102
101
  - lib/ruco/screen.rb
103
102
  - lib/ruco/status_bar.rb
104
103
  - lib/ruco/style_map.rb
105
- - lib/ruco/syntax_parser.rb
106
104
  - lib/ruco/text_area.rb
107
105
  - lib/ruco/text_field.rb
108
- - lib/ruco/tm_theme.rb
109
106
  - lib/ruco/version.rb
110
107
  - lib/ruco/window.rb
111
- - playground/benchmark_syntax_parser.rb
112
108
  - ruco.gemspec
113
- - spec/fixtures/railscasts.tmTheme
114
- - spec/fixtures/slow.js
115
- - spec/fixtures/test.tmTheme
116
109
  - spec/ruco/application_spec.rb
117
- - spec/ruco/array_processor_spec.rb
118
110
  - spec/ruco/command_bar_spec.rb
119
111
  - spec/ruco/core_ext/array_spec.rb
120
112
  - spec/ruco/core_ext/range_spec.rb
@@ -128,9 +120,7 @@ files:
128
120
  - spec/ruco/screen_spec.rb
129
121
  - spec/ruco/status_bar_spec.rb
130
122
  - spec/ruco/style_map_spec.rb
131
- - spec/ruco/syntax_parser_spec.rb
132
123
  - spec/ruco/text_area_spec.rb
133
- - spec/ruco/tm_theme_spec.rb
134
124
  - spec/ruco/window_spec.rb
135
125
  - spec/ruco_spec.rb
136
126
  - spec/spec_helper.rb
@@ -174,5 +164,22 @@ rubygems_version: 1.6.2
174
164
  signing_key:
175
165
  specification_version: 3
176
166
  summary: Commandline editor written in ruby
177
- test_files: []
178
-
167
+ test_files:
168
+ - spec/ruco/application_spec.rb
169
+ - spec/ruco/command_bar_spec.rb
170
+ - spec/ruco/core_ext/array_spec.rb
171
+ - spec/ruco/core_ext/range_spec.rb
172
+ - spec/ruco/core_ext/string_spec.rb
173
+ - spec/ruco/editor_spec.rb
174
+ - spec/ruco/file_store_spec.rb
175
+ - spec/ruco/form_spec.rb
176
+ - spec/ruco/history_spec.rb
177
+ - spec/ruco/keyboard_spec.rb
178
+ - spec/ruco/option_accessor_spec.rb
179
+ - spec/ruco/screen_spec.rb
180
+ - spec/ruco/status_bar_spec.rb
181
+ - spec/ruco/style_map_spec.rb
182
+ - spec/ruco/text_area_spec.rb
183
+ - spec/ruco/window_spec.rb
184
+ - spec/ruco_spec.rb
185
+ - spec/spec_helper.rb
@@ -1,53 +0,0 @@
1
- module Ruco
2
- class ArrayProcessor
3
- attr_accessor :lines
4
-
5
- def initialize
6
- @line_number = -1
7
- @lines = []
8
- @open_elements = []
9
- @still_open_elements = []
10
- end
11
-
12
- def open_tag(name, position)
13
- #puts "Open #{name} #{@line_number}:#{position}"
14
- @open_elements << [name, position]
15
- end
16
-
17
- def close_tag(name, position)
18
- #puts "Close #{name} #{@line_number}:#{position}"
19
- open_element = @open_elements.pop || @still_open_elements.pop
20
- @lines[@line_number] << [name, open_element.last...position]
21
- end
22
-
23
- def new_line(line)
24
- #puts "Line #{line}"
25
- # close elements only opened in last line
26
- @open_elements.each do |name, position|
27
- @lines[@line_number] << [name, position...@line.size]
28
- end
29
-
30
- # surround last line in still open elements from previouse lines
31
- @still_open_elements.each do |name,_|
32
- @lines[@line_number] << [name, 0...@line.size]
33
- end
34
-
35
- # mark open as 'still open'
36
- # and let them start on column 0 -> if closed in this line its 0...position
37
- @still_open_elements += @open_elements.map{|name,_| [name,0]}
38
- @open_elements = []
39
-
40
- # proceed with next line
41
- @line = line
42
- @line_number += 1
43
- @lines[@line_number] = []
44
- end
45
-
46
- def start_parsing(name);end
47
- def end_parsing(name);end
48
-
49
- def inspect
50
- @lines
51
- end
52
- end
53
- end
@@ -1,97 +0,0 @@
1
- require 'timeout'
2
-
3
- module Ruco
4
- class Editor
5
- module Colors
6
- DEFAULT_THEME = 'spec/fixtures/railscasts.tmTheme'
7
- STYLING_TIMEOUT = 4
8
-
9
- def style_map
10
- map = super
11
- return map if @colors_took_too_long
12
-
13
- # disable colors if syntax-parsing takes too long
14
- begin
15
- syntax = Timeout.timeout(STYLING_TIMEOUT) do
16
- syntax_info[@window.visible_lines]
17
- end
18
- rescue Timeout::Error
19
- # this takes too long, just go on without styles
20
- STDERR.puts "Styling takes too long, go on without me!"
21
- @colors_took_too_long = true
22
- return map
23
- end
24
-
25
- add_syntax_highlighting_to_style_map(map, syntax)
26
-
27
- if @selection
28
- # add selection a second time so it stays on top
29
- @window.add_selection_styles(map, @selection)
30
- end
31
- map
32
- end
33
-
34
- private
35
-
36
- def syntax_info
37
- if language = @options[:language]
38
- @syntax_info ||= {}
39
- language = [language.name.downcase, language.lexer]
40
- lines.map do |line|
41
- @syntax_info[line] ||= SyntaxParser.syntax_for_lines([line], language).first
42
- end
43
- else
44
- []
45
- end
46
- end
47
-
48
- def add_syntax_highlighting_to_style_map(map, syntax_info)
49
- return unless syntax_info
50
-
51
- $ruco_foreground = theme.foreground
52
- $ruco_background = theme.background
53
-
54
- syntax_info.each_with_index do |syntax_positions, line|
55
- next unless syntax_positions
56
- syntax_positions.each do |syntax_element, columns|
57
- columns = columns.move(-@window.left)
58
- style = style_for_syntax_element(syntax_element)
59
- if style and columns.first >= 0
60
- map.add(style, line, columns)
61
- end
62
- end
63
- end
64
- end
65
-
66
- def style_for_syntax_element(syntax_element)
67
- @style_for_element ||= {}
68
- @style_for_element[syntax_element] ||= begin
69
- _, style = theme.styles.detect{|name,style| syntax_element.start_with?(name) }
70
- style
71
- end
72
- end
73
-
74
- def theme
75
- @theme ||= begin
76
- file = download_into_file(@options[:color_theme]) if @options[:color_theme]
77
- file ||= DEFAULT_THEME
78
- Ruco::TMTheme.new(file)
79
- end
80
- end
81
-
82
- def download_into_file(url)
83
- theme_store = FileStore.new(File.expand_path('~/.ruco/themes'), :keep => 5, :pure => true)
84
- theme_store.cache(url) do
85
- require 'open-uri'
86
- require 'openssl'
87
- OpenURI.without_ssl_verification do
88
- open(url).read
89
- end
90
- end
91
- File.expand_path(theme_store.file(url))
92
- rescue => e
93
- STDERR.puts "Could not download #{url} -- #{e}"
94
- end
95
- end
96
- end
97
- end
@@ -1,33 +0,0 @@
1
- module Ruco
2
- module SyntaxParser
3
- # uv only offers certain syntax
4
- UV_CONVERT = {
5
- 'scss' => 'sass',
6
- 'html+erb' => 'html_rails',
7
- }
8
-
9
- def self.syntax_for_lines(lines, languages)
10
- if syntax = syntax_node(languages)
11
- processor = syntax.parse(lines.join("\n"), Ruco::ArrayProcessor.new)
12
- processor.lines
13
- else
14
- []
15
- end
16
- end
17
-
18
- def self.syntax_node(languages)
19
- @@syntax_node ||= {}
20
- @@syntax_node[languages] ||= begin
21
- found = nil
22
- fallbacks = languages.map{|l| UV_CONVERT[l] }.compact
23
-
24
- (languages + fallbacks).detect do |language|
25
- syntax = File.join(Uv.syntax_path, "#{language}.syntax")
26
- found = Textpow::SyntaxNode.load(syntax) if File.exist?(syntax)
27
- end
28
-
29
- found
30
- end
31
- end
32
- end
33
- end
@@ -1,45 +0,0 @@
1
- require 'plist'
2
-
3
- module Ruco
4
- class TMTheme
5
- attr_accessor :background, :foreground, :styles
6
-
7
- # TODO maybe later...
8
- #attr_accessor :name, :uuid, :comment, :line_highlight
9
-
10
- # not supported in Curses ...
11
- #attr_accessor :invisibles, :caret, :selection
12
-
13
- def initialize(file)
14
- raw = Plist.parse_xml(file)
15
- rules = raw['settings']
16
- @styles = {}
17
-
18
- # set global styles
19
- global = rules.shift['settings']
20
- self.background = global['background']
21
- self.foreground = global['foreground']
22
-
23
- # set scope styles
24
- rules.each do |rules|
25
- style = [
26
- rules['settings']['foreground'],
27
- rules['settings']['background'],
28
- ]
29
-
30
- next if style == [nil, nil] # some weird themes have rules without colors...
31
- next unless scope = rules['scope'] # some weird themes have rules without scopes...
32
-
33
- scope.split(/, ?/).map(&:strip).each do |scope|
34
- @styles[scope] = style unless nested_scope?(scope)
35
- end
36
- end
37
- end
38
-
39
- private
40
-
41
- def nested_scope?(scope)
42
- scope.include?(' ')
43
- end
44
- end
45
- end