ruco 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -25,14 +25,18 @@ Customize
25
25
 
26
26
  # ~/.ruco.rb
27
27
  Ruco.configure do
28
- # bind a key, you can use Integers and Symbols
29
- # use "ruco --debug-keys foo" to see which keys are possible
30
- # or have a look at lib/ruco/keyboard.rb
28
+ # bind a key
29
+ # - you can use Integers and Symbols
30
+ # - use "ruco --debug-keys foo" to see which keys are possible
31
+ # - have a look at lib/ruco/keyboard.rb
31
32
  bind(:"Ctrl+e") do
32
- ask('delete ?') do |response|
33
- if response or not response
34
- editor.move(:to, 0, 0)
35
- editor.delete(9999)
33
+ ask('foo') do |response|
34
+ if response == 'bar'
35
+ editor.insert('baz')
36
+ else
37
+ editor.move(:to, 0,0)
38
+ editor.delete(99999)
39
+ editor.insert('FAIL!')
36
40
  end
37
41
  end
38
42
  end
@@ -40,11 +44,11 @@ Customize
40
44
  # bind an existing action
41
45
  puts @actions.keys
42
46
 
43
- bind(:"Ctrl+x", :quit)
44
- bind(:"Ctrl+o", :save)
45
- bind(:"Ctrl+k", :delete_line)
47
+ bind :"Ctrl+x", :quit
48
+ bind :"Ctrl+o", :save
49
+ bind :"Ctrl+k", :delete_line
46
50
 
47
- # define a new action and bind it to multiple keys
51
+ # create reusable actions
48
52
  action(:first){ editor.move(:to_column, 0) }
49
53
  bind(:"Ctrl+a", :first)
50
54
  bind(:home, :first)
@@ -58,7 +62,6 @@ TIPS
58
62
 
59
63
  TODO
60
64
  =====
61
- - limit possible file size to e.g. 1MB (would hang/be too slow with big files)
62
65
  - find next (Alt+n)
63
66
  - add selection colors to forms in command_bar
64
67
  - session storage (stay at same line/column when reopening)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.35
1
+ 0.0.36
data/lib/ruco/editor.rb CHANGED
@@ -12,7 +12,15 @@ module Ruco
12
12
 
13
13
  def initialize(file, options)
14
14
  @file = file
15
+
16
+ # check for size (10000 lines * 100 chars should be enough for everybody !?)
17
+ if File.exist?(@file) and File.size(@file) > (1024 * 1024)
18
+ raise "#{@file} is larger than 1MB, did you really want to open that with Ruco?"
19
+ end
20
+
15
21
  content = (File.exist?(@file) ? File.read(@file) : '')
22
+
23
+ # check for tabs
16
24
  if content.include?("\t")
17
25
  if options[:convert_tabs]
18
26
  content.tabs_to_spaces!
@@ -20,6 +28,7 @@ module Ruco
20
28
  raise "#{@file} contains tabs.\nRuco atm does not support tabs, but will happily convert them to spaces if started with --convert-tabs or -c"
21
29
  end
22
30
  end
31
+
23
32
  @saved_content = content
24
33
  @text_area = EditorArea.new(content, options)
25
34
  end
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.35"
8
+ s.version = "0.0.36"
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"]
@@ -12,8 +12,11 @@ describe Ruco::Editor do
12
12
  end
13
13
 
14
14
  describe 'convert tabs' do
15
- it "reads tab as spaces when option is set" do
15
+ before do
16
16
  write("\t\ta")
17
+ end
18
+
19
+ it "reads tab as spaces when option is set" do
17
20
  editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5, :convert_tabs => true)
18
21
  editor.view.should == " a\n\n\n"
19
22
  end
@@ -25,6 +28,23 @@ describe Ruco::Editor do
25
28
  end
26
29
  end
27
30
 
31
+ describe 'huge-files' do
32
+ it "does not try to open huge files" do
33
+ write('a'*(1024*1024 + 1))
34
+ lambda{
35
+ Ruco::Editor.new(@file, :lines => 3, :columns => 5)
36
+ }.should raise_error
37
+ end
38
+
39
+ it "opens large files and does not take forever" do
40
+ write('a'*(1024*1024))
41
+ Time.benchmark do
42
+ editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5)
43
+ editor.view
44
+ end.should < 1
45
+ end
46
+ end
47
+
28
48
  describe :move do
29
49
  before do
30
50
  write(" \n \n ")
@@ -678,7 +698,7 @@ describe Ruco::Editor do
678
698
  end
679
699
  end
680
700
 
681
- describe :changes? do
701
+ describe :modified? do
682
702
  it "is unchanged by default" do
683
703
  editor.modified?.should == false
684
704
  end
data/spec/spec_helper.rb CHANGED
@@ -13,4 +13,12 @@ class Tempfile
13
13
  end
14
14
  result
15
15
  end
16
+ end
17
+
18
+ class Time
19
+ def self.benchmark
20
+ t = Time.now.to_f
21
+ yield
22
+ Time.now.to_f - t
23
+ end
16
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 89
4
+ hash: 87
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 35
10
- version: 0.0.35
9
+ - 36
10
+ version: 0.0.36
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser