vimamsa 0.1.11 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,6 +25,8 @@ class VSourceView < GtkSource::View
25
25
  @removed_controllers = []
26
26
  self.highlight_current_line = true
27
27
 
28
+ @tt = nil
29
+
28
30
  # self.drag_dest_add_image_targets #TODO:gtk4
29
31
  # self.drag_dest_add_uri_targets #TODO:gtk4
30
32
 
@@ -32,6 +34,7 @@ class VSourceView < GtkSource::View
32
34
  # puts "drag-data-received"
33
35
  # puts
34
36
  # if data.uris.size >= 1
37
+
35
38
  # imgpath = CGI.unescape(data.uris[0])
36
39
  # m = imgpath.match(/^file:\/\/(.*)/)
37
40
  # if m
@@ -42,9 +45,25 @@ class VSourceView < GtkSource::View
42
45
  # true
43
46
  # end
44
47
 
48
+ # Mainly after page-up or page-down
45
49
  signal_connect("move-cursor") do |widget, event|
46
- debug("MOVE-CURSOR",2)
47
- $update_cursor = true
50
+ if event.name == "GTK_MOVEMENT_PAGES" and (last_action == "page_up" or last_action == "page_down")
51
+ # Ripl.start :binding => binding
52
+
53
+ debug("MOVE-CURSOR", 2)
54
+ # $update_cursor = true
55
+ handle_scrolling()
56
+ end
57
+
58
+ # handle_scrolling()
59
+ # curpos = buffer.cursor_position
60
+ # debug "MOVE CURSOR (sig): #{curpos}"
61
+
62
+ # run_as_idle proc {
63
+ # curpos = buffer.cursor_position
64
+ # debug "MOVE CURSOR (sig2): #{curpos}"
65
+ # }
66
+
48
67
  false
49
68
  end
50
69
 
@@ -83,7 +102,7 @@ class VSourceView < GtkSource::View
83
102
  # if ctr.class == Gtk::EventControllerKey or ctr.class == Gtk::GestureClick
84
103
  if ctr != @click
85
104
  # to_remove << ctr if ctr.class != Gtk::GestureDrag
86
- to_remove << ctr
105
+ to_remove << ctr
87
106
  end
88
107
  }
89
108
  if to_remove.size > 0
@@ -98,43 +117,141 @@ class VSourceView < GtkSource::View
98
117
  end
99
118
 
100
119
  def register_signals()
120
+ check_controllers
101
121
 
102
- #TODO: Doesn't seem to catch "move-cursor" signal since upgrade to gtk4
103
- # self.signal_connect("move-cursor") do |widget, event|
104
- # $update_cursor = true
105
- # false
106
- # end
122
+ # Implement mouse selections using @cnt_mo and @cnt_drag
123
+ @cnt_mo = Gtk::EventControllerMotion.new
124
+ self.add_controller(@cnt_mo)
125
+ @cnt_mo.signal_connect "motion" do |gesture, x, y|
126
+ if !@range_start.nil? and !x.nil? and !y.nil? and buf.visual_mode?
127
+ i = coord_to_iter(x, y, true)
128
+ @bufo.set_pos(i) if !i.nil? and @last_iter != i
129
+ @last_iter = i
130
+ end
131
+ end
132
+
133
+ @last_coord = nil
134
+ @cnt_drag = Gtk::GestureDrag.new
135
+ self.add_controller(@cnt_drag)
136
+ @cnt_drag.signal_connect "drag-begin" do |gesture, x, y|
137
+ debug "drag-begin", 2
138
+ i = coord_to_iter(x, y, true)
139
+ pp i
140
+ @range_start = i
141
+ if !buf.visual_mode?
142
+ buf.start_visual_mode
143
+ end
144
+ end
145
+
146
+ @cnt_drag.signal_connect "drag-end" do |gesture, offsetx, offsety|
147
+ debug "drag-end", 2
148
+
149
+ # Not enough drag
150
+ if offsetx.abs < 5 and offsety.abs < 5
151
+ buf.end_visual_mode
152
+ end
153
+ @range_start = nil
154
+ end
107
155
 
108
- check_controllers
109
156
  click = Gtk::GestureClick.new
