Sublets » History » Version 13
Version 12 (Anonymous, 04/27/2009 10:39 PM) → Version 13/66 (Anonymous, 08/10/2009 07:53 AM)
h1. Sublets\015\012\015\012[[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]].\015\012\015\012Unit [[subtle]]. Every [[sublets|sublet]] must either provide an update interval (in seconds) and will be updated accordingly or a file to _watch_. _The default update interval is 60s._\015\012\015\012Unit tests for [[Subtlets|sublets]] are also included. [[Development|Read more about unit tests]]\015\012\015\012h2. Types\015\012\015\012Currently there are two types of [[Sublets|sublets]]:\015\012* [[sublets]] that are updated by in a given interval in seconds (default 60s)\015\012* interval\015\012* [[sublets]] that are updated when a file is modified (Via "inotify":http://en.wikipedia.org/wiki/Inotify)\015\012\015\012The "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, everything else "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 ignored.\015\012\015\012h2. Customization\015\012\015\012The color of the ouput of shown as a [[sublet|Sublets]] can be changed in this way:\015\012\015\012<pre><code class="ruby">self.data = color("#ff0000") + "su" + color("#00ff00") + "bt" + color("#0000ff") + "le"</code></pre>\015\012\015\012There small meter.\015\012\015\012\015\012h2. Example\015\012\015\012Below is also a way to add a "x bitmap":http://en.wikipedia.org/wiki/XBM to a [[Sublets|sublet]]:\015\012\015\012<pre><code class="ruby">self.data = icon("/usr/share/icons/subtle.xbm") + "subtle"</code></pre>\015\012\015\012h2. Examples\015\012\015\012Below is the code of a shipped [[sublet|sublets]] [[sublet]] that displays the time. It should be really straight forward:\015\012\015\012<pre><code class="ruby">class Clock < Subtle::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\012Another 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":http://en.wikipedia.org/wiki/Inotify inotify [[sublets|sublet]] which is also included within [[subtle]]:\015\012\015\012<pre><code class="ruby">class Notify < Subtle::Sublet\015\012 def initialize\015\012 self.path = "/tmp/watch"\015\012 end\015\012\015\012 def run\015\012 begin\015\012 file = ""\015\012\015\012 File.open(self.path, "r") do |f|\015\012 self.data file = IO.readlines(self.path).first.chop #< Read data and strip\015\012 f.read\015\012 rescue => err #< Catch error\015\012 puts err\015\012 end\015\012\015\012 self.data = file.chop || "subtle"\015\012 end\015\012 end\015\012end\015\012</code></pre>\015\012\015\012{{tocnavi(Subtler,Quickstart,Grabs)}}