Skip to content
Merged

more #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Usage
=====
```Bash
ruco file.rb
rvmsudo ruco /etc/hosts
```

Customize
Expand All @@ -45,16 +44,19 @@ Customize
# ~/.ruco.rb
Ruco.configure do
# set options
options.window_line_scroll_offset = 5 # default 1
options.window_line_scroll_offset = 5 # when to scroll if getting close to top/bottom, default 1
options.history_entries = 10 # default 100
options.editor_remove_trailing_whitespace_on_save = true # default false
options.editor_blank_line_before_eof_on_save = true # default false
options.editor_line_numbers = true # default false

# Use any Textmate theme e.g. from http://wiki.macromates.com/Themes/UserSubmittedThemes
# Use any Textmate 1 theme e.g. from https://github.com/filmgirl/TextMate-Themes
# (official wiki is dead http://wiki.macromates.com/Themes/UserSubmittedThemes)
# use a url that points directly to the theme, e.g. github 'raw' urls
options.color_theme = "https://raw.github.com/deplorableword/textmate-solarized/master/Solarized%20%28dark%29.tmTheme"
...
# if you use a dark background:
options.color_theme = "https://raw.githubusercontent.com/deplorableword/textmate-solarized/master/Solarized%20%28dark%29.tmTheme"
# if you use a light background:
# options.color_theme = "https://raw.githubusercontent.com/chriskempson/tomorrow-theme/refs/heads/master/textmate/Tomorrow-Night-Bright.tmTheme"

# bind a key
# - you can use Integers and Symbols
Expand All @@ -73,45 +75,43 @@ Ruco.configure do
end

# bind an existing action
puts @actions.keys
# puts @actions.keys

bind :"Ctrl+x", :quit
bind :"Ctrl+o", :save
bind :"Ctrl+k", :delete_line
bind :"Ctrl+a", :move_to_bol
# bind :"Ctrl+x", :quit
# bind :"Ctrl+o", :save
# bind :"Ctrl+k", :delete_line
# bind :"Ctrl+a", :move_to_bol

# create reusable actions
action(:first_line){ editor.move(:to_column, 0) }
bind :"Ctrl+u", :first_line
# action(:first_line){ editor.move(:to_column, 0) }
# bind :"Ctrl+u", :first_line
end
```

TIPS
====
- [Mac] arow-keys + Shift/Alt does not work in default terminal (use iTerm)
- [Tabs] Ruco does not like tabs. Existing tabs are displayed as single space and pressing tab inserts 2*space
- [RVM] `alias r="rvm 1.9.2 exec ruco"` and you only have to install ruco once
- [Ruby1.9] Unicode support -> install libncursesw5-dev before installing ruby
- [RVM] `alias r="rvm 3.3.0 exec ruco"` and you only have to install ruco once
- [ssh vs clipboard] access your desktops clipboard by installing `xauth` on the server and then using `ssh -X`
- [Alt key] if Alt does not work try your Meta/Win/Cmd key
- [Curses] `LoadError: cannot load such file -- curses` --> `rvm install 1.9.3 ----with-libcurses`

Architecture
============
Ruco is basically a lot of String manipulation separated in HTML style elements.
The only component dealing with the commandline interface are Screen and Keyboard. Therefore
everything is very simple to build and test since it returns a string or a e.g. cursor position.
Ruco is a lot of String manipulation separated in HTML style elements.
The only component dealing with the commandline interface are `Screen` and `Keyboard`.
Everything is simple to build and test since it returns a string or e.g. cursor position.

Writing/reading is done in a TextArea or a TextField (a TextArea with 1 line)
which are placed in Form`s.
Writing/reading is done in a `TextArea` or a `TextField` (a `TextArea` with 1 line)
which are placed in a `Form`.

The Application consists of a StatusBar, Editor, CommandBar and delegates actions to the currently active element.
The Application consists of a `StatusBar`, `Editor`, `CommandBar` and delegates actions to the currently active element.

To build the commandline output Editor/CommandBar return:
To build the commandline output `Editor`/`CommandBar` return:

