rbcurse-core 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ **2013-03-25**
2
+ ## 0.0.12 rbcurse-core
3
+ * Minor tweaks and fixes to statusline (tested in ribhu gem)
4
+
1
5
  **2013-03-22**
2
6
  ## 0.0.11 rbcurse-core
3
7
  * Added textpad (tested in cygnus gem)
data/NOTES CHANGED
@@ -1,7 +1,7 @@
1
1
  NOTES
2
2
  =====
3
3
  /// vim:ts=4:sw=4:tw=80:ai:formatoptions=tcqnl:
4
- /// this was posted with appenddiary.sh
4
+ /// this was posted with appenddiary.sh (notes)
5
5
 
6
6
  Subject: Update rubyforge
7
7
  -------------------------
@@ -2149,3 +2149,22 @@ you use a field in a messagebox which is created over and over again, then we
2149
2149
  manually have to keep the history and pass it to the field when creating the messagebox.
2150
2150
 
2151
2151
  * * * * * * * *
2152
+
2153
+ Subject: pad version of widgets
2154
+ -------------------------------
2155
+ Date: 2013-03-26 11:56
2156
+
2157
+ We have textpad functioning as a replacement of textview. Should we
2158
+ replace the code inside textview with pad, this involves a lot of
2159
+ testing and not knowing what can break. What user apps can break?
2160
+
2161
+ Or create parallel widgets. I have used textpad in cygnus for lists,
2162
+ popups and textviews. Now I need to use it for tree and tabularwidget.
2163
+
2164
+ If i keep parallel widgets then there's a naming issue. Should i use
2165
+ another module name Pad so i have Pad::tree etc or a different name ?
2166
+
2167
+ I would go with another module name but same widget name so it is clear
2168
+ that it is the same widget.
2169
+
2170
+ * * * * * * * *
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -96,11 +96,11 @@ module RubyCurses
96
96
  else
97
97
  t = Time.now
98
98
  tt = t.strftime "%F %H:%M:%S"
99
- r = Ncurses.LINES
99
+ #r = Ncurses.LINES
100
100
  # somehow the bg defined here affects the bg in left text, if left does not define
101
101
  # a bg. The bgcolor defined of statusline is ignored in left or overriden by this
102
- ftext = "#[fg=green,bg=blue] %-20s#[/end]" % [tt] # print a default
103
- @form.window.printstring_formatted_right @row, nil, ftext, $datacolor, Ncurses::A_REVERSE
102
+ #ftext = "#[fg=white,bg=blue] %-20s#[/end]" % [tt] # print a default
103
+ @form.window.printstring_formatted_right @row, nil, tt, @color_pair, Ncurses::A_REVERSE
104
104
  end
105
105
 
106
106
  @repaint_required = false
@@ -760,6 +760,7 @@ module RubyCurses
760
760
  w = @cw[i]
761
761
  l = e.to_s.length
762
762
  fmt = "%-#{w}s "
763
+ # if value is longer than width, then truncate it
763
764
  if l > w
764
765
  fmt = "%.#{w}s "
765
766
  else
@@ -8,22 +8,19 @@
8
8
  # Author: rkumar http://github.com/rkumar/mancurses/
9
9
  # Date: 2011-11-09 - 16:59
10
10
  # License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt)
11
- # Last update: 2013-03-25 01:52
11
+ # Last update: 2013-03-29 18:59
12
12
  #
13
13
  # == CHANGES
14
14
  # == TODO
15
- # _ in popup case allowing scrolling when it should not so you get an extra char at end
16
- # _ The list one needs a f-char like functionality.
17
- # x handle putting data again and overwriting existing
18
- # When reputting data, the underlying pad needs to be properly cleared
19
- # esp last row and last col
15
+ # Take care of 3 cases:
16
+ # 1. complete data change, then recreate pad, and call init_vars resetting row, col and curpos etc
17
+ # This is done by method text().
18
+ # 2. row added or minor change - recreate pad, repaint data but don't call initvars. must maintain cursor
19
+ # ignore recreate of pad if width or ht is less than w and h of container.
20
+ # 3. only rewrite a row - row data changed, no recreate pad or anything else
21
+ #
20
22
  #