110
157
  click.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
111
158
  self.add_controller(click)
112
159
  # Detect mouse click
113
160
  @click = click
161
+
162
+ @range_start = nil
114
163
  click.signal_connect "pressed" do |gesture, n_press, x, y, z|
115
- debug "SourceView, GestureClick x=#{x} y=#{y}"
116
- pp visible_rect
117
- winw = width
118
- view_width = visible_rect.width
119
- gutter_width = winw - view_width
120
-
121
- i = get_iter_at_location((x - gutter_width).to_i, (y + visible_rect.y).to_i)
122
- if !i.nil?
123
- @bufo.set_pos(i.offset)
124
- else
125
- debug "iter nil 0000"
164
+ debug "SourceView, GestureClick released x=#{x} y=#{y}"
165
+
166
+ if buf.visual_mode?
167
+ buf.end_visual_mode
126
168
  end
169
+
170
+ xloc = (x - gutter_width).to_i
171
+ yloc = (y + visible_rect.y).to_i
172
+ debug "xloc=#{xloc} yloc=#{yloc}"
173
+
174
+ i = coord_to_iter(xloc, yloc)
175
+ # @range_start = i
176
+
177
+ # This needs to happen after xloc calculation, otherwise xloc gets a wrong value (around 200 bigger)
178
+ if vma.gui.current_view != self
179
+ vma.gui.set_current_view(self)
180
+ end
181
+
182
+ @bufo.set_pos(i) if !i.nil?
127
183
  true
128
184
  end
185
+
186
+ click.signal_connect "released" do |gesture, n_press, x, y, z|
187
+ debug "SourceView, GestureClick released x=#{x} y=#{y}"
188
+
189
+ xloc = (x - gutter_width).to_i
190
+ yloc = (y + visible_rect.y).to_i
191
+ debug "xloc=#{xloc} yloc=#{yloc}"
192
+
193
+ # This needs to happen after xloc calculation, otherwise xloc gets a wrong value (around 200 bigger)
194
+ if vma.gui.current_view != self
195
+ vma.gui.set_current_view(self)
196
+ end
197
+
198
+ i = coord_to_iter(xloc, yloc)
199
+
200
+ # if i != @range_start
201
+ # debug "RANGE #{[@range_start, i]}", 2
202
+ # end
203
+
204
+ @bufo.set_pos(i) if !i.nil?
205
+ # @range_start = nil
206
+ true
207
+ end
208
+ end
209
+
210
+ def coord_to_iter(xloc, yloc, transform_coord = false)
211
+ if transform_coord
212
+ xloc = (xloc - gutter_width).to_i
213
+ yloc = (yloc + visible_rect.y).to_i
214
+ end
215
+
216
+ # Try to get exact character position
217
+ i = get_iter_at_location(xloc, yloc)
218
+
219
+ # If doesn't work, at least get the start of correct line
220
+ # TODO: sometimes end of line is better choice
221
+ if i.nil?
222
+ r = get_line_at_y(yloc)
223
+ i = r[0] if !r.nil?
224
+ end
225
+
226
+ return i.offset if !i.nil?
227
+ return nil
228
+ end
229
+
230
+ def handle_scrolling()
231
+ delete_cursorchar
232
+ # curpos = buffer.cursor_position
233
+ # debug "MOVE CURSOR: #{curpos}"
234
+ return nil if vma.gui.nil?
235
+ return nil if @bufo.nil?
236
+ vma.gui.run_after_scrolling proc {
237
+ debug "START UPDATE POS AFTER SCROLLING", 2
238
+ delete_cursorchar
239
+ bc = window_to_buffer_coords(Gtk::TextWindowType::WIDGET, gutter_width + 2, 60)
240
+ if !bc.nil?
241
+ i = coord_to_iter(bc[0], bc[1])
242
+ if !i.nil?
243
+ @bufo.set_pos(i)
244
+ end
245
+ end
246
+ $update_cursor = false
247
+ }
129
248
  end
130
249
 
131
250
  # def handle_key_event(event, sig)
132
251
  def handle_key_event(keyval, keyname, sig)
252
+ delete_cursorchar
133
253
  if $update_cursor
