wmiirc-rumai

git clone git://oldgit.suckless.org/wmiirc-rumai/
Log | Files | Refs | README | LICENSE

commit bffe02424df9c6edcbf393be4b3e83c74b17d697
parent 8a52c14eba3ce745c89f5e51ddc1e6c3893000f8
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date:   Tue, 19 Sep 2006 17:55:54 -0700

[project @ f0dbde7efec23c15d756e4b0bd14f54e99a324eb]

[project @ 109]
* Added Ixp::Node#open method to reduce 9P traffic.
* Added ability to fetch a sub-node via method_missing, while not dereferencing it (reading its contents if it is a file), by adding an exclamation to the file name. For example, consider the following output in *wmiish*.

  >> Wmii.fs.bar.status.data

Diffstat:
fs.rb | 26++++++++++++++++++--------
wmiirc-config.rb | 32+++++++++++++++++---------------
2 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/fs.rb b/fs.rb @@ -23,7 +23,7 @@ require 'ixp' # Encapsulates access to the IXP file system. module Ixp - @@ixp = IXP::Client.new + @@ixp = IXP::Client.new unless defined? @@ixp # Creates a file at the given path. def self.create aPath @@ -90,6 +90,11 @@ module Ixp create! if aCreateIt && !exist? end + # Open this node for IO operation. + def open &aBlock # :yields: IO + Ixp.open @path, &aBlock + end + # Creates this node. def create! Ixp.create @path @@ -133,11 +138,11 @@ module Ixp File.dirname @path end - # Accesses the given sub-path. The contents of the sub-path are returned if it is a file. Otherwise, its node is returned if it is a directory. - def [] aSubPath + # Accesses the given sub-path. When aDeref is asserted, then the contents of the sub-path are returned if it is a file. + def [] aSubPath, aDeref = true child = Ixp::Node.new("#{@path}/#{aSubPath}") - if child.file? + if aDeref && child.file? child.read else child @@ -151,10 +156,15 @@ module Ixp # Provides easy access to sub-nodes. def method_missing aMeth, *aArgs - if aMeth.to_s =~ /=$/ - self[$`] = *aArgs - else - self[aMeth] + case aMeth.to_s + when /=$/ + self[$`] = *aArgs + + when /!$/ + self[$`, false] + + else + self[aMeth] end end end diff --git a/wmiirc-config.rb b/wmiirc-config.rb @@ -36,11 +36,12 @@ ACTION_MENU = find_programs('~/dry/apps/wmii/etc/wmii-3', File.dirname(__FILE__) ## UI configuration -FS.def.border = 2 - +FS.def.border = 1 FS.def.font = ENV['WMII_FONT'] = '-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1' + +# color order: foreground, background, border FS.def.selcolors = ENV['WMII_SELCOLORS'] = '#ffffff #285577 #4c7899' -FS.def.normcolors = ENV['WMII_NORMCOLORS'] = '#222222 #eeeeee #666666' +FS.def.normcolors = ENV['WMII_NORMCOLORS'] = '#e0e0e0 #0a0a0a #202020' #'#222222 #eeeeee #666666' FS.def.colmode = :default FS.def.colwidth = 0 @@ -408,27 +409,28 @@ FS.def.keys = SHORTCUTS.keys.join("\n") ## status bar Thread.new do - sb = Ixp::Node.new('/bar/status', true) + sb = FS.bar.status + sb.create! sb.colors = ENV['WMII_NORMCOLORS'] + sb.data!.open do |f| + loop do + diskSpace = `df -h ~`.split[-3..-1].join(' ') - loop do - diskSpace = `df -h ~`.split[-3..-1].join(' ') - - 10.times do - cpuLoad = File.read('/proc/loadavg').split[0..2].join(' ') + 10.times do + cpuLoad = File.read('/proc/loadavg').split[0..2].join(' ') - sb.data = "#{Time.now.to_s} | #{cpuLoad} | #{diskSpace}" - sleep 1 + f.write "#{Time.now.to_s} | #{cpuLoad} | #{diskSpace}" + sleep 1 + end end end end - ## WM event loop begin - IXP::Client.new.open('/event') do |io| - while event = io.read.chomp + IXP::Client.new.open('/event') do |f| + while event = f.read.chomp type, arg = event.split(' ', 2) case type.to_sym @@ -469,6 +471,6 @@ begin end end rescue EOFError - LOG.warn($$) {"wmii has been terminated"} + LOG.warn {"wmii has been terminated"} exit 1 end