vimamsa 0.1.14 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,3 @@
1
- class Grep
2
- attr_accessor :history
3
-
4
- def initialize()
5
- end
6
- end
7
1
 
8
2
  class FileSelector
9
3
  def initialize()
@@ -85,9 +79,14 @@ class Grep
85
79
  end
86
80
  vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
87
81
  reg_act(:grep_buffer, proc { Grep.new.run }, "Grep current buffer")
82
+ reg_act(:grep_refresh, proc {
83
+ if vma.buf.module.class == Grep
84
+ vma.buf.module.refresh
85
+ end
86
+ }, "Refresh current Grep buffer")
88
87
 
89
88
  bindkey "C , g", :grep_buffer
90
-
89
+ bindkey "grep ctrl-r", :grep_refresh
91
90
  end
92
91
 
93
92
  def apply_changes()
@@ -114,45 +113,54 @@ class Grep
114
113
  @line_to_id = {}
115
114
  end
116
115
 
117
- def callback(search_str, b = nil)
118
- debug "grep_cur_buffer(search_str)"
119
- lines = vma.buf.split("\n")
120
- r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE)
121
- fpath = ""
122
- fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
123
- res_str = ""
116
+ def refresh
117
+ set_buf_contents
118
+ end
119
+
120
+ def set_buf_contents()
121
+ lines = @orig_buf.split("\n")
124
122
 
125
- hlparts = []
126
123
  @grep_matches = []
124
+
125
+ res_str = ""
127
126
  lines.each_with_index { |l, i|
128
- if r.match(l)
127
+ if @r.match(l)
129
128
  res_str << "#{i + 1}:"
130
129
  # ind = scan_indexes(l, r)
131
130
  res_str << "#{l}\n"
132
131
  @grep_matches << i + 1 # Lines start from index 1
133
132
  end
134
133
  }
135
- $grep_bufid = vma.buffers.current_buf
134
+
135
+ @buf.set_content(res_str)
136
+
137
+ Gui.highlight_match(@buf, @search_str, color: cnf.match.highlight.color!)
138
+ end
139
+
140
+ def callback(search_str, b = nil)
141
+ debug "grep_cur_buffer(search_str)"
142
+ @r = Regexp.new(Regexp.escape(search_str), Regexp::IGNORECASE)
143
+ fpath = ""
144
+ fpath = vma.buf.pathname.expand_path.to_s + ":" if vma.buf.pathname
145
+
146
+ @search_str = search_str
136
147
  @orig_buf = vma.buf
137
- b = create_new_buffer(res_str, "grep")
138
- vbuf = vma.gui.view.buffer
148
+ @buf = create_new_buffer("", "grep")
139
149
 
140
- Gui.highlight_match(b, search_str, color: cnf.match.highlight.color!)
141
- b.default_mode = :grep
142
- b.module = self
150
+ @buf.default_mode = :grep
151
+ @buf.module = self
143
152
 
144
- vma.kbd.set_mode(:grep) #TODO: allow to work with other keybindings also
145
- vma.kbd.set_default_mode(:grep)
146
- b.line_action_handler = proc { |lineno|
153
+ vma.kbd.set_mode(:grep)
154
+ @buf.line_action_handler = proc { |lineno|
147
155
  debug "GREP HANDLER:#{lineno}"
148
156
  jumpto = @grep_matches[lineno]
149
157
  if jumpto.class == Integer
150
- # vma.buffers.set_current_buffer($grep_bufid, update_history = true)
151
- # buf.jump_to_line(jumpto)
152
158
  vma.buffers.set_current_buffer_by_id(@orig_buf.id)
153
159
  @orig_buf.jump_to_line(jumpto)
154
160
  end
155
161
  }
162
+
163
+ set_buf_contents
156
164
  end
157
165
 
158
166
  def run()
@@ -1,3 +1,4 @@
1
+
1
2
  def exec_in_terminal(cmd, autoclose = false)
2
3
  # debug "CMD:#{cmd}"
3
4
 
@@ -19,4 +20,15 @@ def exec_in_terminal(cmd, autoclose = false)
19
20
  fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
20
21
  end
21
22
 
23
+ def command_to_buf_callback(cmd)
24
+ require "open3"
25
+ stdout, stderr, status = Open3.capture3(cmd)
26
+ b = create_new_buffer(stdout, cmd)
27
+ end
28
+
22
29
 
30
+ load "terminal_extra.rb" if File.exist?("terminal_extra.rb")
31
+ def command_to_buf
32
+ callback = method("command_to_buf_callback")
33
+ gui_one_input_action("Execute command in shell, output to buffer", "Command:", "Execute", callback)
34
+ end
data/lib/vimamsa/util.rb CHANGED
@@ -1,5 +1,34 @@
1
1
  require "open3"
2
2
 
3
+ VOWELS = %w(a e i o u)
4
+ CONSONANTS = %w(b c d f g h j k l m n p q r s t v w x y z)
5
+
6
+ def tilde_path(abspath)
7
+ userhome = File.expand_path("~/")
8
+ abspath.sub(/^#{Regexp.escape(userhome)}\//, "~/")
9
+ end
10
+
11
+ def generate_password(length)
12
+ password = ""
13
+ while password.size < length
14
+ i = password.size + 1
15
+ if i.even?
16
+ char = CONSONANTS.sample
17
+ else
18
+ char = VOWELS.sample
19
+ end
20
+ char.upcase! if rand < 0.2
21
+ password << char
22
+ password << (1..10).to_a.sample.to_s if rand < 0.25
23
+ end
24
+ password
25
+ end
26
+
27
+ def generate_password_to_buf(length)
28
+ passw = generate_password(length)
29
+ vma.buf.insert_txt(passw)
30
+ end
31
+
3
32
  # Get all indexes for start of matching regexp
4
33
  def scan_indexes(txt, regex)
5
34
  # indexes = txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) + 1 }
@@ -23,8 +52,17 @@ def file_is_text_file(fpath)
23
52
  debug "file_is_text_file(#{fpath})"
24
53
  fpath = File.expand_path(fpath)
25
54
  return false if !File.exist?(fpath)
55
+ return false if !File.file?(fpath)
56
+
57
+ if File.size(fpath) < 1000e3 #smaler than 1MB
58
+ str = IO.read(fpath)
59
+ str.force_encoding("UTF-8")
60
+ debug "Small file with valid utf-8"
61
+ return true if str.valid_encoding?
62
+ end
63
+
64
+ #TODO: not sure if needed
26
65
  r = exec_cmd("file", fpath)
27
- debug "DEBUG:#{r}"
28
66
  return true if r.match(/UTF-8.*text/)
29
67
  return true if r.match(/ASCII.*text/)
30
68
  return false
@@ -101,7 +139,7 @@ class HSafe
101
139
  hh = @h
102
140
  while !b.empty?
103
141
  x = b.pop
104
- puts "x=#{x}"
142
+ debug "x=#{x}"
105
143
  pp b
106
144
  ok = false
107
145
  if hh.class == Hash or hh.class == Array
@@ -1,3 +1,3 @@
1
1
  module Vimamsa
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  end
data/vimamsa.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib","ext"]
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 2.4.21"
24
- spec.add_development_dependency "rake", "~> 13.0"
24
+ spec.add_development_dependency "rake", "~> 13.1.0"
25
25
 
26
26
  spec.add_runtime_dependency 'rufo', '~> 0.16.2'
27
27
 
@@ -29,7 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency 'ripl-multi_line', '~> 0.3.1'
30
30
  spec.add_runtime_dependency 'gdk4', '~> 4.2.0'
31
31
  spec.add_runtime_dependency 'gtk4', '~> 4.2.0'
32
- spec.add_runtime_dependency 'rake', '~> 13.1.0'
32
+ spec.add_runtime_dependency 'rambling-trie', '~> 2.3.1'
33
+
33
34
  spec.add_runtime_dependency 'differ', '~> 0.1.2'
34
35
  spec.add_runtime_dependency 'gtksourceview5', '~> 4.2.0'
35
36
  spec.add_runtime_dependency 'parallel', '~> 1.14' #TODO: update?
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.14
4
+ version: 0.1.16
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-11-08 00:00:00.000000000 Z
11
+ date: 2023-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '13.0'
33
+ version: 13.1.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '13.0'
40
+ version: 13.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rufo
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: 4.2.0
111
111
  - !ruby/object:Gem::Dependency
112
- name: rake
112
+ name: rambling-trie
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 13.1.0
117
+ version: 2.3.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 13.1.0
124
+ version: 2.3.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: differ
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -255,6 +255,7 @@ files:
255
255
  - lib/vimamsa/gui_menu.rb
256
256
  - lib/vimamsa/gui_select_window.rb
257
257
  - lib/vimamsa/gui_sourceview.rb
258
+ - lib/vimamsa/gui_sourceview_autocomplete.rb
258
259
  - lib/vimamsa/gui_text.rb
259
260
  - lib/vimamsa/hook.rb
260
261
  - lib/vimamsa/hyper_plain_text.rb