134
- curpos = buffer.cursor_position
135
- debug "MOVE CURSOR: #{curpos}"
136
- buf.set_pos(curpos)
137
- $update_cursor = false
254
+ handle_scrolling
138
255
  end
139
256
  debug $view.visible_rect.inspect
140
257
 
@@ -226,17 +343,17 @@ class VSourceView < GtkSource::View
226
343
  # set_focus(5)
227
344
  # false
228
345
 
346
+ draw_cursor #TODO: only when needed
229
347
  end
230
348
 
231
349
  def pos_to_coord(i)
232
350
  b = buffer
233
351
  iter = b.get_iter_at(:offset => i)
234
352
  iterxy = get_iter_location(iter)
235
- # winw = parent_window.width #TODO:gtk4
236
353
  winw = width #TODO
237
354
 
238
355
  view_width = visible_rect.width
239
- gutter_width = winw - view_width
356
+ gutter_width = winw - view_width #TODO
240
357
 
241
358
  x = iterxy.x + gutter_width
242
359
  y = iterxy.y
@@ -249,6 +366,7 @@ class VSourceView < GtkSource::View
249
366
  end
250
367
 
251
368
  def handle_deltas()
369
+ delete_cursorchar
252
370
  any_change = false
253
371
  while d = @bufo.deltas.shift
254
372
  any_change = true
@@ -266,7 +384,7 @@ class VSourceView < GtkSource::View
266
384
  end
267
385
  end
268
386
  if any_change
269
- # gui_set_cursor_pos(@bufo.id, @bufo.pos) #TODO: only when necessary
387
+ #TODO: only when necessary
270
388
  self.set_cursor_pos(pos)
271
389
  end
272
390
 
@@ -289,13 +407,12 @@ class VSourceView < GtkSource::View
289
407
  end
290
408
 
291
409
  def set_cursor_pos(pos)
410
+ delete_cursorchar
292
411
  # return
293
412
  itr = buffer.get_iter_at(:offset => pos)
294
413
  itr2 = buffer.get_iter_at(:offset => pos + 1)
295
414
  buffer.place_cursor(itr)
296
415
 
297
- # $view.signal_emit("extend-selection", Gtk::MovementStep.new(:PAGES), -1, false)
298
-
299
416
  within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
300
417
  use_align = false
301
418
  xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
@@ -310,9 +427,6 @@ class VSourceView < GtkSource::View
310
427
  $idle_scroll_to_mark = true
311
428
  ensure_cursor_visible
312
429
 
313
- # scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
314
-
315
- # $view.signal_emit("extend-selection", Gtk::TextExtendSelection.new, itr,itr,itr2)
316
430
  draw_cursor
317
431
 
318
432
  return true
@@ -382,19 +496,56 @@ class VSourceView < GtkSource::View
382
496
  end
383
497
  end
384
498
 
499
+ # Delete the extra char added to buffer to represent the cursor
500
+ def delete_cursorchar
501
+ if !@cursorchar.nil?
502
+ itr = buffer.get_iter_at(:offset => @cursorchar)
503
+ itr2 = buffer.get_iter_at(:offset => @cursorchar + 1)
504
+ buffer.delete(itr, itr2)
505
+ @cursorchar = nil
506
+ end
507
+ end
508
+
385
509
  def draw_cursor
510
+ # if @tt.nil?
511
+ # @tt = buffer.create_tag("font_tag")
512
+ # @tt.font = "Arial"
513
+ # end
514
+
386
515
  mode = vma.kbd.get_mode
387
516
  ctype = vma.kbd.get_cursor_type
388
- # if is_command_mode
517
+ delete_cursorchar
518
+ vma.gui.remove_overlay_cursor
389
519
  if ctype == :command
