tty_slides 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  require 'delegate'
2
2
 
3
- class MainWindow < SimpleDelegator
4
- def initialize window
5
- super
3
+ class TtySlides::MainWindow < SimpleDelegator
4
+ def initialize window, title=''
5
+ @title = title
6
+ super window
6
7
  refresh
7
8
  end
8
9
 
@@ -13,7 +14,7 @@ class MainWindow < SimpleDelegator
13
14
  def refresh
14
15
  box("|", "-")
15
16
  setpos(0, 0)
16
- addstr('[ Ruby Fail ]')
17
+ addstr(@title)
17
18
  super
18
19
  end
19
20
  end
@@ -1,6 +1,6 @@
1
1
  require 'optparse'
2
2
  require 'ostruct'
3
- module Options
3
+ module TtySlides::Options
4
4
  def self.parse!
5
5
  options = OpenStruct.new host: "localhost", port: 3000,
6
6
  start_at: 0
@@ -1,6 +1,6 @@
1
1
  require 'socket'
2
2
 
3
- class QandAClient
3
+ class TtySlides::QandAClient
4
4
  def initialize q_and_a_window, host="localhost", port=3000
5
5
  @q_and_a_window = q_and_a_window
6
6
  @host = host || "localhost"
@@ -1,6 +1,6 @@
1
1
  require 'delegate'
2
2
 
3
- class QandAWindow < SimpleDelegator
3
+ class TtySlides::QandAWindow < SimpleDelegator
4
4
  def initialize window
5
5
  super
6
6
  refresh
@@ -1,4 +1,4 @@
1
- module TtySlides
1
+ class TtySlides
2
2
  require 'curses'
3
3
  require 'io/console'
4
4
 
@@ -11,28 +11,22 @@ module TtySlides
11
11
  require 'slide_list'
12
12
  require 'options'
13
13
 
14
- @options = Options.parse!
15
-
16
14
  Curses.init_screen
17
15
  Curses.noecho
18
16
  Curses.curs_set(0) # no cursor please
19
17
 
20
- @height = Curses.lines
21
- @width = Curses.cols
22
- @main_window = MainWindow.new(Curses::Window.new @height - 5, @width, 0, 0)
23
- @q_and_a = QandAWindow.new(Curses::Window.new 5, @width, @main_window.maxy, 0)
24
- @slides = SlideList.new(@options.start_at)
25
-
26
- @q_a_client = QandAClient.new(@q_and_a, @options.host, @options.port)
27
- if !@q_a_client.connected?
28
- @main_window.resize @height, @width
29
- Curses.refresh
18
+ def initialize title=''
19
+ @title = title
20
+ @options = Options.parse!
21
+ @height = Curses.lines
22
+ @width = Curses.cols
23
+ @slides = SlideList.new(@options.start_at)
24
+ setup_windows
25
+ exit_handlers
26
+ setup_q_and_a
30
27
  end
31
28
 
32
- at_exit { puts "Last Slide: #{@slides.current}" if $!.kind_of?(StandardError) }
33
- at_exit { Curses.close_screen }
34
-
35
- def self.start
29
+ def start
36
30
  CML.new(@main_window, File.read(@slides.next)).render
37
31
 
38
32
  loop do
@@ -47,4 +41,28 @@ module TtySlides
47
41
  end
48
42
  end
49
43
 
44
+ private
45
+
46
+ def setup_windows
47
+ main_win = Curses::Window.new(@height - 5, @width, 0, 0)
48
+ @main_window = MainWindow.new(main_win, @title)
49
+ q_and_a_win = Curses::Window.new(5, @width, @main_window.maxy, 0)
50
+ @q_and_a = QandAWindow.new(q_and_a_win)
51
+ end
52
+
53
+ def setup_q_and_a
54
+ @q_a_client = QandAClient.new(@q_and_a, @options.host, @options.port)
55
+ if !@q_a_client.connected?
56
+ @main_window.resize @height, @width
57
+ Curses.refresh
58
+ end
59
+ end
60
+
61
+ def exit_handlers
62
+ at_exit do
63
+ puts "Last Slide: #{@slides.current}" if $!.kind_of?(StandardError)
64
+ end
65
+ at_exit { Curses.close_screen }
66
+ end
67
+
50
68
  end
@@ -1,3 +1,3 @@
1
- module TtySlides
2
- VERSION = "0.0.2"
1
+ class TtySlides
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty_slides
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: