howzit 2.0.26 → 2.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/howzit/prompt.rb +64 -38
- data/lib/howzit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 135c2149bfce9fb01705564408ded6052edef780b415d1b305e292c6d3701f57
|
4
|
+
data.tar.gz: c4cfbbd4a6517aa33078c69600f88656ec4c07547c5ff6dcc65cae1151feb47a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3981a7b2eba17397a7e7723105a7f80f7387b04d3a2fabc442fe63a7c27fa79d954801c4527f2168cb557c16e7da865228d8ffb5f7bff55c754c5623010390f6
|
7
|
+
data.tar.gz: 8cee197d4b84557bddcc5d2584c4784af88ade9424c06cf73d2efdd8735e7675db711d20cfcb98efc91fcb722d91b464aa8a45fa85e0c5c1dd8e8509100460e2
|
data/CHANGELOG.md
CHANGED
data/lib/howzit/prompt.rb
CHANGED
@@ -87,60 +87,86 @@ module Howzit
|
|
87
87
|
return [] if !$stdout.isatty || matches.count.zero?
|
88
88
|
|
89
89
|
if Util.command_exist?('fzf')
|
90
|
-
height =
|
91
|
-
|
92
|
-
|
93
|
-
TTY::Screen.rows
|
94
|
-
end
|
95
|
-
|
96
|
-
settings = [
|
97
|
-
'-0',
|
98
|
-
'-1',
|
99
|
-
'-m',
|
100
|
-
"--height=#{height}",
|
101
|
-
'--header="Tab: add selection, ctrl-a/d: (de)select all, return: display/run"',
|
102
|
-
'--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all',
|
103
|
-
'--prompt="Select a topic > "',
|
104
|
-
%(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
|
105
|
-
]
|
90
|
+
height = height == :auto ? matches.count + 3 : TTY::Screen.rows
|
91
|
+
|
92
|
+
settings = fzf_options(height)
|
106
93
|
res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
94
|
+
return fzf_result(res)
|
95
|
+
end
|
96
|
+
|
97
|
+
tty_menu(matches)
|
98
|
+
end
|
99
|
+
|
100
|
+
def fzf_result(res)
|
101
|
+
if res.nil? || res.empty?
|
102
|
+
Howzit.console.info 'Cancelled'
|
103
|
+
Process.exit 0
|
112
104
|
end
|
105
|
+
return res.split(/\n/)
|
106
|
+
end
|
107
|
+
|
108
|
+
def fzf_options(height)
|
109
|
+
[
|
110
|
+
'-0',
|
111
|
+
'-1',
|
112
|
+
'-m',
|
113
|
+
"--height=#{height}",
|
114
|
+
'--header="Tab: add selection, ctrl-a/d: (de)select all, return: display/run"',
|
115
|
+
'--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all',
|
116
|
+
'--prompt="Select a topic > "',
|
117
|
+
%(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
|
118
|
+
]
|
119
|
+
end
|
113
120
|
|
121
|
+
##
|
122
|
+
## Display a numeric menu on the TTY
|
123
|
+
##
|
124
|
+
## @param matches The matches from which to select
|
125
|
+
##
|
126
|
+
def tty_menu(matches)
|
114
127
|
return matches if matches.count == 1
|
115
128
|
|
116
|
-
|
117
|
-
stty_save = `stty -g`.chomp
|
129
|
+
@stty_save = `stty -g`.chomp
|
118
130
|
|
119
131
|
trap('INT') do
|
120
|
-
system('stty'
|
132
|
+
system('stty')
|
121
133
|
exit
|
122
134
|
end
|
123
135
|
|
124
136
|
options_list(matches)
|
137
|
+
read_selection(matches)
|
138
|
+
end
|
125
139
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
140
|
+
##
|
141
|
+
## Read a single number response from the command line
|
142
|
+
##
|
143
|
+
## @param matches The matches
|
144
|
+
##
|
145
|
+
def read_selection(matches)
|
146
|
+
printf "Type 'q' to cancel, enter for first item"
|
147
|
+
while (line = Readline.readline(': ', true))
|
148
|
+
line = read_num(line)
|
134
149
|
|
135
|
-
|
150
|
+
return [matches[line - 1]] if line.positive? && line <= matches.length
|
136
151
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
152
|
+
puts 'Out of range'
|
153
|
+
read_selection(matches)
|
154
|
+
end
|
155
|
+
ensure
|
156
|
+
system('stty', @stty_save)
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
## Convert a response to an Integer
|
161
|
+
##
|
162
|
+
## @param line The response to convert
|
163
|
+
##
|
164
|
+
def read_num(line)
|
165
|
+
if line =~ /^[a-z]/i
|
166
|
+
system('stty', @stty_save) # Restore
|
142
167
|
exit
|
143
168
|
end
|
169
|
+
line == '' ? 1 : line.to_i
|
144
170
|
end
|
145
171
|
end
|
146
172
|
end
|
data/lib/howzit/version.rb
CHANGED