Module: RubyCurses::ViEditable

Includes:
ListEditable
Defined in:
lib/rbcurse/core/include/vieditable.rb

Overview

Since:

  • 1.2.0 UNTESTED

Instance Method Summary collapse

Methods included from ListEditable

#add_to_kill_ring, #append_next_kill, #append_row, #delete_at, #delete_curr_char, #delete_eol, #delete_forward, #delete_line, #delete_prev_char, #delete_word, #join_next_line, #kill_ring_save, #remove_all, #undo_handler, #yank, #yank_pop

Instance Method Details

#edit_charsObject

return str if ret == 0 return “”

Since:

  • 1.2.0 UNTESTED



165
166
167
# File 'lib/rbcurse/core/include/vieditable.rb', line 165

def edit_chars

end

#edit_line(lineno = @current_index) ⇒ Object

edit current or given line

Since:

  • 1.2.0 UNTESTED



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rbcurse/core/include/vieditable.rb', line 105

def edit_line lineno=@current_index
  line = self[lineno]
  prompt = "Edit: "
  maxlen = 80
  config={}; 
  oldline = line.dup
  config[:default] = line
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
  $log.debug " rbgetstr returned #{ret} , #{str} "
  return if ret != 0
  self[lineno].replace(str)
  fire_handler :CHANGE, InputDataEvent.new(0,oldline.length, self, :DELETE_LINE, lineno, oldline)     #  2008-12-24 18:34 
  fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
  @repaint_required = true
  @widget_scrolled = true
end

#edit_string(string, prompt = "Edit: ", maxlen = 80) ⇒ 0, -1

common method to edit given string

Parameters:

  • string (String)

    to edit/modify

  • prompt (String) (defaults to: "Edit: ")

    to display before string

  • max (int)

    length of input

Returns:

  • (0, -1)

    return value 0 if okay, -1 if error

Since:

  • 1.2.0 UNTESTED



147
148
149
150
151
152
153
# File 'lib/rbcurse/core/include/vieditable.rb', line 147

def edit_string string, prompt="Edit: ", maxlen=80
  config={}; 
  config[:default] = string
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
  #return str if ret == 0
  #return ""
end

#edit_wordObject

Since:

  • 1.2.0 UNTESTED



168
169
170
# File 'lib/rbcurse/core/include/vieditable.rb', line 168

def edit_word

end

#input_string(prompt = "Insert: ", maxlen = 80) ⇒ 0, -1

common method to input a blank string

Parameters:

  • prompt (String) (defaults to: "Insert: ")

    to display before string

  • max (int)

    length of input

Returns:

  • (0, -1)

    return value 0 if okay, -1 if error

Since:

  • 1.2.0 UNTESTED



159
160
161
162
163
164
# File 'lib/rbcurse/core/include/vieditable.rb', line 159

def input_string prompt="Insert: ", maxlen=80
  #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
  ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
  #return str if ret == 0
  #return ""
end

#insert_line(lineno = @current_index) ⇒ Object

insert a line FIXME needs to fire handler 2010-05-23 11:40

Since:

  • 1.2.0 UNTESTED



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rbcurse/core/include/vieditable.rb', line 124

def insert_line lineno=@current_index
  prompt = "Insert: "
  maxlen = 80
  #config={}; 
  #config[:default] = line
  #ret, str = rbgetstr(@form.window, $error_message_row, $error_message_col,  prompt, maxlen, config)
  ret, str = input_string prompt
  #ret, str = rbgetstr(@form.window, @row+@height-1, @col+1, prompt, maxlen, config)
  $log.debug " rbgetstr returned #{ret} , #{str} "
  return if ret != 0
  @list.insert lineno, str
  ## added handler on 2010-05-23 11:46 - undo works - tested in testlistbox.rb
  fire_handler :CHANGE, InputDataEvent.new(0,str.length, self, :INSERT_LINE, lineno, str)
  @widget_scrolled = true
  @repaint_required = true
end

#vieditable_initObject

Since:

  • 1.2.0 UNTESTED



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rbcurse/core/include/vieditable.rb', line 16

def vieditable_init
  $log.debug " inside vieditable_init "
  @editable = true
  bind_key( ?C, :edit_line)
  #bind_key( ?o, :insert_line)
  #bind_key( ?O) { insert_line(@current_index-1) } 
  bind_key( ?o) { insert_line(@current_index+1) } 
  bind_key( ?O) { insert_line(@current_index) } 
  bind_key( ?D, :delete_eol)
  bind_key( [?d, ?$], :delete_eol)
  bind_key( [?d, ?d] , :delete_line ) 
  bind_key( [?d, ?w], :delete_word )
  bind_key( [?d, ?t], :delete_till )
  bind_key( [?d, ?f], :delete_forward )
  bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
  bind_key( ?u ) { @undo_handler.undo if @undo_handler }
  bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
  bind_key( ?x, :delete_curr_char )
  bind_key( ?X, :delete_prev_char )
  bind_key( [?y, ?y] , :kill_ring_save ) 
  bind_key( ?p, :yank ) # paste after this line
  bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
  bind_key(?w, :forward_word)
  bind_key(?f, :forward_char)
  bind_key(?\M-y, :yank_pop)
  bind_key(?\M-w, :kill_ring_save)
  @_events.push :CHANGE # thru vieditable

end

#vieditable_init_listboxObject

Separate mappings for listboxes. Some methods don;‘t make sense for listboxes and are crashing since not present for them. f was being overwritten, too. Sorry for duplication, need to clean this somehow.

Since:

  • 1.2.0 UNTESTED



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rbcurse/core/include/vieditable.rb', line 50

def vieditable_init_listbox
  $log.debug " inside vieditable_init_listbox "
  @editable = true
  bind_key( ?C, :edit_line)
  bind_key( ?o) { insert_line(@current_index+1) } 
  bind_key( ?O) { insert_line(@current_index) } 
  bind_key( [?d, ?d] , :delete_line ) 
  bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
  bind_key( ?u ) { @undo_handler.undo if @undo_handler }
  bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
  bind_key( [?y, ?y] , :kill_ring_save ) 
  bind_key( ?p, :yank ) # paste after this line
  #bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
  # seems -1 was pasting 2 lines before
  bind_key( ?P ) { yank(@current_index - 0) } # should be before this line
  bind_key(?w, :forward_word)
  bind_key(?\M-y, :yank_pop)
  bind_key(?\C-y, :yank)
  bind_key(?\M-w, :kill_ring_save)
  @_events.push :CHANGE # thru vieditable
  #bind_key( ?D, :delete_eol)
  #bind_key( [?d, ?$], :delete_eol)
  #bind_key(?f, :forward_char)
  #bind_key( ?x, :delete_curr_char )
  #bind_key( ?X, :delete_prev_char )
  #bind_key( [?d, ?w], :delete_word )
  #bind_key( [?d, ?t], :delete_till )
  #bind_key( [?d, ?f], :delete_forward )

end

#vieditable_init_tabularObject

currently only adding delete_line and some yank pop functions These will all give wrong results in table due to _header_offset

Since:

  • 1.2.0 UNTESTED



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rbcurse/core/include/vieditable.rb', line 83

def vieditable_init_tabular
  $log.debug " inside vieditable_init tabular"
  @editable = true
  #bind_key( ?C, :edit_line)
  #bind_key( ?o, :insert_line)
  #bind_key( ?O) { insert_line(@current_index-1) } 
  #bind_key( ?o) { insert_line(@current_index+1) } 
  #bind_key( ?O) { insert_line(@current_index) } 
  bind_key( [?d, ?d] , :delete_line ) 
  #bind_key( ?\C-_ ) { @undo_handler.undo if @undo_handler }
  #bind_key( ?u ) { @undo_handler.undo if @undo_handler }
  #bind_key( ?\C-r ) { @undo_handler.redo if @undo_handler }
  bind_key( [?y, ?y] , :kill_ring_save ) 
  bind_key( ?p, :yank ) # paste after this line
  bind_key( ?P ) { yank(@current_index - 1) } # should be before this line
  bind_key(?\M-y, :yank_pop)
  bind_key(?\M-w, :kill_ring_save)
  @_events.push :CHANGE # thru vieditable
end