handy_toolbox 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8153ab3dd9d135545418c75c5b394a0d05c1462
4
- data.tar.gz: 3610c4584474c30ecc9fe3d7567c4ff62acbb650
3
+ metadata.gz: 1339da7be846b9dc3bce036dbcc4bd9338480709
4
+ data.tar.gz: 3dc2c7c12dacb1468e2e142f466dba1543f75c0e
5
5
  SHA512:
6
- metadata.gz: cf1fd975e5ec0e617243b43fa9a85eeb8f75912dfbe9355e1dea6c86efabba5b2ccc5d6dd8bd8621b3eaf61537b539626ad2ca7fd6502c24159b4ee974f85429
7
- data.tar.gz: e903eec79411f7040fdc0a18b44b5a3ca964e6a8a999b5c285f886e26ef268e20d56d73d541460534cb7480e3e6d1f10cce52b4c0e6cd8b942b9c6783186ed27
6
+ metadata.gz: 7cf4d3cae1a4daaed0b2b3e3c029bcb458ea8b76fa229535b522072aff75470de6bcc8d8322b892db7973e3b846a4c62b5b82df3960e1c590d8d05797bb4e75b
7
+ data.tar.gz: e71a860c3bbceb136a0a8e8be99caffb75ef04809b9c67d300ec8aa44f348ce3e921c11a2afef20c8fe779d8ff8355d036a0ec0ac4c9329a7c664cb0fbf76dd8
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ### Changelog
2
+
3
+ #### 0.1.1
4
+ - Replace title box with full line header
5
+ - Fix text overflow issues for long task description
6
+
7
+ #### 0.1.0
8
+ - Initial release
data/README.md CHANGED
@@ -7,12 +7,14 @@ HandyToolbox is a text based user interface that will help you with every day ta
7
7
 
8
8
  Gem was built for the Rails apps in mind but can be used standalone as well and not only for Ruby related stuff.
9
9
 
10
+ View [changelog](CHANGELOG.md).
11
+
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
13
15
 
14
16
  ```ruby
15
- gem 'handy_toolbox'
17
+ gem 'handy_toolbox', require: false
16
18
  ```
17
19
 
18
20
  And then execute:
@@ -41,6 +43,14 @@ app = App.new(title: 'Project name')
41
43
  app.run