21
- # x add mappings and process key in handle_keys and other widget things
22
- # - can pad movement and other ops be abstracted into module for reuse
23
- # / get scrolling like in vim (C-f e y b d)
24
23
  #
25
- # == TODO 2013-03-07 - 20:34
26
- # _ key bindings not showing up -- bind properly
27
24
  # ----------------------------------------------------------------------------- #
28
25
  #
29
26
  require 'rbcurse'
@@ -35,10 +32,14 @@ module RubyCurses
35
32
  class TextPad < Widget
36
33
  include BorderTitle
37
34
 
38
- dsl_accessor :suppress_border
35
+ dsl_accessor :suppress_borders
39
36
  dsl_accessor :print_footer
40
37
  attr_reader :current_index
41
38
  attr_reader :rows , :cols
39
+ # adding these only for debugging table, to see where cursor is.
40
+ attr_reader :lastrow, :lastcol
41
+ # for external methods or classes to advance cursor
42
+ #attr_accessor :curpos
42
43
  # You may pass height, width, row and col for creating a window otherwise a fullscreen window
43
44
  # will be created. If you pass a window from caller then that window will be used.
44
45
  # Some keys are trapped, jkhl space, pgup, pgdown, end, home, t b
@@ -53,6 +54,7 @@ module RubyCurses
53
54
  @prow = @pcol = 0
54
55
  @startrow = 0
55
56
  @startcol = 0
57
+ # @list is unused, think it can be removed
56
58
  @list = []
57
59
  super
58
60
 
@@ -68,27 +70,27 @@ module RubyCurses
68
70
  # NOTE XXX if cols is > COLS then padrefresh can fail
69
71
  @startrow = @row
70
72
  @startcol = @col
71
- #@suppress_border = config[:suppress_border]
72
- @row_offset = @col_offset = 1
73
- unless @suppress_border
73
+ unless @suppress_borders
74
+ @row_offset = @col_offset = 1
74
75
  @startrow += 1
75
76
  @startcol += 1
76
77
  @rows -=3 # 3 is since print_border_only reduces one from width, to check whether this is correct
77
78
  @cols -=3
79
+ @scrollatrows = @height - 3
78
80
  else
79
- # seeing why nothing is printing
80
- @rows -=0 # 3 is since print_border_only reduces one from width, to check whether this is correct
81
+ # no borders printed
82
+ @rows -= 1 # 3 is since print_border_only reduces one from width, to check whether this is correct
81
83
  ## if next is 0 then padrefresh doesn't print
82
84
  @cols -=1
85
+ @scrollatrows = @height - 1 # check this out 0 or 1
86
+ @row_offset = @col_offset = 0
83
87
  end
84
- @row_offset = @col_offset = 0 if @suppress_borders
85
88
  @top = @row
86
89
  @left = @col
87
- @lastrow = @row + 1
88
- @lastcol = @col + 1
90
+ @lastrow = @row + @row_offset
91
+ @lastcol = @col + @col_offset
89
92
  @_events << :PRESS
90
93
  @_events << :ENTER_ROW
91
- @scrollatrows = @height - 3
92
94
  init_vars
93
95
  end
94
96
  def init_vars
@@ -97,10 +99,11 @@ module RubyCurses
97
99
  # column cursor
98
100
  @prow = @pcol = @curpos = 0
99
101
  if @row && @col
100
- @lastrow = @row + 1
101
- @lastcol = @col + 1
102
+ @lastrow = @row + @row_offset
103
+ @lastcol = @col + @col_offset
102
104
  end
103
105
  @repaint_required = true
