Skip to content

Commit

Permalink
feat(output): Add pagination 📚
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Aug 10, 2018
1 parent 6582fbc commit 2db523a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
15 changes: 14 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
PATH
remote: .
specs:
fakerbot (0.2.3)
fakerbot (0.2.4)
faker
pastel (~> 0.7.2)
thor (~> 0.20.0)
tty-pager
tty-screen
tty-tree

GEM
Expand Down Expand Up @@ -65,15 +67,26 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
strings (0.1.1)
unicode-display_width (~> 1.3.0)
unicode_utils (~> 1.4.0)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.20.0)
tins (1.16.3)
tty-color (0.4.3)
tty-pager (0.11.0)
strings (~> 0.1.0)
tty-screen (~> 0.6.4)
tty-which (~> 0.3.0)
tty-screen (0.6.5)
tty-tree (0.1.0)
tty-which (0.3.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.3.3)
unicode_utils (1.4.0)

PLATFORMS
ruby
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ $ fakerbot search name
## New Features! :sunglasses: :dancers:

- [x] List classes with methods E.g. Faker::FunnyName should list `.name`,`.first_name` e.t.c.
- [x] Expand search to Faker::Base sub classes i.e."fakerbot search email" should include `Faker::Internet.email`
- [x] Expand search to Faker::Base sub classes
- [x] Paginate results :book:

![screen shot 2018-08-09 at 20 21 06](https://user-images.githubusercontent.com/17295175/43914887-c9a99d84-9c11-11e8-9686-85f584412b27.jpg)

Expand All @@ -53,6 +54,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

Bug reports and pull requests are welcome on GitHub at https://github.com/akabiru/fakerbot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## Credits

Terminal awesomeness made easy by the [TTY Toolkit](http://piotrmurach.github.io/tty/). :beer:

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Expand Down
2 changes: 2 additions & 0 deletions fakerbot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
spec.add_dependency "faker"
spec.add_dependency "pastel", "~> 0.7.2"
spec.add_dependency "thor", "~> 0.20.0"
spec.add_dependency "tty-pager"
spec.add_dependency "tty-screen"
spec.add_dependency "tty-tree"

spec.add_development_dependency "bundler", "~> 1.16"
Expand Down
22 changes: 19 additions & 3 deletions lib/fakerbot/commands/search.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'pastel'
require 'tty/pager'
require 'tty/tree'
require 'fakerbot/bot'

Expand All @@ -9,11 +10,26 @@ module Commands
class Search
def initialize(options)
@options = options
@pager = TTY::Pager.new(command: 'less -R')
@screen = TTY::Screen
end

def execute(input)
result = FakerBot::Bot.find(input)
puts result.empty? ? not_found : tree(result).render
render FakerBot::Bot.find(input)
end

private

attr_reader :screen, :pager

def render(result)
return not_found if result.empty?
output = tree(result)
if screen.height < output.nodes.size
pager.page output.render
else
puts output.render
end
end

def tree(input)
Expand All @@ -27,7 +43,7 @@ def tree(input)
end

def not_found
"\n ☹️ Sorry, we couldn't find a match\n"
puts "\nSorry, we couldn't find a match 😢", "\n"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fakerbot/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FakerBot
VERSION = '0.2.3'.freeze
VERSION = '0.2.4'.freeze
end

0 comments on commit 2db523a

Please sign in to comment.