blight 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .bundle
3
+ config/*.yml
4
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "blight/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'blight'
7
+ s.version = Blight::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "ncurses with less cursing"
10
+ s.description = "Blight provides a sane interface to the very procedural ncurses API"
11
+ s.authors = ["Justin Searls"]
12
+ s.email = 'searls@gmail.com'
13
+ s.homepage = 'https://github.com/searls/blight'
14
+
15
+ s.add_dependency "ncurses-ruby"
16
+
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,119 @@
1
+ require 'ncurses'
2
+
3
+ module Blight
4
+
5
+ class RunsLoop
6
+ def run(options = {})
7
+ config = default_options.merge(options)
8
+
9
+ begin
10
+ Ncurses.initscr
11
+ Ncurses.raw
12
+ Ncurses.start_color if config[:color]
13
+ config[:echo] ? Ncurses.echo : Ncurses.noecho
14
+
15
+ yield window = Window.new
16
+
17
+ while window.open?
18
+ key = Ncurses.stdscr.getch
19
+ config[:listeners].each { |l| l.listen({value: key.chr}, window) }
20
+ end
21
+
22
+ ensure
23
+ Ncurses.endwin
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def default_options
30
+ {
31
+ color: true,
32
+ listeners: [ListensForQuitters.new],
33
+ echo: false
34
+ }
35
+ end
36
+
37
+ end
38
+
39
+ class Window
40
+
41
+ def initialize
42
+ @window = Ncurses.stdscr
43
+ end
44
+
45
+ def x
46
+ Ncurses.getcurx(@window)
47
+ end
48
+
49
+ def y
50
+ Ncurses.getcury(@window)
51
+ end
52
+
53
+ def width
54
+ Ncurses.getmaxx(@window)
55
+ end
56
+
57
+ def height
58
+ Ncurses.getmaxy(@window)
59
+ end
60
+
61
+ def print(string, x = x, y = y)
62
+ Ncurses.mvwprintw(@window, y, x, string)
63
+ refresh
64
+ end
65
+
66
+ def open?
67
+ !@closed
68
+ end
69
+
70
+ def close
71
+ @closed = true
72
+ end
73
+
74
+ def refresh
75
+ Ncurses.refresh
76
+ end
77
+
78
+ end
79
+
80
+ class RendersCenteredText
81
+ def initialize(window)
82
+ @window = window
83
+ end
84
+
85
+ def render(text)
86
+ center_x = @window.x + (@window.width - text.length) / 2
87
+ center_y = @window.height / 2
88
+ @window.print(text, center_x, center_y)
89
+ end
90
+ end
91
+
92
+ class UsesColors
93
+ def initialize(window)
94
+ @window = window
95
+ end
96
+
97
+ def use(foreground, background)
98
+ Ncurses.init_pair(1, find(foreground), find(background))
99
+ Ncurses.attron(Ncurses.COLOR_PAIR(1))
100
+ yield
101
+ Ncurses.attroff(Ncurses.COLOR_PAIR(1))
102
+ end
103
+
104
+ private
105
+
106
+ def find(color)
107
+ Ncurses.const_get("COLOR_#{color.to_s.upcase}")
108
+ end
109
+
110
+ end
111
+
112
+ class ListensForQuitters
113
+ def listen(event, window)
114
+ window.close if event[:value] == 'q'
115
+ end
116
+ end
117
+
118
+ end
119
+
@@ -0,0 +1,3 @@
1
+ module Blight
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Searls
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ncurses-ruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Blight provides a sane interface to the very procedural ncurses API
31
+ email: searls@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - Rakefile
39
+ - blight.gemspec
40
+ - lib/blight.rb
41
+ - lib/blight/version.rb
42
+ homepage: https://github.com/searls/blight
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: ncurses with less cursing
66
+ test_files: []