106
+ map_keys unless @mapped_keys
104
107
  end
105
108
  def rowcol #:nodoc:
106
109
  return @row+@row_offset, @col+@col_offset
@@ -118,19 +121,14 @@ module RubyCurses
118
121
  # create and populate pad
119
122
  def populate_pad
120
123
  @_populate_needed = false
121
- # how can we make this more sensible ? FIXME
122
- #@renderer ||= DefaultFileRenderer.new #if ".rb" == @filetype
123
124
  @content_rows = @content.count
124
125
  @content_cols = content_cols()
125
- # this should be explicit and not "intelligent"
126
- #@title += " [ #{@content_rows},#{@content_cols}] " if @cols > 50
127
126
  @content_rows = @rows if @content_rows < @rows
128
127
  @content_cols = @cols if @content_cols < @cols
129
- #$log.debug "XXXX content_cols = #{@content_cols}"
130
128
 
131
129
  create_pad
132
130
 
133
- # clearstring is the string required to clear the pad to backgroud color
131
+ # clearstring is the string required to clear the pad to background color
134
132
  @clearstring = nil
135
133
  cp = get_color($datacolor, @color, @bgcolor)
136
134
  @cp = FFI::NCurses.COLOR_PAIR(cp)
@@ -139,11 +137,18 @@ module RubyCurses
139
137
  end
140
138
 
141
139
  Ncurses::Panel.update_panels
140
+ render_all
141
+
142
+ end
143
+ #
144
+ # iterate through content rendering each row
145
+ # 2013-03-27 - 01:51 separated so that widgets with headers such as tables can
146
+ # override this for better control
147
+ def render_all
142
148
  @content.each_index { |ix|
143
149
  #FFI::NCurses.mvwaddstr(@pad,ix, 0, @content[ix])
144
150
  render @pad, ix, @content[ix]
145
151
  }
146
-
147
152
  end
148
153
 
149
154
  public
@@ -226,6 +231,8 @@ module RubyCurses
226
231
  self
227
232
  end
228
233
  alias :list :text
234
+ # for compat with textview
235
+ alias :set_content :text
229
236
  def content
230
237
  raise "content is nil " unless @content
231
238
  return @content
@@ -285,6 +292,7 @@ module RubyCurses
285
292
 
286
293
  #
287
294
  # pass in formatted text along with parser (:tmux or :ansi)
295
+ # NOTE this does not call init_vars, i think it should, text() does
288
296
  def formatted_text text, fmt
289
297
 
290
298
  require 'rbcurse/core/include/chunk'
@@ -327,16 +335,34 @@ module RubyCurses
327
335
  end
328
336
 
329
337
  public
338
+ # to be called with program / user has added a row or changed column widths so that
339
+ # the pad needs to be recreated. However, cursor positioning is maintained since this
340
+ # is considered to be a minor change.
341
+ # We do not call init_vars since user is continuing to do some work on a row/col.
342
+ def fire_dimension_changed
343
+ # recreate pad since width or ht has changed (row count or col width changed)
344
+ @_populate_needed = true
345
+ @repaint_required = true
346
+ @repaint_all = true
347
+ end
348
+ # repaint only one row since content of that row has changed.
349
+ # No recreate of pad is done.
350
+ def fire_row_changed ix
351
+ render @pad, ix, @content[ix]
352
+ # may need to call padrefresh TODO TESTING
353
+ end
330
354
  def repaint
331
355
  ## 2013-03-08 - 21:01 This is the fix to the issue of form callign an event like ? or F1
332
356
  # which throws up a messagebox which leaves a black rect. We have no place to put a refresh
333
357
  # However, form does call repaint for all objects, so we can do a padref here. Otherwise,
334
358
  # it would get rejected. UNfortunately this may happen more often we want, but we never know
335
359
  # when something pops up on the screen.