42
44
  ```
43
45
 
46
+ If you want to use your default terminal colors you can pass extra option to app:
47
+
48
+ ```ruby
49
+ app = App.new(
50
+ default_colors: true # default is false
51
+ )
52
+ ```
53
+
44
54
  ### Defining your tasks
45
55
 
46
56
  Other example [here](EXAMPLE.md).
@@ -178,11 +188,9 @@ home / end - go to first/last item
178
188
 
179
189
  ![Main menu](promo/1.png?raw=true)
180
190
 
181
- ![Quick tasks](promo/2.png?raw=true)
182
-
183
- ![Nested menu with loader not executed yet](promo/3.png?raw=true)
191
+ ![Simple tasks](promo/2.png?raw=true)
184
192
 
185
- ![Loaded data from loader](promo/4.png?raw=true)
193
+ ![Long tasks](promo/3.png?raw=true)
186
194
 
187
195
  ## TODO
188
196
 
data/bin/example ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "handy_toolbox"
5
+ include HandyToolbox
6
+
7
+
8
+ class RakeLoader < Loader
9
+ def on_load(node)
10
+ data = IO.read('fixtures/rakes.txt')
11
+ data.strip.split("\n").each do |rake|
12
+ name, desc = rake.split("#")
13
+ node.tool name.strip, desc: desc.strip
14
+ end
15
+ end
16
+ end
17
+
18
+ class RailsDatabasePlugin < Plugin
19
+ def on_attach(node)
20
+ node.menu 'Database' do |db|
21
+ db.tool 'rails db:migrate', name: 'Migrate database'
22
+ db.tool 'rails db:test:prepare', name: 'Prepare test database'
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ branch = Cmd.exec('git branch').match(/^\* (?<name>.+)$/)[:name]
29
+ app = App.new(
30
+ title: "My project name (on #{branch})"#,
31
+ # default_colors: true
32
+ )
33
+
34
+ app.menu 'Quick' do |quick|
35
+ quick.menu 'Some'
36
+ quick.tool 'ls -la', desc: 'Lists current directory'
37
+ end
38
+
39
+ app.menu 'Rails' do |rails|
40
+ rails.plugin RailsDatabasePlugin
41
+ rails.menu_loader 'Rake', RakeLoader
42
+ rails.menu 'Assets' do |assets|
43
+ assets.tool 'rake assets:precompile', desc: 'Precompile all the assets'
44
+ end
45
+ end
46
+
47
+ app.menu 'Deployment' do |deploy|
48
+ deploy.tool 'cap staging deploy', name: 'Deploy to staging'
49
+ deploy.tool 'cap production deploy', name: 'Deploy to production'
50
+ end
51
+
52
+ app.run
@@ -0,0 +1,38 @@
1
+ rake about # List versions of all Rails frameworks and the environment
2
+ rake app:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
3
+ rake app:update # Update configs and some other initially generated files (or use just update:configs or update:bin)
4
+ rake assets:clean[keep] # Remove old compiled assets
5
+ rake assets:clobber # Remove compiled assets
6
+ rake assets:environment # Load asset compile environment
7
+ rake assets:precompile # Compile all the assets named in config.assets.precompile
8
+ rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
9
+ rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
10
+ rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases
11
+ rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases
12
+ rake db:environment:set # Set the environment value for the database
13
+ rake db:fixtures:load # Loads fixtures into the current environment's database
14
+ rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
15
+ rake db:migrate:status # Display status of migrations
16
+ rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
17
+ rake db:schema:cache:clear # Clears a db/schema_cache.dump file
18
+ rake db:schema:cache:dump # Creates a db/schema_cache.dump file
19
+ rake db:schema:dump # Creates a db/schema.rb file that is portable against any DB supported by Active Record
20
+ rake db:schema:load # Loads a schema.rb file into the database
21
+ rake db:seed # Loads the seed data from db/seeds.rb
22
+ rake db:setup # Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)
23
+ rake db:structure:dump # Dumps the database structure to db/structure.sql
24
+ rake db:structure:load # Recreates the databases from the structure.sql file
25
+ rake db:version # Retrieves the current schema version number
26
+ rake dev:cache # Toggle development mode caching on/off
27
+ rake initializers # Print out all defined initializers in the order they are invoked by Rails
28
+ rake log:clear # Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
29
+ rake middleware # Prints out your Rack middleware stack
30
+ rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
31
+ rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
32
+ rake restart # Restart app by touching tmp/restart.txt
33
+ rake routes # Print out all defined routes in match order, with names
34
+ rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
35
+ rake stats # Report code statistics (KLOCs, etc) from the application or engine
36
+ rake time:zones[country_or_offset] # List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)
37
+ rake tmp:clear # Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)
38
+ rake tmp:create # Creates tmp directories for cache, sockets, and pids
@@ -3,11 +3,11 @@ module HandyToolbox
3
3
  class App
4
4
  attr_reader :title
5
5
 
6
- def initialize(title: "Tools")
6
+ def initialize(title: "Tools", default_colors: false)
7
7
  @title = title
8
8
  @loop = true
9
9
  @builder = Menu.new(nil, nil)
10
- @screen = Screen.new
10
+ @screen = Screen.new(default_colors: default_colors)
11
11
  @navigator = Navigator.new
12
12
  @tool_runner = ToolRunner.new
13
13
  @positions = {}
@@ -21,7 +21,7 @@ module HandyToolbox
21
21
 
22
22
  while @loop
23
23
  screen.draw do
24
- draw_title
24
+ screen.header(title)
25
25
  draw_tools
26
26
  end
27
27
  handle_input
@@ -94,17 +94,8 @@ module HandyToolbox
94
94
  end
95
95
  end
96
96
 
97
- def draw_title
98
- horizontal_line = "-" * (title.size + 4)
99
- padded_title = "| #{title} |"
100
-
101
- screen.text_at(0, 0, horizontal_line)
102
- screen.text_at(0, 1, padded_title)
103
- screen.text_at(0, 2, horizontal_line)
104
- end
105
-
106
97
  def draw_tools
107
- y = 4
98
+ y = 2
108
99
  longest = find_longest_child_name
109
100
  @positions = {}
110
101
  current.children.each_with_index do |child|
@@ -119,14 +110,14 @@ module HandyToolbox
119
110
  if is_multiline
120
111
  Ui.dim do
121
112
  text = format_desc(str[1])
122
- screen.text_at(2, y + 1, text)
113
+ screen.text_at(1, y + 1, text)
123
114
  end
124
115
  text = format_child_name(child.icon, str[0], longest)
125
- screen.text_at(2, y + 2, text)
116
+ screen.text_at(1, y + 2, text)
126
117
  @positions[child.id] = y + 2
127
118
  else
128
119
  text = format_child_name(child.icon, str, longest)
129
- screen.text_at(2, y, text)
120
+ screen.text_at(1, y, text)
130
121
  @positions[child.id] = y
131
122
  end
132
123
  end
@@ -141,11 +132,11 @@ module HandyToolbox
141
132
  end
142
133
 
143
134
  def format_desc(str)
144
- " # #{str}"
135
+ " # #{str}"
145
136
  end
146
137
 
147
138
  def format_child_name(icon, name, max_len)
148
- " #{icon}#{name.ljust(max_len, ' ')} "
139
+ " #{icon}#{name.ljust(max_len, ' ')} "
149
140
  end
150
141
 
151
142
  def find_longest_child_name
@@ -3,12 +3,18 @@ require 'curses'
3
3
  module HandyToolbox
4
4
 
5
5
  class Screen
6
+ SPACE = ' '.freeze
6
7
 
7
8
  attr_reader :scroll
8
9
 
10
+ def initialize(default_colors: false)
11
+ @default_colors = default_colors
12
+ end
13
+
9
14
  def init
10
15
  Curses.init_screen
11
16
  Curses.start_color
17
+ Curses.use_default_colors if @default_colors
12
18
  Ui.hide_cursor
13
19
  Curses.cbreak
14
20
  Curses.crmode
@@ -30,8 +36,20 @@ module HandyToolbox
30
36
  Curses.refresh
31
37
  end
32
38
 
39
+ def header(title)
40
+ title = " #{title}"[0, Curses.cols - 1]
41
+ title = title.ljust(Curses.cols, SPACE)
42
+
43
+ Ui.reverse do
44
+ if scroll.fits_into_pane?(-scroll.top)
45
+ Ui.text_at(0, -scroll.top, title)
46
+ end
47
+ end
48
+ end
49
+
33
50
  def text_at(x, y, str)
34
51
  if scroll.fits_into_pane?(y)
52
+ str = str[0, Curses.cols - x - 1]
35
53
  Ui.text_at(x, y - scroll.top, str)
36
54
  end
37
55
  @max_y = y if @max_y < y
@@ -31,6 +31,12 @@ module HandyToolbox
31
31
  highlight_off if condition
32
32
  end
33
33
 
34
+ def self.reverse
35
+ attr_on Curses::A_REVERSE
36
+ yield
37
+ attr_off Curses::A_REVERSE
38
+ end
39
+
34
40
  def self.dim_on
35
41
  attr_on Curses::A_DIM
36
42
  end
@@ -1,3 +1,3 @@
1
1
  module HandyToolbox
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/promo/1.png CHANGED
Binary file
data/promo/2.png CHANGED
Binary file
data/promo/3.png CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handy_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartłomiej Wójtowicz
@@ -65,13 +65,16 @@ files:
65
65
  - ".gitignore"
66
66
  - ".ruby-gemset"
67
67
  - ".ruby-version"
68
+ - CHANGELOG.md
68
69
  - EXAMPLE.md
69
70
  - Gemfile
70
71
  - LICENSE.txt
71
72
  - README.md
72
73
  - Rakefile
73
74
  - bin/console
75
+ - bin/example
74
76
  - bin/setup
77
+ - fixtures/rakes.txt
75
78
  - handy_toolbox.gemspec
76
79
  - lib/handy_toolbox.rb
77
80
  - lib/handy_toolbox/app.rb
@@ -94,7 +97,6 @@ files:
94
97
  - promo/1.png
95
98
  - promo/2.png
96
99
  - promo/3.png
97
- - promo/4.png
98
100
  homepage: https://github.com/qbart/handy_toolbox
99
101
  licenses:
100
102
  - MIT
data/promo/4.png DELETED
Binary file