imdb-terminal 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/imdb +70 -21
  3. metadata +18 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5900c22d081fb8cc49e3b657f2380246d4984245698fe7f997ce725a5d94a363
4
- data.tar.gz: 7fa4905d7d01d3753d53639db6b6f432a4424c5e5224fffd4065c47d7647af52
3
+ metadata.gz: 318c36f7732c8e2ff3831c96d3e15cef170d9ca6528a49ed65f6de7ff9411f88
4
+ data.tar.gz: 685167952efd3b9b8b90d79ac7a285347217e2ed246ed9c29f09e93172c25316
5
5
  SHA512:
6
- metadata.gz: 8545ab5fc7c8655ad3e9541517899e4ce761cb15d7ce4ceb24e6949048b160af96fe2b7e211b39896897aed54fa3b75871a295da9d903e120467b91eb1df8cba
7
- data.tar.gz: 359a3cfd14dd7d03f93ef40da0b5e3d0addabeee12cee86f8354e5d791ef52589424b9d91522c5b0a6146415843564575ddac55a55f2cd682915e37415084912
6
+ metadata.gz: 0b9bc63aaa63bb5f979b9ab3e8b956ae937bba83de7fca1be15e43b75c695f42fcf7e52ad0cc869151ed6bde6475959cd4ada1424f726286cb02bc19f96349b8
7
+ data.tar.gz: fadebca0abc0f276141a90a2b0eb1f11232f76e7774b530ce249379a35a7c539deff79a9938cded9f8fe109f89bc24f9429807a8ae721f84ad5f9d02dc2a847f
data/bin/imdb CHANGED
@@ -117,40 +117,87 @@ end
117
117
 
118
118
  # CLASSES
119
119
  class Curses::Window # CLASS EXTENSION
120
- attr_accessor :fg, :bg, :attr, :text, :index, :list, :update
121
120
  # General extensions (see https://github.com/isene/Ruby-Curses-Class-Extension)
122
- def clr
121
+ # This is a class extension to Ruby Curses - a class in dire need of such.
122
+ # self.pair keeps a registry of colors as they are encountered - defined with:
123
+ # init_pair(index, foreground, background)
124
+ # self.fg is set for the foreground color
125
+ # self.bg is set for the background color
126
+ # self.attr is set for text attributes like Curses::A_BOLD
127
+ # self.update can be used to indicate if a window should be updated (true/false)
128
+ # self.index can be used to keep track of the current list item in a window
129
+ attr_accessor :fg, :bg, :attr, :text, :update, :index, :list
130
+ def self.pair(fg, bg)
131
+ @p = [[]] if @p == nil
132
+ fg = fg.to_i; bg = bg.to_i
133
+ if @p.include?([fg,bg])
134
+ @p.index([fg,bg])
135
+ else
136
+ @p.push([fg,bg])
137
+ cp = @p.index([fg,bg])
138
+ init_pair(cp, fg, bg)
139
+ @p.index([fg,bg])
140
+ end
141
+ end
142
+ def clr # Clears the whole window
123
143
  self.setpos(0, 0)
124
144
  self.maxy.times {self.deleteln()}
125
145
  self.refresh
126
146
  self.setpos(0, 0)
127
147
  end
128
- def fill # Fill window with color as set by :bg
148
+ def fill # Fill window with color as set by self.color (or self.bg if not set)
149
+ self.setpos(0, 0)
150
+ self.fill_from_cur_pos
151
+ end
152
+ def fill_to_cur_pos # Fills the window up to current line
153
+ x = self.curx
154
+ y = self.cury
129
155
  self.setpos(0, 0)
130
156
  self.bg = 0 if self.bg == nil
131
157
  self.fg = 255 if self.fg == nil
132
- xor = self.fg ^ self.bg
133
- init_pair(xor, self.fg, self.bg)
134
158
  blank = " " * self.maxx
135
- self.maxy.times {self.attron(color_pair(xor)) {self << blank}}
159
+ cp = Curses::Window.pair(self.fg, self.bg)
160
+ y.times {self.attron(color_pair(cp)) {self << blank}}
136
161
  self.refresh
137
- self.setpos(0, 0)
162
+ self.setpos(y, x)
138
163
  end
139
- def write # Write context of :text to window with attributes :attr
140
- self.bg = 0 if self.bg == nil
141
- self.fg = 255 if self.fg == nil
142
- xor = self.fg ^ self.bg
143
- init_pair(xor, self.fg, self.bg)
164
+ def fill_from_cur_pos # Fills the rest of the window from current line
165
+ x = self.curx
166
+ y = self.cury
167
+ self.setpos(y, 0)
168
+ self.bg = 0 if self.bg == nil
169
+ self.fg = 255 if self.fg == nil
170
+ blank = " " * self.maxx
171
+ cp = Curses::Window.pair(self.fg, self.bg)
172
+ self.maxy.times {self.attron(color_pair(cp)) {self << blank}}
173
+ self.refresh
174
+ self.setpos(y, x)
175
+ end
176
+ def write
144
177
  self.attr = 0 if self.attr == nil
