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.
data/Gemfile CHANGED
@@ -1,11 +1,8 @@
1
1
  source :rubygems
2
2
 
3
3
  gem 'clipboard', '>=0.9.8'
4
- gem 'ultraviolet1x'
5
- gem 'language_sniffer'
6
4
 
7
5
  group :dev do # not development <-> would add unneeded development dependencies in gemspec
8
- gem 'oniguruma', :platform => :ruby_18
9
6
  gem 'ffi', :platform => [:mingw]
10
7
  gem 'rake'
11
8
  gem 'rspec', '~>2'
@@ -8,9 +8,6 @@ GEM
8
8
  bundler (~> 1.0.0)
9
9
  git (>= 1.2.5)
10
10
  rake
11
- language_sniffer (1.0.0)
12
- oniguruma (1.1.0)
13
- plist (3.1.0)
14
11
  rake (0.9.2)
15
12
  rspec (2.6.0)
16
13
  rspec-core (~> 2.6.0)
@@ -20,10 +17,6 @@ GEM
20
17
  rspec-expectations (2.6.0)
21
18
  diff-lcs (~> 1.1.2)
22
19
  rspec-mocks (2.6.0)
23
- textpow1x (0.11.0)
24
- plist (>= 3.0.1)
25
- ultraviolet1x (0.12.1)
26
- textpow1x (>= 0.11.0)
27
20
 
28
21
  PLATFORMS
29
22
  ruby
@@ -32,8 +25,5 @@ DEPENDENCIES
32
25
  clipboard (>= 0.9.8)
33
26
  ffi
34
27
  jeweler
35
- language_sniffer
36
- oniguruma
37
28
  rake
38
29
  rspec (~> 2)
39
- ultraviolet1x
data/Rakefile CHANGED
@@ -21,23 +21,19 @@ end
21
21
 
22
22
  task :try_color do
23
23
  require 'curses'
24
- # fix colors for xterm...
25
- #if Curses::has_colors?
26
- ENV['TERM'] += '-256color' if ENV['TERM'] == 'xterm'
27
- Curses::start_color
28
- # initialize every color we want to use
29
- # id, foreground, background
30
- #Curses.use_default_colors if defined? Curses.use_default_colors # 1.9 only, maybe helps to get real white...
31
- Curses::init_pair( 32, 253, 39 )
32
- #Curses::init_pair( 32, -1, -1 )
33
- #Curses::init_pair( Curses::COLOR_RED, Curses::COLOR_RED, Curses::COLOR_BLACK )
34
- #Curses::init_pair( Curses::COLOR_GREEN, Curses::COLOR_GREEN, Curses::COLOR_BLACK )
35
- #end
24
+ if Curses::has_colors?
25
+ Curses::start_color
26
+ # initialize every color we want to use
27
+ # id, foreground, background
28
+ Curses::init_pair( Curses::COLOR_BLACK, Curses::COLOR_BLACK, Curses::COLOR_BLACK )
29
+ Curses::init_pair( Curses::COLOR_RED, Curses::COLOR_RED, Curses::COLOR_BLACK )
30
+ Curses::init_pair( Curses::COLOR_GREEN, Curses::COLOR_GREEN, Curses::COLOR_BLACK )
31
+ end
36
32
 
37
33
  Curses.setpos(0,0)
38
- Curses.attrset(Curses::color_pair( 32 )) # fetch color pair with the id xxx
34
+ Curses.attrset(Curses.color_pair(Curses::COLOR_RED)) # fetch color pair with the id xxx
39
35
  Curses.addstr("xxxxxxxx\nyyyyyyy");
40
- Curses.attrset(Curses::color_pair( 32 ))
36
+ Curses.attrset(Curses.color_pair(Curses::COLOR_GREEN))
41
37
  Curses.addstr("xxxxxxxx\nyyyyyyy");
42
38
  Curses.getch
43
39
  end
@@ -65,19 +61,6 @@ task :key do
65
61
  end
66
62
  end
67
63
 
68
- task :parse_syntax do
69
- require 'ruco/array_processor'
70
- require 'ultra_pow_list'
71
- UltraPowList.make_loadable
72
- require 'textpow'
73
- require 'uv'
74
- puts ruby = File.join(Uv.path.first,'uv', 'syntax','ruby.syntax')
75
- syntax = Textpow::SyntaxNode.load(ruby)
76
- processor = Ruco::ArrayProcessor.new
77
- result = syntax.parse( "class Foo\n def xxx;end\nend", processor )
78
- puts result.inspect
79
- end
80
-
81
64
  begin
