ruco 0.2.0.beta → 0.2.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -10
- data/Rakefile +10 -27
- data/Readme.md +26 -22
- data/VERSION +1 -1
- data/bin/ruco +6 -15
- data/lib/ruco.rb +0 -25
- data/lib/ruco/application.rb +1 -1
- data/lib/ruco/core_ext/object.rb +0 -26
- data/lib/ruco/core_ext/range.rb +0 -9
- data/lib/ruco/editor.rb +0 -1
- data/lib/ruco/editor_area.rb +0 -1
- data/lib/ruco/file_store.rb +5 -23
- data/lib/ruco/screen.rb +7 -61
- data/lib/ruco/style_map.rb +2 -2
- data/lib/ruco/window.rb +14 -19
- data/ruco.gemspec +22 -13
- data/spec/ruco/core_ext/range_spec.rb +0 -24
- data/spec/ruco/editor_spec.rb +11 -129
- data/spec/ruco/file_store_spec.rb +0 -45
- data/spec/ruco/screen_spec.rb +2 -39
- data/spec/spec_helper.rb +2 -6
- metadata +29 -22
- data/lib/ruco/array_processor.rb +0 -53
- data/lib/ruco/editor/colors.rb +0 -97
- data/lib/ruco/syntax_parser.rb +0 -33
- data/lib/ruco/tm_theme.rb +0 -45
- data/playground/benchmark_syntax_parser.rb +0 -23
- data/spec/fixtures/railscasts.tmTheme +0 -369
- data/spec/fixtures/slow.js +0 -4
- data/spec/fixtures/test.tmTheme +0 -186
- data/spec/ruco/array_processor_spec.rb +0 -46
- data/spec/ruco/syntax_parser_spec.rb +0 -74
- data/spec/ruco/tm_theme_spec.rb +0 -14
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'
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
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
|
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
|
-
- **
|
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
|
-
-
|
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
|
18
|
-
-
|
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
|
-
|
26
|
-
|
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
|
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
|
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.
|
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(
|
68
|
+
app.resize(lines, columns)
|
78
69
|
screen.clear_cache
|
79
70
|
else
|
80
71
|
result = app.key key
|
data/lib/ruco.rb
CHANGED
@@ -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'
|
data/lib/ruco/application.rb
CHANGED
@@ -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
|
250
|
+
:columns, :convert_tabs, :convert_newlines, :undo_stack_size
|
251
251
|
).merge(
|
252
252
|
:window => @options.nested(:window),
|
253
253
|
:history => @options.nested(:history),
|
data/lib/ruco/core_ext/object.rb
CHANGED
@@ -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
|
data/lib/ruco/core_ext/range.rb
CHANGED
data/lib/ruco/editor.rb
CHANGED
data/lib/ruco/editor_area.rb
CHANGED
@@ -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
|
|
data/lib/ruco/file_store.rb
CHANGED
@@ -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
|
-
|
40
|
+
Marshal.dump(value)
|
59
41
|
end
|
60
42
|
|
61
43
|
def deserialize(value)
|
data/lib/ruco/screen.rb
CHANGED
@@ -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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
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
|