Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Commit

Permalink
Added Config.term.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed May 29, 2009
1 parent 905222b commit 43980d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 29 additions & 0 deletions lib/sketches/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ module Config
# Directory to store temporary sketches in
TMPDIR = Dir.tmpdir

# Terminal to optionally run the editor within
TERM = nil

# Default editor to use
EDITOR = ENV['EDITOR']

# Default pause between checking if sketches were modified
PAUSE = 3

@@sketches_term = TERM
@@sketches_editor = EDITOR
@@sketches_tmpdir = TMPDIR
@@sketches_pause = PAUSE
Expand All @@ -55,6 +59,31 @@ def Config.tmpdir=(directory)
@@sketches_tmpdir = File.expand_path(dir)
end

#
# Returns the terminal to optionally run the editor within.
#
# Config.term
# # => "xterm"
#
def Config.term
@@sketches_term
end

#
# Sets the terminal to optionally run the editor within to the
# specified _new_term_. _new_term_ may either be a String or a
# Proc.
#
# Config.term = 'gnome-terminal'
#
# Config.term = lambda { |cmd|
# "xterm -fg gray -bg black -e #{cmd.dump} &"
# }
#
def Config.term=(new_term)
@@sketches_term = new_term
end

#
# Returns the current editor to use for editing sketches.
#
Expand Down
9 changes: 7 additions & 2 deletions lib/sketches/sketches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,26 @@ module Sketches
# _options_ may contain the following keys:
# <tt>:tmpdir</tt>:: Directory to store temporary sketches in.
# Defaults to Dir.tmpdir if unspecified.
# <tt>:term</tt>:: The terminal to optionally run the editor within.
# <tt>:editor</tt>:: The editor to use to edit sketches.
# <tt>:pause</tt>:: The number of seconds to pause in-between
# checking if any sketches were modified.
#
# Sketches.config :editor => 'gvim', :pause => 2
#
# Sketches.config :editor => lambda { |path|
# "xterm -fg gray -bg black -e vim #{path} &"
# Sketches.config :editor => 'vim', :term => lambda { |cmd|
# "xterm -fg gray -bg black -e #{cmd.dump} &"
# }
#
def Sketches.config(options={})
if options[:tmpdir]
Config.tmpdir = options[:tmpdir]
end

if options[:term]
Config.term = options[:term]
end

if options[:editor]
Config.editor = options[:editor]
end
Expand Down

0 comments on commit 43980d3

Please sign in to comment.