na 1.2.28 → 1.2.30

Sign up to get free protection for your applications and to get access to all the features.
data/lib/na/pager.rb ADDED
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module NA
6
+ # Pagination
7
+ module Pager
8
+ class << self
9
+ # Boolean determines whether output is paginated
10
+ def paginate
11
+ @paginate ||= false
12
+ end
13
+
14
+ # Enable/disable pagination
15
+ #
16
+ # @param should_paginate [Boolean] true to paginate
17
+ def paginate=(should_paginate)
18
+ @paginate = should_paginate
19
+ end
20
+
21
+ # Page output. If @paginate is false, just dump to
22
+ # STDOUT
23
+ #
24
+ # @param text [String] text to paginate
25
+ #
26
+ def page(text)
27
+ unless @paginate
28
+ puts text
29
+ return
30
+ end
31
+
32
+ pager = which_pager
33
+
34
+ read_io, write_io = IO.pipe
35
+
36
+ input = $stdin
37
+
38
+ pid = Kernel.fork do
39
+ write_io.close
40
+ input.reopen(read_io)
41
+ read_io.close
42
+
43
+ # Wait until we have input before we start the pager
44
+ IO.select [input]
45
+
46
+ begin
47
+ NA.notify("{dw}Pager #{pager}", debug: true)
48
+ exec(pager)
49
+ rescue SystemCallError => e
50
+ raise Errors::DoingStandardError, "Pager error, #{e}"
51
+ end
52
+ end
53
+
54
+ begin
55
+ read_io.close
56
+ write_io.write(text)
57
+ write_io.close
58
+ rescue SystemCallError # => e
59
+ # raise Errors::DoingStandardError, "Pager error, #{e}"
60
+ end
61
+
62
+ _, status = Process.waitpid2(pid)
63
+ status.success?
64
+ end
65
+
66
+ private
67
+
68
+ def git_pager
69
+ TTY::Which.exist?('git') ? `#{TTY::Which.which('git')} config --get-all core.pager` : nil
70
+ end
71
+
72
+ def pagers
73
+ [
74
+ ENV['PAGER'],
75
+ 'less -FXr',
76
+ ENV['GIT_PAGER'],
77
+ git_pager,
78
+ 'more -r'
79
+ ].remove_bad
80
+ end
81
+
82
+ def find_executable(*commands)
83
+ execs = commands.empty? ? pagers : commands
84
+ execs
85
+ .remove_bad.uniq
86
+ .find { |cmd| TTY::Which.exist?(cmd.split.first) }
87
+ end
88
+
89
+ def which_pager
90
+ @which_pager ||= find_executable(*pagers)
91
+ end
92
+ end
93
+ end
94
+ end
data/lib/na/string.rb CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  # String helpers
4
4
  class ::String
5
+ ##
6
+ ## Tests if object is nil or empty
7
+ ##
8
+ ## @return [Boolean] true if object is defined and
9
+ ## has content
10
+ ##
11
+ def good?
12
+ !strip.empty?
13
+ end
14
+
5
15
  def read_file
6
16
  file = File.expand_path(self)
7
17
  raise "Missing file #{file}" unless File.exist?(file)
data/lib/na/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Na
2
- VERSION = '1.2.28'
2
+ VERSION = '1.2.30'
3
3
  end
data/lib/na.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'na/version'
4
+ require 'na/pager'
4
5
  require 'time'
5
6
  require 'fileutils'
6
7
  require 'shellwords'
@@ -11,6 +12,7 @@ require 'tty-which'
11
12
  require 'na/hash'
12
13
  require 'na/colors'
13
14
  require 'na/string'
15
+ require 'na/array'
14
16
  require 'na/project'
15
17
  require 'na/action'
16
18
  require 'na/next_action'
data/src/_README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  _If you're one of the rare people like me who find this useful, feel free to
10
10
  [buy me some coffee][donate]._
11
11
 
12
- The current version of `na` is <!--VER-->1.2.27<!--END VER-->.
12
+ The current version of `na` is <!--VER-->1.2.28<!--END VER-->.
13
13
 
14
14
  `na` ("next action") is a command line tool designed to make it easy to see what your next actions are for any project, right from the command line. It works with TaskPaper-formatted files (but any plain text format will do), looking for `@na` tags (or whatever you specify) in todo files in your current folder.
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: na
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.28
4
+ version: 1.2.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-21 00:00:00.000000000 Z
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -210,6 +210,7 @@ files:
210
210
  - bin/commands/archive.rb
211
211
  - bin/commands/changes.rb
212
212
  - bin/commands/complete.rb
213
+ - bin/commands/completed.rb
213
214
  - bin/commands/edit.rb
214
215
  - bin/commands/find.rb
215
216
  - bin/commands/init.rb
@@ -223,9 +224,12 @@ files:
223
224
  - bin/na
224
225
  - lib/na.rb
225
226
  - lib/na/action.rb
227
+ - lib/na/array.rb
226
228
  - lib/na/colors.rb
227
229
  - lib/na/hash.rb
230
+ - lib/na/help_monkey_patch.rb
228
231
  - lib/na/next_action.rb
232
+ - lib/na/pager.rb
229
233
  - lib/na/project.rb
230
234
  - lib/na/prompt.rb
231
235
  - lib/na/string.rb
@@ -260,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
264
  - !ruby/object:Gem::Version
261
265
  version: '0'
262
266
  requirements: []
263
- rubygems_version: 3.2.16
267
+ rubygems_version: 3.2.15
264
268
  signing_key:
265
269
  specification_version: 4
266
270
  summary: A command line tool for adding and listing project todos