- view -- text that should be displayed on the screen (complete content cropped via Window)
- style_map -- a big Array with style infos, e.g. 'on line 1 chars 5 to 7 are red'
- cursor -- where to draw the cursor
- `view` -- text that should be displayed on the screen (complete content cropped via Window)
- `style_map` -- a big Array with style infos, e.g. 'on line 1 chars 5 to 7 are red'
- `cursor` -- where to draw the cursor


TODO
Expand Down
66 changes: 36 additions & 30 deletions bin/ruco
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def parse_options
opts.on("-c", "--convert-tabs","Convert tabs to spaces") { options[:convert_tabs] = true }
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 }
opts.on("-n", "--no-colors","No colors -- helps performance / broken terminals") { options[:no_colors] = true }
opts.on("--colors","Force colors -- everything could be black") { options[:colors] = true }
opts.on("--debug-cache","Show caching in action") { options[:debug_cache] = true }
opts.on("--colors", "Force colors -- everything could be black") { options[:colors] = true }
opts.on("--debug-cache", "Show caching in action") { options[:debug_cache] = true }
opts.on("--debug-keys", "Show pressed keys") { options[:debug_keys] = true }
opts.on("-v", "--version","Show Version") do
opts.on("-v", "--version", "Show Version") do
require 'ruco/version'
puts Ruco::VERSION
exit
Expand All @@ -40,39 +40,44 @@ def parse_options
exit
end

if ARGV.size != 1
puts parser
exit 1
end

options
end

def log(stuff)
File.open('ruco.log','ab') { |f| f.puts stuff }
def log(message)
File.open('ruco.log','ab') { |f| f.puts message }
end

options = parse_options

options[:colors] = if options[:no_colors]
false
elsif options[:colors]
true
else
# so far the only terminal that supports it:
# - xterm-256color on osx
# - xterm on ubuntu 10.04+
if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
if ENV["TERM"] == 'xterm-256color'
true
else
require 'ruco/file_store'
if ENV['TERM'] == 'xterm'
# switch terminal, so curses knows we want colors
# setting ENV['TERM'] will sometimes crash un-rescue-able -> test if it works
possible = Ruco::FileStore.new('~/.ruco/cache').cache('color_possible') do
system(%{TERM=xterm-256color ruby -r curses -e 'Curses.noecho' > /dev/null 2>&1})
end
ENV['TERM'] = 'xterm-256color' if possible
end
options[:colors] =
if options[:no_colors]
false
elsif options[:colors]
true
# windows does not support colors, so disable it
elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
false
# this mostly is osx and works fine
elsif ENV["TERM"] == 'xterm-256color'
true
# xterm on ubuntu 10.04+ also supports colors, but ot might crash if we force it
elsif ENV['TERM'] == 'xterm'
require 'ruco/file_store'
# switch terminal, so curses knows we want colors
# setting ENV['TERM'] will sometimes crash un-rescue-able -> test if it works
possible = Ruco::FileStore.new('~/.ruco/cache').cache('color_possible') do
system(%{TERM=xterm-256color ruby -r curses -e 'Curses.noecho' > /dev/null 2>&1})
end
ENV['TERM'] = 'xterm-256color' if possible
possible
else
false
end
end
$ruco_colors = options[:colors]

require 'ruco'
Expand All @@ -83,9 +88,10 @@ Dispel::Screen.open(options) do |screen|

app = Ruco::Application.new(
ARGV[0],
:convert_tabs => options[:convert_tabs],
:undo_stack_size => options[:undo_stack_size],
:lines => screen.lines, :columns => screen.columns
convert_tabs: options[:convert_tabs],
undo_stack_size: options[:undo_stack_size],
lines: screen.lines,
columns: screen.columns
)

screen.draw *app.display_info
Expand Down
6 changes: 3 additions & 3 deletions lib/ruco/editor/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ def theme
memoize :theme

def download_into_file(url)
theme_store = FileStore.new('~/.ruco/cache', :string => true)
theme_store = FileStore.new('~/.ruco/cache', string: true)
theme_store.cache(url) do
require 'open-uri'
require 'openssl'
OpenURI.without_ssl_verification do
open(url).read
URI.open(url).read
end
end
File.expand_path(theme_store.file(url))
rescue => e
STDERR.puts "Could not download #{url} -- #{e}"
STDERR.puts "Could not download #{url} set via :color_theme option -- #{e}"
end
end
end
Expand Down