Module: Wmiirc
- Extended by:
- Wmiirc
- Included in:
- Wmiirc, Sandbox
- Defined in:
- lib/wmiirc/handler.rb,
lib/wmiirc.rb,
lib/wmiirc/menu.rb,
lib/wmiirc/config.rb,
lib/wmiirc/system.rb,
lib/wmiirc/import.rb,
lib/wmiirc/loader.rb
Overview
DSL for wmiirc configuration.
Defined Under Namespace
Modules: Import, Loader Classes: Config, Handler, Sandbox
Constant Summary
- DIR =
path to user's wmii configuration directory
File.dirname(File.dirname(__FILE__))
- LOG =
keep a log file to aid the user in debugging
Logger.new(File.join(DIR, 'wmiirc.log'))
- SANDBOX =
Sandbox.new
- HISTORY_DIR =
File.join(DIR, 'history')
- EVENTS =
Handler.new
- ACTIONS =
Handler.new
- KEYS =
Handler.new
Instance Method Summary (collapse)
-
- (Object) action(*a, &b)
If a block is given, registers a handler for the given action and returns the handler.
-
- (Boolean) action?(name)
Checks if a handler for the given action name has been registered.
-
- (Object) actions
Returns a list of registered action names.
-
- (Object) click_menu(choices, initial = nil)
Shows a menu (where the user must click a menu item using their mouse to make a choice) with the given items and returns the chosen item.
-
- (Object) client_menu(*key_menu_args)
Shows a #key_menu containing all currently available clients and returns the chosen client.
-
- (Object) dialog(message, *arguments)
Shows a dialog box containing the given message.
-
- (Object) event(*a, &b)
If a block is given, registers a handler for the given event and returns the handler.
-
- (Boolean) event?(name)
Checks if a handler for the given event name has been registered.
-
- (Object) events
Returns a list of registered event names.
-
- (Object) index_menu(choices, *key_menu_args)
Shows a #key_menu containing the given choices and returns the index of the chosen item.
-
- (Object) key(*a, &b)
If a block is given, registers a handler for the given keypress name and returns the handler.
-
- (Boolean) key?(name)
Checks if a handler for the given keypress name has been registered.
-
- (Object) key_menu(choices, prompt, history_name = nil)
Shows a menu (where the user must press keys on their keyboard to make a choice) with the given items and returns the chosen item.
-
- (Object) keys
Returns a list of registered keypress names.
-
- (Object) launch(*args)
Runs #launch! inside the present working directory of the currently focused client or, if undeterminable, that of wmii.
-
- (Object) launch!(command, *arguments_then_wihack_options)
Launches the given command in the background.
-
- (Object) notify(title, message, icon = 'dialog-information', *arguments)
Shows a notification with the given title and message.
Instance Method Details
- (Object) action(*a, &b)
If a block is given, registers a handler for the given action and returns the handler. Otherwise, executes all handlers for the given action.
65 66 67 |
# File 'lib/wmiirc/handler.rb', line 65 def action(*a, &b) ACTIONS.handle(*a, &b) end |
- (Boolean) action?(name)
Checks if a handler for the given action name has been registered.
72 73 74 |
# File 'lib/wmiirc/handler.rb', line 72 def action? name ACTIONS.key? name end |
- (Object) actions
Returns a list of registered action names.
79 80 81 |
# File 'lib/wmiirc/handler.rb', line 79 def actions ACTIONS.keys end |
- (Object) click_menu(choices, initial = nil)
Shows a menu (where the user must click a menu item using their mouse to make a choice) with the given items and returns the chosen item.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wmiirc/menu.rb', line 68 def choices, initial=nil command = ['wmii9menu'] if initial command << '-i' unless choices.include? initial initial = "<<#{initial}>>:" command << initial end command << initial end command.concat choices choice = `#{command.shelljoin}`.chomp choice unless choice.empty? end |
- (Object) client_menu(*key_menu_args)
Shows a #key_menu containing all currently available clients and returns the chosen client.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/wmiirc/menu.rb', line 93 def * clients = Rumai.clients choices = clients.map do |c| "#{c[:label].read.downcase} @#{c[:tags].read}" end if index = (choices, *) clients[index] end end |
- (Object) dialog(message, *arguments)
Shows a dialog box containing the given message.
This is a “fire and forget” operation. The result of the launched dialog box is NOT returned by this method!
118 119 120 |
# File 'lib/wmiirc/system.rb', line 118 def dialog , *arguments launch! 'xmessage', '-nearmouse', *arguments, , type: 'DIALOG' end |
- (Object) event(*a, &b)
If a block is given, registers a handler for the given event and returns the handler. Otherwise, executes all handlers for the given event.
42 43 44 |
# File 'lib/wmiirc/handler.rb', line 42 def event(*a, &b) EVENTS.handle(*a, &b) end |
- (Boolean) event?(name)
Checks if a handler for the given event name has been registered.
49 50 51 |
# File 'lib/wmiirc/handler.rb', line 49 def event? name EVENTS.key? name end |
- (Object) events
Returns a list of registered event names.
56 57 58 |
# File 'lib/wmiirc/handler.rb', line 56 def events EVENTS.keys end |
- (Object) index_menu(choices, *key_menu_args)
Shows a #key_menu containing the given choices and returns the index of the chosen item.
110 111 112 113 114 115 |
# File 'lib/wmiirc/menu.rb', line 110 def choices, * choices = choices.each_with_index.map {|c,i| "#{c}\t#{i}" } if target = (choices, *) target[/\d+\z/].to_i end end |
- (Object) key(*a, &b)
If a block is given, registers a handler for the given keypress name and returns the handler. Otherwise, executes all handlers for the given keypress name.
89 90 91 |
# File 'lib/wmiirc/handler.rb', line 89 def key(*a, &b) KEYS.handle(*a, &b) end |
- (Boolean) key?(name)
Checks if a handler for the given keypress name has been registered.
96 97 98 |
# File 'lib/wmiirc/handler.rb', line 96 def key? name KEYS.key? name end |
- (Object) key_menu(choices, prompt, history_name = nil)
Shows a menu (where the user must press keys on their keyboard to make a choice) with the given items and returns the chosen item.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wmiirc/menu.rb', line 24 def choices, prompt, history_name=nil command = ['wimenu'] command.push '-p', prompt.to_s if prompt if history_name history_file = File.join(HISTORY_DIR, history_name.to_s) if File.exist? history_file # show history *before* actual choices in menu history = File.readlines(history_file).map(&:chomp) choices = (history & choices).reverse.concat(choices).uniq end end IO.popen(command, 'r+') do || .puts choices .close_write choice = .read unless choice.empty? if history_name # record choice in history for use next time File.open(history_file, 'a') {|f| f.puts choice } end choice end end end |
- (Object) keys
Returns a list of registered keypress names.
103 104 105 |
# File 'lib/wmiirc/handler.rb', line 103 def keys KEYS.keys end |
- (Object) launch(*args)
Runs #launch! inside the present working directory of the currently focused client or, if undeterminable, that of wmii.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wmiirc/system.rb', line 18 def launch *args if label = curr_client.label.read rescue nil label.encode(Encoding::UTF_8, undef: :replace, replace: ''). split(/[\s\[\]\{\}\(\)<>"':]+/).reverse_each do |word| if File.exist? path = File.(word) path = File.dirname(path) unless File.directory? path Dir.chdir(path) { launch! *args } return end end end launch! *args end |
- (Object) launch!(command, *arguments_then_wihack_options)
Launches the given command in the background.
Examples
Launch a self-contained shell command (while making sure that the arguments within the shell command are properly quoted):
launch! "xmessage 'hello world' '#{Time.now}'"
Launch a command with explicit arguments (while not having to worry about shell-quoting those arguments):
launch! 'xmessage', 'hello world', Time.now.to_s
Launch a command on the floating layer (treating it as a dialog box) using the `wihack` program:
launch! 'xmessage', 'hello world', Time.now.to_s, type: 'DIALOG'
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/wmiirc/system.rb', line 63 def launch! command, * *arguments, = unless .nil? or .kind_of? Hash arguments.push = nil end unless arguments.empty? command = [command, *arguments].shelljoin end if wihack_argv = .map {|k,v| ["-#{k}", v] }.flatten command = "wihack #{wihack_argv.shelljoin} #{command}" end spawn command end |
- (Object) notify(title, message, icon = 'dialog-information', *arguments)
Shows a notification with the given title and message.
This is a “fire and forget” operation. The result of the notification command is NOT returned by this method!
101 102 103 104 |
# File 'lib/wmiirc/system.rb', line 101 def notify title, , icon='dialog-information', *arguments Rumai.fs.event.write "Notice #{title}: #{}\n" launch! 'notify-send', '-i', icon, title, , *arguments end |