145
- self.attron(color_pair(xor) | self.attr) { self << self.text }
178
+ self.bg = 0 if self.bg == nil
179
+ self.fg = 255 if self.fg == nil
180
+ cp = Curses::Window.pair(self.fg, self.bg)
181
+ self.attron(color_pair(cp) | self.attr) { self << self.text }
146
182
  self.refresh
147
- self.text = ""
148
183
  end
149
- def p(fg, bg, attr, text)
150
- init_pair(fg ^ bg, fg, bg)
151
- self.attron(color_pair(fg ^ bg) | attr) { self << text }
184
+ def p(text) # Puts text to window
185
+ self.attr = 0 if self.attr == nil
186
+ self.bg = 0 if self.bg == nil
187
+ self.fg = 255 if self.fg == nil
188
+ cp = Curses::Window.pair(self.fg, self.bg)
189
+ self.attron(color_pair(cp) | attr) { self << text }
190
+ self.refresh
191
+ end
192
+ def pa(fg = self.fg, bg = self.bg, attr = self.attr, text) # Puts text to window with full set of attributes
193
+ cp = Curses::Window.pair(fg, bg)
194
+ self.attron(color_pair(cp) | attr) { self << text }
152
195
  self.refresh
153
196
  end
197
+ def format_text(text) # Format text so that it linebreaks neatly inside window
198
+ return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
199
+ end
200
+ alias :puts :p
154
201
  end
155
202
 
156
203
  # GENERIC FUNCTIONS
@@ -504,8 +551,10 @@ end
504
551
 
505
552
  # BASIC WINDOW FUNCTIONS
506
553
  def w_t # SHOW INFO IN @w_t
554
+ @w_t.clr
507
555
  @movies ? @w_t.text = " MOVIES :: " : @w_t.text = " SERIES :: "
508
556
  @w_t.text += "Rating MIN: #{@rating} - Year MIN: #{@yearMin} - Year MAX: #{@yearMax} :: Selection = #{@imdbsel.size}"
557
+ @w_t.text += " " * (@w_t.maxx - @w_t.text.length) if @w_t.text.length < @w_t.maxx
509
558
  @w_t.write
510
559
  end
511
560
  def w_list(win) # LIST IN WINDOW
@@ -716,10 +765,11 @@ end
716
765
  loop do # OUTER LOOP - (catching refreshes via 'r')
717
766
  @break = false # Initialize @break variable (set if user hits 'r')
718
767
  begin # Create the windows/panels
719
- Curses.stdscr.bg = 234 # Use for borders
720
- Curses.stdscr.fill
721
768
  maxx = Curses.cols
722
769
  maxy = Curses.lines
770
+ init_pair(255, 0, 234)
771
+ maxy.times {Curses.stdscr.attron(color_pair(255)) {Curses.stdscr << " " * maxx}}
772
+ Curses.stdscr.refresh
723
773
  # Curses::Window.new( h, w, y, x )
724
774
  @w_t = Curses::Window.new( 1, maxx, 0, 0 )
725
775
  @w_i = Curses::Window.new( maxy-2, 40, 1, 0 )
@@ -737,7 +787,6 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
737
787
  @w_p.fg, @w_p.bg = Wpfg, WIbg
738
788
  @w_b.fg, @w_b.bg = Wbfg, Wbbg
739
789
  [@w_i, @w_g, @w_m, @w_n].each{|w| w.index = 0}
740
- @w_b.fill
741
790
  @w_g.list = @genres
742
791
  @w_b.update = true
743
792
  @w_d.update = true
@@ -754,7 +803,7 @@ loop do # OUTER LOOP - (catching refreshes via 'r')
754
803
  @search == '' ? @w_t.bg = WtSbg : @w_t.bg = WtSbgS
755
804
  @w_t.attr = Curses::A_BOLD
756
805
  end
757
- @w_t.fill; @w_i.fill; @w_g.fill; @w_m.fill; @w_n.fill; @w_p.fill
806
+ @w_i.fill; @w_g.fill; @w_m.fill; @w_n.fill; @w_p.fill
758
807
  w_t; w_list(@w_i); w_list(@w_g); w_list(@w_m); w_list(@w_n)
759
808
  if @w_d.update
760
809
  @w_d.fill
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imdb-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-02 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -30,11 +30,26 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.3.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: rest-client
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
33
47
  description: 'Narrow down your preferences from a 1000 movies and almost 500 series.
34
48
  Select a minimum IMDB rating, range of production years, genres you like and dislike
35
49
  to get your preferred list. Get detailed information on movies and series and where
36
50
  you can stream them. Even the movie poster in the terminal. New in 0.2: Added ''v''
37
- to show version and RubyGem version. Code cleanup. 0.3: Major bug fix on listing'
51
+ to show version and RubyGem version. Code cleanup. 0.4: Adopted new curses extension
52
+ upgrade. Added gem dependency for rest-client'
38
53
  email: g@isene.com
39
54
  executables:
40
55
  - imdb