336
- padrefresh unless @repaint_required
337
- return unless @repaint_required
360
+ unless @repaint_required
361
+ padrefresh
362
+ return
363
+ end
338
364
  if @formatted_text
339
- $log.debug "XXX: INSIDE FORMATTED TEXT "
365
+ #$log.debug "XXX: INSIDE FORMATTED TEXT "
340
366
 
341
367
  l = RubyCurses::Utils.parse_formatted_text(@color_parser,
342
368
  @formatted_text)
@@ -349,7 +375,7 @@ module RubyCurses
349
375
  @window ||= @graphic
350
376
  populate_pad if @_populate_needed
351
377
  #HERE we need to populate once so user can pass a renderer
352
- unless @suppress_border
378
+ unless @suppress_borders
353
379
  if @repaint_all
354
380
  ## XXX im not getting the background color.
355
381
  #@window.print_border_only @top, @left, @height-1, @width, $datacolor
@@ -464,7 +490,11 @@ module RubyCurses
464
490
  def down num=(($multiplier.nil? or $multiplier == 0) ? 1 : $multiplier)
465
491
  #@oldindex = @current_index if num > 10
466
492
  @current_index += num
467
- ensure_visible
493
+ # no , i don't like this here. it scrolls up too much making prow = current_index
494
+ unless is_visible? @current_index
495
+ @prow += num
496
+ end
497
+ #ensure_visible
468
498
  $multiplier = 0
469
499
  end
470
500
 
@@ -555,7 +585,6 @@ module RubyCurses
555
585
  #
556
586
  def handle_key ch
557
587
  return :UNHANDLED unless @content
558
- map_keys unless @mapped_keys
559
588
 
560
589
 
561
590
  @oldrow = @prow
@@ -681,7 +710,11 @@ module RubyCurses
681
710
  @crow = @current_index + r - @prow
682
711
  @crow = r if @crow < r
683
712
  # 2 depends on whetehr suppressborders
684
- @crow = @row + @height -2 if @crow >= r + @height -2
713
+ if @suppress_borders
714
+ @crow = @row + @height -1 if @crow >= r + @height -1
715
+ else
716
+ @crow = @row + @height -2 if @crow >= r + @height -2
717
+ end
685
718
  setrowcol @crow, @curpos+c
686
719
  lastcurpos @crow, @curpos+c
687
720
  if @oldindex != @current_index
@@ -728,8 +761,13 @@ module RubyCurses
728
761
  # This uses the dialog, but what if user wants the old style.
729
762
  # Isn't there a cleaner way to let user override style, or allow user
730
763
  # to use own UI for getting pattern and then passing here.
731
- def ask_search
732
- str = get_string("Enter pattern: ")
764
+ # @param str default nil. If not passed, then user is prompted using get_string dialog
765
+ # This allows caller to use own method to prompt for string such as 'get_line' or 'rbgetstr' /
766
+ # 'ask()'
767
+ def ask_search str=nil
768
+ # the following is a change that enables callers to prompt for the string
769
+ # using some other style, basically the classical style and send the string in
770
+ str = get_string("Enter pattern: ") unless str
733
771
  return if str.nil?
734
772
  str = @last_regex if str == ""
735
773
  return if str == ""
@@ -891,6 +929,10 @@ module RubyCurses
891
929
 
892
930
  # a test renderer to see how things go
893
931
  class DefaultFileRenderer
932
+ #
933
+ # @param pad for calling print methods on
934
+ # @param lineno the line number on the pad to print on
935
+ # @param text data to print
894
936
  def render pad, lineno, text
895
937
  bg = :black
896
938
  fg = :white
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rbcurse-core"
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rahul Kumar"]
12
- s.date = "2013-03-25"
12
+ s.date = "2013-03-29"
13
13
  s.description = "Ruby curses/ncurses widgets for easy application development on text terminals (ruby 1.9)"
14
14
  s.email = "sentinel1879@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbcurse-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-25 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-ncurses