ruco 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.26
1
+ 0.0.27
data/bin/ruco CHANGED
@@ -19,9 +19,10 @@ Usage:
19
19
 
20
20
  Options:
21
21
  BANNER
22
+ opts.on("-c", "--convert-tabs","Convert tabs to spaces") { options[:convert_tabs] = true }
22
23
  opts.on("--debug-cache","Show caching in action") { options[:debug_cache] = true }
23
24
  opts.on("--debug-keys", "Show pressed keys") { options[:debug_keys] = true }
24
- opts.on('-v', '--version','Show Version'){
25
+ opts.on("-v", "--version","Show Version"){
25
26
  require 'ruco/version'
26
27
  puts Ruco::VERSION
27
28
  exit
@@ -117,7 +118,10 @@ end
117
118
 
118
119
  require 'ruco'
119
120
 
120
- app = Ruco::Application.new(ARGV[0], :lines => Curses.stdscr.maxy, :columns => Curses.stdscr.maxx)
121
+ app = Ruco::Application.new(ARGV[0],
122
+ :convert_tabs => @options[:convert_tabs],
123
+ :lines => Curses.stdscr.maxy, :columns => Curses.stdscr.maxx
124
+ )
121
125
 
122
126
  init_screen do
123
127
  show_app app
@@ -183,7 +183,7 @@ module Ruco
183
183
 
184
184
  def create_components
185
185
  @status_lines = 1
186
- @editor ||= Ruco::Editor.new(@file, :lines => editor_lines, :columns => @options[:columns])
186
+ @editor ||= Ruco::Editor.new(@file, :lines => editor_lines, :columns => @options[:columns], :convert_tabs => @options[:convert_tabs])
187
187
  @status = Ruco::StatusBar.new(@editor, :columns => @options[:columns])
188
188
  @command = Ruco::CommandBar.new(:columns => @options[:columns])
189
189
  command.cursor_line = editor_lines
@@ -12,6 +12,10 @@ class String
12
12
  found
13
13
  end
14
14
 
15
+ def tabs_to_spaces!
16
+ gsub!("\t",' ' * Ruco::TAB_SIZE)
17
+ end
18
+
15
19
  # stub for 1.8
16
20
  unless method_defined?(:force_encoding)
17
21
  def force_encoding(encoding)
data/lib/ruco/editor.rb CHANGED
@@ -8,6 +8,13 @@ module Ruco
8
8
  def initialize(file, options)
9
9
  @file = file
10
10
  content = (File.exist?(@file) ? File.read(@file) : '')
11
+ if content.include?("\t")
12
+ if options[:convert_tabs]
13
+ content.tabs_to_spaces!
14
+ else
15
+ raise "#{@file} contains tabs.\nRuco atm does not support tabs, but will happily convert them to spaces if started with --convert-tabs or -c"
16
+ end
17
+ end
11
18
  @text_area = TextArea.new(content, options)
12
19
  @modified = false
13
20
  end
data/lib/ruco/keyboard.rb CHANGED
@@ -19,7 +19,7 @@ class Keyboard
19
19
  loop do
20
20
  key = fetch_user_input
21
21
  if sequence_finished?
22
- sequence_to_keys(@sequence).each{|key| yield key }
22
+ sequence_to_keys(@sequence).each{|k| yield k }
23
23
  @sequence = []
24
24
  end
25
25
  next unless key
@@ -71,9 +71,9 @@ class Keyboard
71
71
  end
72
72
 
73
73
  def self.fetch_user_input
74
- key = @input.call
75
- return if key.nil? or key >= NOTHING
74
+ key = @input.call or return
76
75
  key = key.ord if key.is_a?(String) # ruby 1.9 fix
76
+ return if key >= NOTHING
77
77
  key
78
78
  end
79
79
 
@@ -129,7 +129,7 @@ class Keyboard
129
129
  if needs_paste_fix?(sequence)
130
130
  [bytes_to_string(sequence)]
131
131
  else
132
- # weird stuff that happens when connected via ssh
132
+ # when connected via ssh escape sequences are used
133
133
  if escape_sequence?(sequence)
134
134
  [escape_sequence_to_key(sequence)]
135
135
  else
@@ -3,7 +3,7 @@ module Ruco
3
3
  attr_reader :lines, :selection
4
4
 
5
5
  def initialize(content, options)
6
- @lines = tabs_to_spaces(content).naive_split("\n")
6
+ @lines = content.naive_split("\n")
7
7
  @options = options
8
8
  @line = 0
9
9
  @column = 0
@@ -91,7 +91,7 @@ module Ruco
91
91
  def insert(text)
92
92
  delete_content_in_selection if @selection
93
93
 
94
- text = tabs_to_spaces(text)
94
+ text.tabs_to_spaces!
95
95
  if text == "\n" and @column >= after_last_word
96
96
  current_whitespace = current_line.match(/^\s*/)[0]
97
97
  next_whitespace = lines[@line+1].to_s.match(/^\s*/)[0]
@@ -277,10 +277,6 @@ module Ruco
277
277
  end
278
278
  end
279
279
 
280
- def tabs_to_spaces(text)
281
- text.gsub("\t",' ' * Ruco::TAB_SIZE)
282
- end
283
-
284
280
  def delete_content_in_selection
285
281
  with_lines_as_string do |content|
286
282
  start = index_for_position(*@selection.first)
data/ruco.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.0.26"
8
+ s.version = "0.0.27"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
@@ -11,9 +11,18 @@ describe Ruco::Editor do
11
11
  @file = 'spec/temp.txt'
12
12
  end
13
13
 
14
- it "reads tab as spaces" do
15
- write("\t\ta")
16
- editor.view.should == " a\n\n\n"
14
+ describe 'convert tabs' do
15
+ it "reads tab as spaces when option is set" do
16
+ write("\t\ta")
17
+ editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5, :convert_tabs => true)
18
+ editor.view.should == " a\n\n\n"
19
+ end
20
+
21
+ it "raises when tabs are in content and option is not set" do
22
+ lambda{
23
+ editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5)
24
+ }.should raise_error
25
+ end
17
26
  end
18
27
 
19
28
  describe :move do
@@ -86,10 +86,18 @@ describe Keyboard do
86
86
  output.should == [11121, 324234]
87
87
  end
88
88
 
89
- it "recognises weird key combos" do
90
- type [27, 91, 49, 59, 50, 65]
91
- output.should == [:"Shift+up"]
89
+ it "recognises escape sequence for Shift+down" do
92
90
  type [27, 91, 49, 59, 50, 66]
93
91
  output.should == [:"Shift+down"]
94
92
  end
93
+
94
+ it "recognises escape sequence for Shift+up" do
95
+ type [27, 91, 49, 59, 50, 65]
96
+ output.should == [:"Shift+up"]
97
+ end
98
+
99
+ it "can handle strings from 1.9" do
100
+ type ['a']
101
+ output.should == ["a"]
102
+ end
95
103
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 26
9
- version: 0.0.26
8
+ - 27
9
+ version: 0.0.27
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- hash: -84268255
92
+ hash: 926649455
93
93
  segments:
94
94
  - 0
95
95
  version: "0"