Project

General

Profile

unexist.dev

/

subtle

Assorted tidbits and projects

Sublets » History » Version 7

Version 6 (Anonymous, 01/21/2009 01:00 PM) → Version 7/66 (Anonymous, 01/21/2009 01:07 PM)

h1. Sublets\015\012\015\012[[Sublets]] Sublets\015\012\015\012[[Sublets|sublets]] are small "Ruby":http://www.ruby-lang.org scripts that provide the data for the statusbar. They are run in an embedded "Ruby":http://www.ruby-lang.org interpreter and are well included in the main loop of [[subtle]]. Every [[sublets|sublet]] [[sublet]] must either provide an update interval (in seconds) and will be updated accordingly or a file to _watch_. \015\012_The default update interval is 60s._\015\012\015\012h2. Types\015\012\015\012Currently there are two types of [[sublets]]:\015\012* [[sublets]] that are updated in a given interval\015\012* [[sublets]] that are updated when a file is modified (Via "inotify":http://en.wikipedia.org/wiki/Inotify)\015\012\015\012h2. Data\015\012\015\012The [[sublet]] data can be either of type "String":http://www.ruby-doc.org/core/classes/String.html or "Fixnum":http://www.ruby-doc.org/core/classes/Fixnum.html. "Strings":http://www.ruby-doc.org/core/classes/String.html are directly displayed and "Fixnums":http://www.ruby-doc.org/core/classes/Fixnum.html will be shown as a small meter.\015\012\015\012\015\012h2. Example\015\012\015\012Below is the code of a shipped [[sublet]] that displays the time. It should be really straight forward:\015\012\015\012<pre><code class="ruby">class Clock < Sublet\015\012 def initialize\015\012 self.interval = 60 # Set interval time\015\012 end\015\012\015\012 def run\015\012 self.data = Time.now().strftime("%d%m%y%H%M") # Set data\015\012 end\015\012end\015\012</code></pre>\015\012\015\012Interval and data can be updated via setter/getter functions.\015\012\015\012Another example for the inotify [[sublets|sublet]] sublet which is also included within [[subtle]]:\015\012\015\012<pre><code class="ruby">class Notify < Sublet\015\012 def initialize\015\012 self.path = "/tmp/watch"\015\012 end\015\012\015\012 def run\015\012 file = ""\015\012\015\012 File.open(self.path, "r") do |f|\015\012 file = f.read\015\012 end\015\012\015\012 self.data = file.chop || "subtle"\015\012 end\015\012end\015\012</code></pre>\015\012\015\012More soon..