82
65
  require 'jeweler'
83
66
  Jeweler::Tasks.new do |gem|
data/Readme.md CHANGED
@@ -1,29 +1,41 @@
1
1
  Simple, extendable, test-driven commandline editor written in ruby, for Linux/Mac/Windows.
2
2
 
3
- Features:
3
+ ### Features
4
4
 
5
- - **Intuitive interface**
6
- - TextMate Syntax and Theme support
5
+ - **Desktop-like / intuitive interface**
7
6
  - selecting via Shift + arrow-keys (only Linux or iTerm) or 'select mode' Ctrl+b + arrow-keys
8
7
  - move line up/down (Alt+Ctrl+up/down)
9
8
  - Tab -> indent / Shift+Tab -> unindent
10
9
  - keeps indentation (+ paste-detection e.g. via Cmd+v)
11
10
  - change (*) + writable (!) indicators
12
11
  - find / go to line / delete line / search & replace
13
- - configuration via `~/.ruco.rb`
14
- - cut, copy and paste -> Ctrl+x/c/v
15
- - undo / redo
12
+ - configuration via `~/.ruco.rb` in Ruby
13
+ - Full clipboard support -> Ctrl+x/c/v
14
+ - undo / redo -> Ctrl+z/y
16
15
  - stays at last position when reopening a file