390
- itr = buffer.get_iter_at(:offset => @bufo.pos)
391
- itr2 = buffer.get_iter_at(:offset => @bufo.pos + 1)
392
- buffer.select_range(itr, itr2)
520
+ if @bufo[@bufo.pos] == "\n"
521
+ # If we are at end of line, it's not possible to draw the cursor by making a selection. I tried to do this by drawing an overlay, but that generates issues. If moving the cursor causes the ScrolledWindow to be scrolled, these errors randomly appear and the whole view shows blank:
522
+ # (ruby:21016): Gtk-WARNING **: 19:52:23.181: Trying to snapshot GtkSourceView 0x55a97524c8c0 without a current allocation
523
+ # (ruby:21016): Gtk-WARNING **: 19:52:23.181: Trying to snapshot GtkGizmo 0x55a9727d2580 without a current allocation
524
+ # (ruby:21016): Gtk-WARNING **: 19:52:23.243: Trying to snapshot GtkSourceView 0x55a97524c8c0 without a current allocation
525
+ # vma.gui.overlay_draw_cursor(@bufo.pos)
526
+
527
+ # Current workaround is to add an empty space to the place where the cursor is and then remove this whenever we get any kind of event that might cause this class to be accessed.
528
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
529
+ buffer.insert(itr, " ") # normal space
530
+ # buffer.insert(itr, " ") # thin space (U+2009)
531
+ # buffer.insert(itr, "l")
532
+ @cursorchar = @bufo.pos
533
+
534
+ # Apparently we need to redo this after buffer.insert:
535
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
536
+ itr2 = buffer.get_iter_at(:offset => @bufo.pos + 1)
537
+ # buffer.apply_tag(@tt, itr, itr2)
538
+ buffer.select_range(itr, itr2)
539
+ else
540
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
541
+ itr2 = buffer.get_iter_at(:offset => @bufo.pos + 1)
542
+ buffer.select_range(itr, itr2)
543
+ end
393
544
  # elsif @bufo.visual_mode?
394
545
  elsif ctype == :visual
395
- debug "VISUAL MODE"
546
+ # debug "VISUAL MODE"
396
547
  (_start, _end) = @bufo.get_visual_mode_range2
397
- debug "#{_start}, #{_end}"
548
+ # debug "#{_start}, #{_end}"
398
549
  itr = buffer.get_iter_at(:offset => _start)
399
550
  itr2 = buffer.get_iter_at(:offset => _end + 1)
400
551
  # Pango-CRITICAL **: pango_layout_get_cursor_pos: assertion 'index >= 0 && index <= layout->length' failed
@@ -1,8 +1,10 @@
1
1
  def hpt_check_cur_word(w)
2
2
  debug "check_cur_word(w)"
3
- m = w.match(/⟦(.*)⟧/)
3
+ m = w.match(/⟦((audio|img):)(.*)⟧/)
4
4
  if m
5
- fpfx = m[1]
5
+ # Ripl.start :binding => binding
6
+
7
+ fpfx = m[3]
6
8
  if vma.buf.fname
7
9
  dn = File.dirname(vma.buf.fname)
8
10
 
@@ -23,8 +25,13 @@ def hpt_check_cur_word(w)
23
25
  end
24
26
 
25
27
  if fn
26
- message "HPT opening file #{fn}"
27
- return fn
28
+ if m[2] == "audio"
29
+ # Thread.new { Audio.play(fn) }
30
+ Audio.play(fn)
31
+ else
32
+ message "HPT opening file #{fn}"
33
+ return fn
34
+ end
28
35
  # open_existing_file(fn)
29
36
  # return true
30
37
  else
