From c11341c884de8e9ef57ca95b1588f17693b73b95 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 13 Jun 2025 21:00:32 -0700 Subject: [PATCH 1/4] readme polish --- Readme.md | 42 +++++++++++++++++++----------------------- bin/ruco | 10 +++++----- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/Readme.md b/Readme.md index 3c67c1b..9357e57 100644 --- a/Readme.md +++ b/Readme.md @@ -35,7 +35,6 @@ Usage ===== ```Bash ruco file.rb -rvmsudo ruco /etc/hosts ``` Customize @@ -45,7 +44,7 @@ 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 @@ -54,7 +53,6 @@ Ruco.configure do # Use any Textmate theme e.g. from 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" - ... # bind a key # - you can use Integers and Symbols @@ -73,16 +71,16 @@ 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 ``` @@ -90,28 +88,26 @@ 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 diff --git a/bin/ruco b/bin/ruco index 489d907..7d3421a 100755 --- a/bin/ruco +++ b/bin/ruco @@ -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 @@ -43,8 +43,8 @@ def parse_options 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 From 2cfc7f79c599157bd2af50f16d78b0bacaf1a2e5 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 13 Jun 2025 21:11:33 -0700 Subject: [PATCH 2/4] refactor --- bin/ruco | 56 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/bin/ruco b/bin/ruco index 7d3421a..4243c89 100755 --- a/bin/ruco +++ b/bin/ruco @@ -40,6 +40,11 @@ def parse_options exit end + if ARGV.size != 1 + puts parser + exit 1 + end + options end @@ -49,30 +54,30 @@ 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' @@ -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 From dbcc50ca924a864d1977ddb5aa1164a24c3b4bbb Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 13 Jun 2025 21:19:05 -0700 Subject: [PATCH 3/4] fix github urls --- Readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9357e57..d4742b3 100644 --- a/Readme.md +++ b/Readme.md @@ -52,7 +52,10 @@ Ruco.configure do # Use any Textmate theme e.g. from 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 From 1ab7f956bad2a514ed6d2ded12b778c88d0cf98e Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Fri, 13 Jun 2025 21:35:31 -0700 Subject: [PATCH 4/4] fix theme parsing --- Readme.md | 3 ++- lib/ruco/editor/colors.rb | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index d4742b3..f5f61c0 100644 --- a/Readme.md +++ b/Readme.md @@ -50,7 +50,8 @@ Ruco.configure do 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 # if you use a dark background: options.color_theme = "https://raw.githubusercontent.com/deplorableword/textmate-solarized/master/Solarized%20%28dark%29.tmTheme" diff --git a/lib/ruco/editor/colors.rb b/lib/ruco/editor/colors.rb index 298be3e..36ef83a 100644 --- a/lib/ruco/editor/colors.rb +++ b/lib/ruco/editor/colors.rb @@ -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