17
- - opens file at line with `ruco foo/bar.rb:32` syntax
18
- - keeps whatever newline format you use (\r \n \r\n)
16
+ - opens file at line e.g. `ruco foo/bar.rb:32`
17
+ - supports all newline formats
19
18
  - surrounds selection with quotes/braces (select abc + " --> "abc")
20
19
  - shortens long file names in the middle
21
20
  - (optional) remove trailing whitespace on save
22
21
  - (optional) blank line before eof on save
23
22
  - (optional) line numbers
24
23
 
25
- ![ruco with railscasts theme](http://dl.dropbox.com/u/2670385/Web/ruco-with-railscasts-theme.png)<br/>
26
- (to get colors on ruby 1.8, install oniguruma [OsX](http://blog.pastie.org/2010/01/oniguruma-on-snow-leopard.html) / [Ubuntu](http://blog.loftninjas.org/2008/09/25/installing-the-oniguruma-gem-on-debianubuntu/))
24
+ ### Architecture
25
+ Ruco is basically a lot of String manipulation separated in HTML style elements.
26
+ The only component dealing with the commandline interface are Screen and Keyboard. Therefore
27
+ everything is very simple to build and test since it returns a string or a e.g. cursor position.
28
+
29
+ Writing/reading is done in a TextArea or a TextField (a TextArea with 1 line)
30
+ which are placed in Form`s.
31
+
32
+ The Application consists of a StatusBar, Editor, CommandBar and delegates actions to the currently active element.
33
+
34
+ To build the commandline output Editor/CommandBar return:
35
+
36
+ - view -- text that should be displayed on the screen (complete content cropped via Window)
37
+ - style_map -- a big Array with style infos, e.g. 'on line 1 chars 5 to 7 are red'
38
+ - cursor -- where to draw the cursor
27
39
 
28
40
  Install
29
41
  =======
@@ -44,10 +56,6 @@ Customize
44
56
  options.editor_remove_trailing_whitespace_on_save = true # default false
45
57
  options.editor_blank_line_before_eof_on_save = true # default false
46
58
  options.editor_line_numbers = true # default false
47
-
48
- # Use any Textmate theme e.g. from http://wiki.macromates.com/Themes/UserSubmittedThemes
49
- # use a url that points directly to the theme, e.g. github 'raw' urls
50
- options.color_theme = "https://raw.github.com/deplorableword/textmate-solarized/master/Solarized%20%28dark%29.tmTheme"
51
59
  ...
52
60
 
53
61
  # bind a key
@@ -83,20 +91,16 @@ Customize
83
91
  TIPS
84
92
  ====
85
93
  - [Mac] arow-keys + Shift/Alt does not work in default terminal (use iTerm)
86
- - [Tabs] Ruco does not like tabs. Existing tabs are displayed as ' ' and pressing tab inserts 2*space
94
+ - [Tabs] Ruco does not like tabs. Existing tabs are displayed as single space and pressing tab inserts 2*space
87
95
  - [RVM] `alias r="rvm 1.9.2 exec ruco"` and you only have to install ruco once
88
- - [Ruby1.9] Unicode support -> install libncursesw5-dev before installing ruby (does not work for 1.8)
96
+ - [Ruby1.9] Unicode support -> install libncursesw5-dev before installing ruby
89
97
  - [ssh vs clipboard] access your desktops clipboard by installing `xauth` on the server and then using `ssh -X`
90
98
  - [Alt key] if Alt does not work try your Meta/Win/Cmd key
91
99
 
100
+
101
+
92
102
  TODO
93
103
  =====
94
- - only do syntax parsing for changed lines + selected lines <-> will not be redrawn anyhow
95
- - try to use complete file coloring as removed in 26d6da4
96
- - javascript syntax parsing is slow and often causes syntax-timeouts
97
- - some languages are still not mapped correctly to their syntax file
98
- [languages](https://github.com/grosser/language_sniffer/blob/master/lib/language_sniffer/languages.yml) <->
99
- [syntaxes](https://github.com/grosser/ultraviolet/tree/master/syntax)
100
104
  - do not fall back to 0:0 after undoing the first change
101
105
  - check writable status every x seconds (e.g. in background) -> faster while typing
102
106
  - search help e.g. 'Nothing found' '#4 of 6 hits' 'no more hits, start from beginning ?'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0.beta
1
+ 0.1.14
data/bin/ruco CHANGED
@@ -21,7 +21,6 @@ Options:
21
21
  BANNER
22
22
  opts.on("-c", "--convert-tabs","Convert tabs to spaces") { options[:convert_tabs] = true }
23
23
  opts.on("-u", "--undo-stack-size SIZE","Maximum size of the undo stack. 0 allows for a complete undo stack.") {|size| options[:undo_stack_size] = size.to_i }
24
- opts.on("-n", "--no-colors","No colors -- helps performance / broken terminals") { options[:no_colors] = true }
25
24
  opts.on("--debug-cache","Show caching in action") { options[:debug_cache] = true }
26
25
  opts.on("--debug-keys", "Show pressed keys") { options[:debug_keys] = true }
27
26
  opts.on("-v", "--version","Show Version"){
@@ -45,23 +44,15 @@ def log(stuff)
45
44
  File.open('ruco.log','ab'){|f| f.puts stuff }
46
45
  end
47
46
 
48
- options = parse_options
49
-
50
- # do not use colors if told so or the terminal does not support colors
51
- $ruco_colors = (
52
- not options[:no_colors] and
53
- RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ and # windows
54
- ENV['TERM'] != 'rxvt' and
55
- ENV['TERM'] !~ /-color$/
56
- )
47
+ @options = parse_options
57
48
 
58
49
  require 'ruco'
59
50
 
60
51
  # draw app and redraw after each keystroke (or paste)
61
- Ruco::Screen.open(options) do |screen|
52
+ Ruco::Screen.open(@options) do |screen|
62
53
  app = Ruco::Application.new(ARGV[0],
63
- :convert_tabs => options[:convert_tabs],
64
- :undo_stack_size => options[:undo_stack_size],
54
+ :convert_tabs => @options[:convert_tabs],
55
+ :undo_stack_size => @options[:undo_stack_size],
65
56
  :lines => screen.lines, :columns => screen.columns
66
57
  )
67
58
 
@@ -72,9 +63,9 @@ Ruco::Screen.open(options) do |screen|
72
63
  end
73
64
 
74
65
  Keyboard.output do |key|
75
- screen.debug_key(key) if options[:debug_keys]
66
+ screen.debug_key(key) if @options[:debug_keys]
76
67
  if key == :resize
77
- app.resize(screen.lines, screen.columns)
68
+ app.resize(lines, columns)
78
69
  screen.clear_cache
79
70
  else
80
71
  result = app.key key
@@ -1,5 +1,3 @@
1
- require 'language_sniffer'
2
-
3
1
  require 'ruco/version'
4
2
 
5
3
  require 'ruco/core_ext/object'
@@ -17,7 +15,6 @@ require 'ruco/file_store'
17
15
  require 'ruco/window'
18
16
  require 'ruco/screen'
19
17
  require 'ruco/style_map'
20
- require 'ruco/syntax_parser'
21
18
 
22
19
  require 'ruco/editor'
23
20
  require 'ruco/editor/line_numbers'
@@ -26,28 +23,6 @@ require 'ruco/status_bar'
26
23
  require 'ruco/command_bar'
27
24
  require 'ruco/application'
28
25
 
29
- if $ruco_colors
30
- begin
31
- # this can fail on ruby 1.8 <-> oniguruma is complicated to install
32
- require 'oniguruma' if RUBY_VERSION < '1.9.0'
33
-
34
- # there are some other gems out there like spox-textpow etc, so be picky
35
- gem 'plist'
36
- require 'plist'
37
- gem 'textpow1x'
38
- require 'textpow'
39
- gem 'ultraviolet1x'
40
- require 'uv'
41
-
42
- # we do not need there if any other color li failed
43
- require 'ruco/array_processor'
44
- require 'ruco/tm_theme'
45
- require 'ruco/editor/colors'
46
- rescue LoadError
47
- warn "Could not load color libs -- #{$!}"
48
- end
49
- end
50
-
51
26
  require 'ruco/form'
52
27
  require 'ruco/text_area'
53
28
  require 'ruco/editor_area'
@@ -247,7 +247,7 @@ module Ruco
247
247
  @status_lines = 1
248
248
 
249
249
  editor_options = @options.slice(
250
- :columns, :convert_tabs, :convert_newlines, :undo_stack_size, :color_theme
250
+ :columns, :convert_tabs, :convert_newlines, :undo_stack_size
251
251
  ).merge(
252
252
  :window => @options.nested(:window),
253
253
  :history => @options.nested(:history),
@@ -50,29 +50,3 @@ class Object
50
50
  Marshal.load(Marshal.dump(self))
51
51
  end unless defined? deep_copy
52
52
  end
53
-
54
- class Object
55
- # copy from active_support
56
- def silence_warnings
57
- with_warnings(nil) { yield }
58
- end unless defined? silence_warnings
59
-
60
- # copy from active_support
61
- def with_warnings(flag)
62
- old_verbose, $VERBOSE = $VERBOSE, flag
63
- yield
64
- ensure
65
- $VERBOSE = old_verbose
66
- end unless defined? with_warnings
67
- end
68
-
69
- # http://grosser.it/2010/07/23/open-uri-without-ssl-https-verification/
70
- module OpenURI
71
- def self.without_ssl_verification
72
- old = ::OpenSSL::SSL::VERIFY_PEER
73
- silence_warnings{ ::OpenSSL::SSL.const_set :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE }
74
- yield
75
- ensure
76
- silence_warnings{ ::OpenSSL::SSL.const_set :VERIFY_PEER, old }
77
- end
78
- end
@@ -9,13 +9,4 @@ class Range
9
9
  def last_element
10
10
  exclude_end? ? last.pred : last
11
11
  end unless defined? last_element
12
-
13
- # (1..2).move(2) == (3..4)
14
- def move(n)
15
- if exclude_end?
16
- (first + n)...(last + n)
17
- else
18
- (first + n)..(last + n)
19
- end
20
- end
21
12
  end
@@ -21,7 +21,6 @@ module Ruco
21
21
  end
22
22
 
23
23
  content = (File.exist?(@file) ? File.binary_read(@file) : '')
24
- @options[:language] ||= LanguageSniffer.detect(@file, :content => content).language
25
24
  content.tabs_to_spaces! if @options[:convert_tabs]
26
25
 
27
26
  # cleanup newline formats
@@ -2,7 +2,6 @@ module Ruco
2
2
  # everything that does not belong to a text-area
3
3
  # but is needed for Ruco::Editor
4
4
  class EditorArea < TextArea
5
- include Ruco::Editor::Colors if defined? Ruco::Editor::Colors # only colorize if all color libs are loaded
6
5
  include Ruco::Editor::LineNumbers
7
6
  include Ruco::Editor::History
8
7
 
@@ -19,28 +19,6 @@ module Ruco
19
19
  deserialize File.binary_read(file) if File.exist?(file)
20
20
  end
21
21
 
22
- def cache(key, &block)
23
- value = get(key)
24
- if value.nil?
25
- value = yield
26
- set(key, value)
27
- end
28
- value
29
- end
30
-
31
- def delete(key)
32
- FileUtils.rm(file(key))
33
- rescue Errno::ENOENT
34
- end
35
-
36
- def clear
37
- FileUtils.rm_rf(@folder)
38
- end
39
-
40
- def file(key)
41
- "#{@folder}/#{Digest::MD5.hexdigest(key)}.yml"
42
- end
43
-
44
22
  private
45
23
 
46
24
  def entries
@@ -54,8 +32,12 @@ module Ruco
54
32
  delete.each{|f| File.delete(f) }
55
33
  end
56
34
 
35
+ def file(key)
36
+ "#{@folder}/#{Digest::MD5.hexdigest(key)}.yml"
37
+ end
38
+
57
39
  def serialize(value)
58
- @options[:string] ? value : Marshal.dump(value)
40
+ Marshal.dump(value)
59
41
  end
60
42
 
61
43
  def deserialize(value)
@@ -1,7 +1,5 @@
1
1
  module Ruco
2
2
  class Screen
3
- @@styles = {}
4
-
5
3
  def initialize(options)
6
4
  @options = options
7
5
  @cache = []
@@ -12,16 +10,12 @@ module Ruco
12
10
  end
13
11
 
14
12
  def open(&block)
15
- if $ruco_colors and ENV['TERM'] == 'xterm'
16
- ENV['TERM'] += '-256color' # activate 256 colors
17
- end
18
13
  Curses.noecho # do not show typed chars
19
14
  Curses.nonl # turn off newline translation
20
15
  Curses.stdscr.keypad(true) # enable arrow keys
21
16
  Curses.raw # give us all other keys
22
17
  Curses.stdscr.nodelay = 1 # do not block -> we can use timeouts
23
18
  Curses.init_screen
24
- Curses.start_color if $ruco_colors and Curses.has_colors?
25
19
  yield self
26
20
  ensure
27
21
  Curses.clear # needed to clear the menu/status bar on windows
@@ -94,62 +88,14 @@ module Ruco
94
88
  yield # render the line
95
89
  end
96
90
 
97
- def self.curses_style(style)
98
- @@styles[style] ||= begin
99
- if $ruco_colors
100
- foreground = $ruco_foreground || '#ffffff'
101
- background = $ruco_background || '#000000'
102
-
103
- foreground, background = if style == :normal
104
- [foreground, background]
105
- elsif style == :reverse
106
- ['#000000', '#ffffff']
107
- else
108
- # :red or [:red, :blue]
109
- f,b = style
110
- b ||= background
111
- [f,b]
112
- end
113
-
114
- foreground = html_to_terminal_color(foreground)
115
- background = html_to_terminal_color(background)
116
- color_id(foreground, background)
117
- else # no colors
118
- if style == :reverse
119
- Curses::A_REVERSE
120
- else
121
- Curses::A_NORMAL
122
- end
123
- end
124
- end
125
- end
126
-
127
- # create a new color from foreground+background or reuse old
128
- # and return color-id
129
- def self.color_id(foreground, background)
130
- @@color_ids ||= {}
131
- @@color_ids[[foreground, background]] ||= begin
132
- # make a new pair with a unique id
133
- @@max_color_id ||= 0
134
- id = (@@max_color_id += 1)
135
- unless defined? RSpec # stops normal text-output, do not use in tests
136
- Curses::init_pair(id, foreground, background)
137
- end
138
- Curses.color_pair(id)
139
- end
140
- end
91
+ STYLES = {
92
+ :normal => 0,
93
+ :reverse => Curses::A_REVERSE
94
+ }
141
95
 
142
- COLOR_SOURCE_VALUES = 256
143
- COLOR_TARGET_VALUES = 5
144
- COLOR_DIVIDE = COLOR_SOURCE_VALUES / COLOR_TARGET_VALUES
145
- TERM_COLOR_BASE = 16
146
-
147
- def self.html_to_terminal_color(html_color)
148
- return unless html_color
149
- r = (html_color[1..2].to_i(16) / COLOR_DIVIDE) * 36
150
- g = (html_color[3..4].to_i(16) / COLOR_DIVIDE) * 6
151
- b = (html_color[5..6].to_i(16) / COLOR_DIVIDE) * 1
152
- TERM_COLOR_BASE + r + g + b
96
+ def self.curses_style(style)
97
+ return 0 unless style
98
+ STYLES[style] or raise("Unknown style #{style.inspect}")
153
99
  end
154
100
  end
155
101
  end