@@ -104,6 +104,10 @@ reg_act(:execute_current_line_in_terminal_autoclose, proc { buf.execute_current_
104
104
  reg_act(:show_images, proc { hpt_scan_images() }, "Show images inserted with ⟦img:file.png⟧ syntax")
105
105
  reg_act(:delete_current_file, proc { bufs.delete_current_buffer() }, "Delete current file")
106
106
 
107
+
108
+ reg_act(:audio_stop, proc { Audio.stop }, "Stop audio playback")
109
+
110
+
107
111
  act_list = {
108
112
  # File handling
109
113
  :buf_save => { :proc => proc { buf.save },
@@ -267,7 +267,12 @@ class KeyBindingTree
267
267
  for st in @state_trail
268
268
  st = st[0] if st.class == Array
269
269
  if first
270
- s_trail << "[#{st.to_s}]"
270
+ trailpfx = ""
271
+ if !st.major_modes.empty?
272
+ mmid = st.major_modes.first
273
+ trailpfx = "#{@modes[mmid].to_s}>"
274
+ end
275
+ s_trail << "[#{trailpfx}#{st.to_s}]"
271
276
  else
272
277
  s_trail << " #{st.to_s}"
273
278
  end
@@ -475,6 +480,7 @@ class KeyBindingTree
475
480
  end
476
481
 
477
482
  def handle_key_bindigs_action(action, c)
483
+ $acth << action
478
484
  $method_handles_repeat = false #TODO:??
479
485
  n = 1
480
486
  if $next_command_count and !(action.class == String and action.include?("set_next_command_count"))
@@ -531,7 +537,7 @@ def exec_action(action)
531
537
  $kbd.last_action = $kbd.cur_action
532
538
  $kbd.cur_action = action
533
539
  if action.class == Symbol
534
- return call(action)
540
+ return call_action(action)
535
541
  elsif action.class == Proc
536
542
  return action.call
537
543
  else
@@ -3,6 +3,8 @@ vma.kbd.add_mode("I", :insert, :insert)
3
3
  vma.kbd.add_mode("V", :visual, :visual)
4
4
  vma.kbd.add_mode("M", :minibuffer) #TODO: needed?
5
5
  vma.kbd.add_mode("R", :readchar)
6
+ # vma.kbd.add_mode("audio", :audio, :command)
7
+ vma.kbd.add_minor_mode("audio", :audio, :command)
6
8
  vma.kbd.add_mode("B", :browse, :command)
7
9
  vma.kbd.add_mode("X", :replace, :command, name: "Replace")
8
10
  vma.kbd.set_default_mode(:command)
@@ -49,6 +51,15 @@ bindkey "C , b", :start_buf_manager
49
51
  bindkey "C , w", :toggle_active_window
50
52
  bindkey "C , , w", :toggle_two_column
51
53
 
54
+ bindkey "C , u s", :audio_stop
55
+ bindkey "C m a", "vma.kbd.set_mode(:audio)"
56
+ bindkey "audio s", :audio_stop
57
+ bindkey "audio space", :audio_stop
58
+ bindkey "audio q || audio esc", "vma.kbd.set_mode_to_default"
59
+
60
+
61
+
62
+
52
63
  # bindkey "C , f o", :open_file_dialog
53
64
  bindkey "CI ctrl-o", :open_file_dialog
54
65
  # bindkey "M enter", :minibuffer_end
@@ -63,7 +74,7 @@ bindkey "C z ", :start_browse_mode
63
74
  bindkey "B h", :history_switch_backwards
64
75
  bindkey "B l", :history_switch_forwards
65
76
  #bindkey 'B z', :center_on_current_line
66
- bindkey "B z", "center_on_current_line();call(:exit_browse_mode)"
77
+ bindkey "B z", "center_on_current_line();call_action(:exit_browse_mode)"
67
78
  bindkey "B enter || B return || B esc || B j || B ctrl!", :exit_browse_mode
68
79
  bindkey "B s", :page_up
69
80
  bindkey "B d", :page_down
@@ -75,7 +86,7 @@ bindkey "B c", :close_current_buffer
75
86
  bindkey "B ;", "buf.jump_to_last_edit"
76
87
  bindkey "B q", :jump_to_last_edit
77
88
  bindkey "B w", :jump_to_next_edit
78
- bindkey "C , d", :diff_buffer
89
+ # bindkey "C , d", :diff_buffer
79
90
  bindkey "C , g", :invoke_grep_search
80
91
  #bindkey 'C , g', proc{invoke_grep_search}
81
92
  bindkey "C , v", :auto_indent_buffer
@@ -156,11 +167,13 @@ default_keys = {
156
167
 
157
168
  # Debug
158
169
  "C , d r p" => "start_ripl",
170
+ "C , d o" => "vma.gui.clear_overlay",
159
171
  "C , D" => "debug_print_buffer",
160
172
  "C , c s" => "bufs.close_scrap_buffers",
161
173
  "C , d b" => "debug_print_buffer",
162
174
  "C , d c" => "debug_dump_clipboard",
163
175
  "C , d d" => "debug_dump_deltas",
176
+
164
177
  "VC O" => "buf.jump(END_OF_LINE)",
165
178
  "VC $" => "buf.jump(END_OF_LINE)",
166
179
 
@@ -196,6 +209,7 @@ default_keys = {
196
209
  "C d $" => "buf.delete2(:to_line_end)",
197
210
  # 'C d e'=> 'buf.delete_to_next_word_end',
198
211
  "C d <num> e" => "delete_next_word",
212
+ "C d ' <char>" => "buf.delete2(:to_mark,<char>)",
199
213
  "C r <char>" => "buf.replace_with_char(<char>)", # TODO
200
214
  "C , l b" => "load_buffer_list",
201
215
  "C , l l" => "save_buffer_list",
data/lib/vimamsa/main.rb CHANGED
@@ -49,18 +49,11 @@ end
49
49
 
50
50
  require "vimamsa/editor.rb"
51
51
 
52
- # load "gui_funcs.rb"
53
-
54
52
  $vma = Editor.new
55
53
  def vma()
56
54
  return $vma
57
55
  end
58
56
 
59
- # c_startup
60
- # run_random_jump_test
61
- # main_loop
62
-
63
- # debug("END")
64
57
 
65
58
 
66
59
 
data/lib/vimamsa/rbvma.rb CHANGED
@@ -48,12 +48,6 @@ require "vimamsa/conf"
48
48
  # load "vendor/ver/lib/ver/syntax/detector.rb"
49
49
  # load "vendor/ver/config/detect.rb"
50
50
 
51
- $vma = Editor.new
52
-
53
- def vma()
54
- return $vma
55
- end
56
-
57
51
  def unimplemented
58
52
  debug "unimplemented"
59
53
  end
@@ -68,6 +68,24 @@ def gui_grep()
68
68
  gui_one_input_action("Grep", "Search:", "grep", callback)
69
69
  end
70
70
 
71
+ def highlight_match(bf, str, color: "#aa0000ff")
72
+ vbuf = bf.view.buffer
73
+ r = Regexp.new(Regexp.escape(str), Regexp::IGNORECASE)
74
+
75
+ hlparts = []
76
+
77
+ tt = vma.gui.view.buffer.create_tag("highlight_match_tag")
78
+ tt.weight = 650
79
+ tt.foreground = color
80
+
81
+ ind = scan_indexes(bf, r)
82
+ ind.each { |x|
83
+ itr = vbuf.get_iter_at(:offset => x)
84
+ itr2 = vbuf.get_iter_at(:offset => x + str.size)
85
+ vbuf.apply_tag(tt, itr, itr2)
86
+ }
87
+ end
88
+
71
89
  def grep_cur_buffer(search_str, b = nil)
72
90
  debug "grep_cur_buffer(search_str)"
73
91
  lines = vma.buf.split("\n")
@@ -76,18 +94,21 @@ def grep_cur_buffer(search_str, b = nil)
76
94
  fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
77
95
  res_str = ""
78
96
 
97
+ hlparts = []
79
98
  $grep_matches = []
80
99
  lines.each_with_index { |l, i|
81
100
  if r.match(l)
82
- # res_str << "#{fpath}#{i + 1}:#{l}\n"
83
- res_str << "#{i + 1}:#{l}\n"
101
+ res_str << "#{i + 1}:"
102
+ # ind = scan_indexes(l, r)
103
+ res_str << "#{l}\n"
84
104
  $grep_matches << i + 1 # Lines start from index 1
85
105
  end
86
106
  }
87
107
  $grep_bufid = vma.buffers.current_buf
88
- b = create_new_file(nil, res_str)
89
- # set_current_buffer(buffer_i, update_history = true)
90
- # @current_buf = buffer_i
108
+ b = create_new_buffer(res_str, "grep")
109
+ vbuf = vma.gui.view.buffer
110
+
111
+ highlight_match(b, search_str, color: "#10bd8e")
91
112
 
92
113
  b.line_action_handler = proc { |lineno|
93
114
  debug "GREP HANDLER:#{lineno}"
@@ -99,10 +120,6 @@ def grep_cur_buffer(search_str, b = nil)
99
120
  }
100
121
  end
101
122
 
102
- # def invoke_grep_search()
103
- # start_minibuffer_cmd("", "", :grep_cur_buffer)
104
- # end
105
-
106
123
  def gui_one_input_action(title, field_label, button_title, callback, opt = {})
107
124
  a = OneInputAction.new(nil, title, field_label, button_title, callback, opt)
108
125
  a.run
@@ -188,6 +205,13 @@ module Gtk
188
205
  end
189
206
  end
190
207
 
208
+ def set_margin_all(widget, m)
209
+ widget.margin_bottom = m
210
+ widget.margin_top = m
211
+ widget.margin_end = m
212
+ widget.margin_start = m
213
+ end
214
+
191
215
  class OneInputAction
192
216
  def initialize(main_window, title, field_label, button_title, callback, opt = {})
193
217
  @window = Gtk::Window.new()
data/lib/vimamsa/util.rb CHANGED
@@ -1,3 +1,57 @@
1
+ require "open3"
2
+
3
+
4
+ # Run idle proc once
5
+ # Delay execution of proc until Gtk has fully processed the last calls.
6
+ def run_as_idle(p)
7
+ if p.class == Proc
8
+ Thread.new {
9
+ GLib::Idle.add(proc { p.call; false })
10
+ }
11
+ end
12
+ end
13
+
14
+ def open_url(url)
15
+ system("xdg-open", url)
16
+ end
17
+
18
+ def open_with_default_program(url)
19
+ system("xdg-open", url)
20
+ end
21
+
22
+ def run_cmd(cmd)
23
+ tmpf = Tempfile.new("vmarun", "/tmp").path
24
+ cmd = "#{cmd} > #{tmpf}"
25
+ debug "CMD:\n#{cmd}"
26
+ system("bash", "-c", cmd)
27
+ res_str = File.read(tmpf)
28
+ return res_str
29
+ end
30
+
31
+ def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = nil)
32
+ assert_binary_exists(bin_name)
33
+ if !arg5.nil?
34
+ p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4, arg5)
35
+ elsif !arg4.nil?
36
+ p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4)
37
+ elsif !arg3.nil?
38
+ p = Open3.popen2(bin_name, arg1, arg2, arg3)
39
+ elsif !arg2.nil?
40
+ p = Open3.popen2(bin_name, arg1, arg2)
41
+ elsif !arg1.nil?
42
+ p = Open3.popen2(bin_name, arg1)
43
+ else
44
+ p = Open3.popen2(bin_name)
45
+ end
46
+
47
+ ret_str = p[1].read
48
+ return ret_str
49
+ end
50
+
51
+ def mkdir_if_not_exists(_dirpath)
52
+ dirpath = File.expand_path(_dirpath)
53
+ Dir.mkdir(dirpath) unless File.exist?(dirpath)
54
+ end
1
55
 
2
56
  class HSafe
3
57
  def initialize(hash)
@@ -44,7 +98,6 @@ end
44
98
  # pp HSafe.new(h)[2]["sdf"][:llz].val
45
99
  # pp HSafe.new(h)["SDFSDFD"]["sdf"][:llz].val
46
100
 
47
-
48
101
  # From https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
49
102
  # Cross-platform way of finding an executable in the $PATH.
50
103
  #
@@ -131,6 +184,16 @@ def read_file(text, path)
131
184
  return content
132
185
  end
133
186
 
187
+ def sanitize_input(str)
188
+ if str.encoding != Encoding::UTF_8
189
+ str = text.encode(Encoding::UTF_8)
190
+ end
191
+ str.gsub!(/\r\n/, "\n")
192
+ return str
193
+ end
194
+
195
+
196
+
134
197
  def is_url(s)
135
198
  return s.match(/(https?|file):\/\/.*/) != nil
136
199
  end
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimamsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sami Sieranoja
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -190,6 +190,7 @@ files:
190
190
  - lib/vimamsa.rb
191
191
  - lib/vimamsa/ack.rb
192
192
  - lib/vimamsa/actions.rb
193
+ - lib/vimamsa/audio.rb
193
194
  - lib/vimamsa/buffer.rb
194
195
  - lib/vimamsa/buffer_list.rb
195
196
  - lib/vimamsa/buffer_manager.rb