divebar 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7108613d17c1c87e5fc31b59dbab1471c7e4905576df7544b2aac7fd41777ad7
4
+ data.tar.gz: 15958d89d8528b82138963ceb8ef053d7cf77ded05f86478074cc8a5d5a54d20
5
+ SHA512:
6
+ metadata.gz: d8fea8c2a44ba3463931ae18177a2b76ab16e59dbb3ff7af69d245dea784c716cfae5067cf1d80245f45b1346c19eb375545f0d58198cff3cdb87a51c6550d09
7
+ data.tar.gz: 75a8cd8bebdff60628e53810e25f0e4d393fae7f6536701db94591f6e7f5bc6bcd94d287054d7c87e5d69f83682c23f0db505b479139c54502db83a223aebb1f
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'divebar'
5
+ require 'divebar/plugins/clock'
6
+ require 'divebar/plugins/loadavg'
7
+ require 'divebar/drivers/view/erb'
8
+ require 'divebar/drivers/output/stdout'
9
+
10
+ divebar = Divebar::Instance.new
11
+
12
+ divebar.config.update_interval 1
13
+ divebar.config.plugins.register Divebar::Plugin::Clock
14
+ divebar.config.plugins.register Divebar::Plugin::Loadavg
15
+ divebar.config.views.driver Divebar::Driver::View::Erb
16
+ divebar.config.views.register 'base'
17
+ divebar.config.views.default 'base'
18
+ divebar.config.output_driver Divebar::Driver::Output::Stdout
19
+
20
+ divebar.start
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'divebar'
5
+ require 'divebar/plugins/clock'
6
+ require 'divebar/plugins/loadavg'
7
+ require 'divebar/drivers/view/erb'
8
+ require 'divebar/drivers/output/xsetroot'
9
+
10
+ divebar = Divebar::Instance.new
11
+
12
+ divebar.config.update_interval 1
13
+ divebar.config.plugins.register Divebar::Plugin::Clock
14
+ divebar.config.plugins.register Divebar::Plugin::Loadavg
15
+ divebar.config.views.driver Divebar::Driver::View::Erb
16
+ divebar.config.views.register 'base'
17
+ divebar.config.views.default 'base'
18
+ divebar.config.output_driver Divebar::Driver::Output::XSetRoot
19
+
20
+ divebar.start
@@ -0,0 +1,6 @@
1
+ require 'divebar/instance'
2
+ require 'divebar/plugin'
3
+ require 'divebar/pluginlist'
4
+ require 'divebar/viewlist'
5
+ require 'divebar/config'
6
+ require 'divebar/version'
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'divebar/pluginlist'
4
+ require 'divebar/viewlist'
5
+
6
+ module Divebar
7
+ class Config
8
+ attr_accessor :plugins, :views
9
+
10
+ def initialize(instance_bind)
11
+ @update_interval = 1
12
+ @plugins = Divebar::PluginList.new(instance_bind)
13
+ @views = Divebar::ViewList.new(instance_bind)
14
+ end
15
+
16
+ def update_interval(interval = nil)
17
+ @update_interval = interval unless interval.nil?
18
+ @update_interval
19
+ end
20
+
21
+ def output_driver(klass = nil, instance_bind = nil)
22
+ @output_driver = klass.new unless klass.nil?
23
+ @output_driver
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Divebar
4
+ module Driver
5
+ class Output
6
+ class Stdout
7
+ def draw(str)
8
+ puts str
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'XStoreName'
4
+
5
+ module Divebar
6
+ module Driver
7
+ class Output
8
+ class XSetRoot
9
+ def draw(str)
10
+ XStoreName.set_xname(str)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'divebar/version'
5
+
6
+ module Divebar
7
+ module Driver
8
+ class View
9
+ class Erb
10
+ def initialize(instance_bind)
11
+ @instance = instance_bind
12
+ end
13
+
14
+ def register_view(filepath)
15
+ ERB.new(File.read(find_file(filepath)))
16
+ end
17
+
18
+ def render(view)
19
+ view.result(@instance).chomp
20
+ end
21
+
22
+ private def find_file(filepath)
23
+ searchpath = [filepath,
24
+ "#{Dir.pwd}/views/#{filepath}",
25
+ "#{Dir.pwd}/views/#{filepath}.erb",
26
+ "#{File.dirname(__FILE__)}/views/#{filepath}",
27
+ "#{File.dirname(__FILE__)}/views/#{filepath}.erb"] +
28
+ Gem.path.map { |p| "#{p}/gems/divebar-#{Divebar::VERSION}/views/#{filepath}" } +
29
+ Gem.path.map { |p| "#{p}/gems/divebar-#{Divebar::VERSION}/views/#{filepath}.erb" }
30
+ realpath = searchpath.find { |file| File.exist?(file) }
31
+ raise IOError, "Could not find template file #{filepath} in searchpath #{searchpath}" if realpath.nil?
32
+
33
+ realpath
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+ require 'divebar/config'
5
+
6
+ module Divebar
7
+ # The Main class for Divebar; instantiate this with a config and run .loop
8
+ class Instance
9
+ attr_accessor :config, :data
10
+
11
+ def initialize
12
+ @data = OpenStruct.new
13
+ @config = Divebar::Config.new(binding())
14
+ end
15
+
16
+ def start
17
+ loop do
18
+ sleep config.update_interval
19
+ draw(render(config.views.default))
20
+ end
21
+ end
22
+
23
+ def draw(arg)
24
+ @config.output_driver.draw(arg)
25
+ end
26
+
27
+ def render(arg)
28
+ @config.views.driver.render(arg)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Divebar
4
+ class Plugin
5
+ attr_accessor :options
6
+
7
+ def initialize(instance_bind, options = {})
8
+ @options = options
9
+ @options[:update_interval] = 1 unless options[:update_interval]
10
+ @instance = instance_bind
11
+ end
12
+
13
+ def start
14
+ Thread.new do
15
+ loop do
16
+ @instance.eval("@data")[plugin_name] = tick
17
+ sleep options[:update_interval]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Divebar
4
+ class PluginList
5
+ attr_reader :list, :threads
6
+
7
+ def initialize(instance_bind)
8
+ @list = []
9
+ @threads = []
10
+ @instance = instance_bind
11
+ end
12
+
13
+ def register(plugin, **options)
14
+ case plugin.class
15
+ when String
16
+ @list << get_class(plugin).new(@instance, options)
17
+ @threads << @list.last.start
18
+ when Class
19
+ @list << plugin.new(@instance, options)
20
+ @threads << @list.last.start
21
+ else
22
+ raise ArgumentError, 'Expected Class Name or Class.to_s for plugin'
23
+ end
24
+ end
25
+
26
+ private def get_class(str)
27
+ str.split('::').inject(Object) do |mod, class_name|
28
+ mod.const_get(class_name)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'divebar/plugin'
4
+
5
+ module Divebar
6
+ class Plugin
7
+ class Clock < Divebar::Plugin
8
+ def tick
9
+ Time.now.to_s
10
+ end
11
+
12
+ def plugin_name
13
+ 'clock'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'divebar/plugin'
5
+
6
+ module Divebar
7
+ class Plugin
8
+ class Loadavg < Divebar::Plugin
9
+ def configure
10
+ options[:update_interval] = 5
11
+ end
12
+
13
+ def tick
14
+ File.read('/proc/loadavg').split
15
+ end
16
+
17
+ def plugin_name
18
+ 'loadavg'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Divebar
4
+ VERSION = '0.1.1'.freeze
5
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Divebar
4
+ class ViewList
5
+ attr_reader :list
6
+
7
+ def initialize(instance_bind)
8
+ @list = {}
9
+ @instance = instance_bind
10
+ end
11
+
12
+ def driver(klass = nil)
13
+ @driver = klass.new(@instance) unless klass.nil?
14
+ @driver
15
+ end
16
+
17
+ def default(viewname = nil)
18
+ @default = viewname unless viewname.nil?
19
+ list[@default]
20
+ end
21
+
22
+ def register(viewname)
23
+ raise 'Set the view driver before registering views' unless @driver
24
+
25
+ list[viewname] = @driver.register_view(viewname)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ <%= @data.clock %> :: <%= @data.loadavg.first %>
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: divebar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Bucky Wolfe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xstorename
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.0
33
+ description: A framework for building statusbars.
34
+ email: pmigneous@gmail.com
35
+ executables:
36
+ - divebar-example-stdout
37
+ - divebar-example-xsetroot
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - bin/divebar-example-stdout
42
+ - bin/divebar-example-xsetroot
43
+ - lib/divebar.rb
44
+ - lib/divebar/config.rb
45
+ - lib/divebar/drivers/output/stdout.rb
46
+ - lib/divebar/drivers/output/xsetroot.rb
47
+ - lib/divebar/drivers/view/erb.rb
48
+ - lib/divebar/instance.rb
49
+ - lib/divebar/plugin.rb
50
+ - lib/divebar/pluginlist.rb
51
+ - lib/divebar/plugins/clock.rb
52
+ - lib/divebar/plugins/loadavg.rb
53
+ - lib/divebar/version.rb
54
+ - lib/divebar/viewlist.rb
55
+ - views/base.erb
56
+ homepage: http://github.com/igneous/divebar
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: divebar
79
+ test_files: []