tty 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +16 -7
  6. data/CHANGELOG.md +6 -0
  7. data/Gemfile +18 -1
  8. data/README.md +55 -28
  9. data/Rakefile +5 -9
  10. data/images/tty.png +0 -0
  11. data/lib/tty.rb +7 -1
  12. data/lib/tty/coercer/boolean.rb +6 -9
  13. data/lib/tty/coercer/float.rb +14 -17
  14. data/lib/tty/coercer/integer.rb +14 -17
  15. data/lib/tty/coercer/range.rb +6 -7
  16. data/lib/tty/logger.rb +23 -9
  17. data/lib/tty/plugins.rb +3 -6
  18. data/lib/tty/plugins/plugin.rb +4 -7
  19. data/lib/tty/shell.rb +20 -12
  20. data/lib/tty/shell/question.rb +41 -48
  21. data/lib/tty/shell/question/modifier.rb +5 -8
  22. data/lib/tty/shell/question/validation.rb +8 -7
  23. data/lib/tty/shell/reader.rb +28 -19
  24. data/lib/tty/shell/response.rb +26 -22
  25. data/lib/tty/shell/statement.rb +13 -9
  26. data/lib/tty/shell/suggestion.rb +17 -13
  27. data/lib/tty/support/coercion.rb +5 -6
  28. data/lib/tty/support/conversion.rb +7 -6
  29. data/lib/tty/support/delegatable.rb +5 -5
  30. data/lib/tty/support/unicode.rb +3 -4
  31. data/lib/tty/support/utils.rb +1 -2
  32. data/lib/tty/system.rb +13 -6
  33. data/lib/tty/system/editor.rb +21 -18
  34. data/lib/tty/system/which.rb +3 -5
  35. data/lib/tty/table.rb +18 -22
  36. data/lib/tty/table/border.rb +2 -4
  37. data/lib/tty/table/border/ascii.rb +3 -2
  38. data/lib/tty/table/border/null.rb +1 -3
  39. data/lib/tty/table/border/row_line.rb +1 -4
  40. data/lib/tty/table/border/unicode.rb +3 -2
  41. data/lib/tty/table/border_dsl.rb +21 -17
  42. data/lib/tty/table/border_options.rb +6 -5
  43. data/lib/tty/table/column_set.rb +11 -7
  44. data/lib/tty/table/columns.rb +19 -16
  45. data/lib/tty/table/error.rb +1 -3
  46. data/lib/tty/table/field.rb +30 -12
  47. data/lib/tty/table/header.rb +18 -9
  48. data/lib/tty/table/indentation.rb +1 -3
  49. data/lib/tty/table/operation/alignment.rb +8 -9
  50. data/lib/tty/table/operation/alignment_set.rb +6 -5
  51. data/lib/tty/table/operation/escape.rb +3 -3
  52. data/lib/tty/table/operation/filter.rb +3 -4
  53. data/lib/tty/table/operation/truncation.rb +3 -3
  54. data/lib/tty/table/operation/wrapped.rb +3 -4
  55. data/lib/tty/table/operations.rb +19 -22
  56. data/lib/tty/table/orientation.rb +5 -5
  57. data/lib/tty/table/orientation/horizontal.rb +9 -6
  58. data/lib/tty/table/orientation/vertical.rb +10 -7
  59. data/lib/tty/table/padder.rb +46 -8
  60. data/lib/tty/table/renderer.rb +21 -14
  61. data/lib/tty/table/renderer/ascii.rb +6 -5
  62. data/lib/tty/table/renderer/basic.rb +18 -19
  63. data/lib/tty/table/renderer/unicode.rb +11 -5
  64. data/lib/tty/table/row.rb +36 -20
  65. data/lib/tty/table/transformation.rb +6 -5
  66. data/lib/tty/table/validatable.rb +32 -17
  67. data/lib/tty/terminal.rb +26 -42
  68. data/lib/tty/terminal/color.rb +10 -12
  69. data/lib/tty/terminal/echo.rb +4 -7
  70. data/lib/tty/terminal/home.rb +3 -10
  71. data/lib/tty/terminal/pager.rb +11 -10
  72. data/lib/tty/terminal/pager/basic.rb +3 -6
  73. data/lib/tty/terminal/pager/system.rb +2 -5
  74. data/lib/tty/text.rb +7 -10
  75. data/lib/tty/text/distance.rb +2 -4
  76. data/lib/tty/text/truncation.rb +1 -3
  77. data/lib/tty/text/wrapping.rb +1 -3
  78. data/lib/tty/vector.rb +3 -5
  79. data/lib/tty/version.rb +2 -2
  80. data/spec/spec_helper.rb +4 -11
  81. data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
  82. data/spec/tty/coercer/float/coerce_spec.rb +6 -4
  83. data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
  84. data/spec/tty/coercer/range/coerce_spec.rb +12 -11
  85. data/spec/tty/logger/log_spec.rb +23 -0
  86. data/spec/tty/logger/new_spec.rb +14 -14
  87. data/spec/tty/logger/valid_level_spec.rb +6 -6
  88. data/spec/tty/plugins/find_spec.rb +4 -4
  89. data/spec/tty/plugins/load_spec.rb +4 -5
  90. data/spec/tty/plugins/plugin/load_spec.rb +10 -8
  91. data/spec/tty/plugins/plugin/new_spec.rb +7 -7
  92. data/spec/tty/shell/ask_spec.rb +6 -7
  93. data/spec/tty/shell/error_spec.rb +1 -2
  94. data/spec/tty/shell/print_table_spec.rb +1 -2
  95. data/spec/tty/shell/question/argument_spec.rb +1 -1
  96. data/spec/tty/shell/question/character_spec.rb +11 -3
  97. data/spec/tty/shell/question/default_spec.rb +3 -3
  98. data/spec/tty/shell/question/in_spec.rb +1 -1
  99. data/spec/tty/shell/question/initialize_spec.rb +8 -11
  100. data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
  101. data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
  102. data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
  103. data/spec/tty/shell/question/modify_spec.rb +1 -1
  104. data/spec/tty/shell/question/valid_spec.rb +4 -4
  105. data/spec/tty/shell/question/validate_spec.rb +4 -4
  106. data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
  107. data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
  108. data/spec/tty/shell/reader/getc_spec.rb +16 -14
  109. data/spec/tty/shell/response/read_bool_spec.rb +1 -1
  110. data/spec/tty/shell/response/read_char_spec.rb +1 -2
  111. data/spec/tty/shell/response/read_date_spec.rb +1 -1
  112. data/spec/tty/shell/response/read_email_spec.rb +1 -1
  113. data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
  114. data/spec/tty/shell/response/read_number_spec.rb +1 -2
  115. data/spec/tty/shell/response/read_range_spec.rb +2 -2
  116. data/spec/tty/shell/response/read_spec.rb +7 -7
  117. data/spec/tty/shell/response/read_string_spec.rb +2 -2
  118. data/spec/tty/shell/say_spec.rb +1 -1
  119. data/spec/tty/shell/statement/initialize_spec.rb +3 -3
  120. data/spec/tty/shell/suggest_spec.rb +1 -1
  121. data/spec/tty/shell/warn_spec.rb +1 -2
  122. data/spec/tty/support/coercion_spec.rb +10 -10
  123. data/spec/tty/support/conversion_spec.rb +9 -9
  124. data/spec/tty/support/delegatable_spec.rb +7 -5
  125. data/spec/tty/support/equatable_spec.rb +32 -34
  126. data/spec/tty/support/fixtures/classes.rb +4 -2
  127. data/spec/tty/system/editor/available_spec.rb +12 -12
  128. data/spec/tty/system/editor/build_spec.rb +8 -16
  129. data/spec/tty/system/editor/command_spec.rb +3 -2
  130. data/spec/tty/system/editor/executables_spec.rb +3 -3
  131. data/spec/tty/system/editor/invoke_spec.rb +10 -14
  132. data/spec/tty/system/editor/open_spec.rb +9 -7
  133. data/spec/tty/system/platform_spec.rb +32 -13
  134. data/spec/tty/system/which/which_spec.rb +9 -9
  135. data/spec/tty/system/which_spec.rb +4 -4
  136. data/spec/tty/table/access_spec.rb +24 -21
  137. data/spec/tty/table/add_row_spec.rb +2 -2
  138. data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
  139. data/spec/tty/table/border/new_spec.rb +5 -4
  140. data/spec/tty/table/border/null/rendering_spec.rb +12 -12
  141. data/spec/tty/table/border/options/from_spec.rb +2 -3
  142. data/spec/tty/table/border/options/new_spec.rb +4 -5
  143. data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
  144. data/spec/tty/table/border_options/new_spec.rb +20 -0
  145. data/spec/tty/table/border_options/update_spec.rb +18 -0
  146. data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
  147. data/spec/tty/table/column_set/total_width_spec.rb +2 -2
  148. data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
  149. data/spec/tty/table/columns/enforce_spec.rb +2 -2
  150. data/spec/tty/table/columns/widths_spec.rb +2 -0
  151. data/spec/tty/table/data_spec.rb +3 -3
  152. data/spec/tty/table/each_spec.rb +9 -11
  153. data/spec/tty/table/each_with_index_spec.rb +8 -9
  154. data/spec/tty/table/empty_spec.rb +3 -3
  155. data/spec/tty/table/eql_spec.rb +6 -6
  156. data/spec/tty/table/field/equality_spec.rb +11 -11
  157. data/spec/tty/table/field/length_spec.rb +4 -4
  158. data/spec/tty/table/field/lines_spec.rb +3 -3
  159. data/spec/tty/table/field/new_spec.rb +7 -7
  160. data/spec/tty/table/field/width_spec.rb +6 -4
  161. data/spec/tty/table/filter_spec.rb +3 -3
  162. data/spec/tty/table/header/call_spec.rb +3 -3
  163. data/spec/tty/table/header/height_spec.rb +1 -1
  164. data/spec/tty/table/header/new_spec.rb +5 -5
  165. data/spec/tty/table/header/set_spec.rb +9 -4
  166. data/spec/tty/table/header/to_ary_spec.rb +4 -4
  167. data/spec/tty/table/header_spec.rb +3 -4
  168. data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
  169. data/spec/tty/table/initialize_spec.rb +13 -13
  170. data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
  171. data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
  172. data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
  173. data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
  174. data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
  175. data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
  176. data/spec/tty/table/operation/escape/call_spec.rb +1 -1
  177. data/spec/tty/table/operation/filter/call_spec.rb +1 -1
  178. data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
  179. data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
  180. data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
  181. data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
  182. data/spec/tty/table/operations/new_spec.rb +1 -1
  183. data/spec/tty/table/options_spec.rb +8 -8
  184. data/spec/tty/table/orientation_spec.rb +15 -13
  185. data/spec/tty/table/padder/parse_spec.rb +1 -1
  186. data/spec/tty/table/padder/to_s_spec.rb +14 -0
  187. data/spec/tty/table/padding_spec.rb +1 -1
  188. data/spec/tty/table/properties_spec.rb +9 -8
  189. data/spec/tty/table/render_spec.rb +8 -5
  190. data/spec/tty/table/render_with_spec.rb +5 -4
  191. data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
  192. data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
  193. data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
  194. data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
  195. data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
  196. data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
  197. data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
  198. data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
  199. data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
  200. data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
  201. data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
  202. data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
  203. data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
  204. data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
  205. data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
  206. data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
  207. data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
  208. data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
  209. data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
  210. data/spec/tty/table/renderer/border_spec.rb +21 -21
  211. data/spec/tty/table/renderer/render_spec.rb +7 -7
  212. data/spec/tty/table/renderer/select_spec.rb +4 -4
  213. data/spec/tty/table/renderer/style_spec.rb +19 -19
  214. data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
  215. data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
  216. data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
  217. data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
  218. data/spec/tty/table/renderer_spec.rb +1 -1
  219. data/spec/tty/table/rotate_spec.rb +27 -27
  220. data/spec/tty/table/row/access_spec.rb +3 -3
  221. data/spec/tty/table/row/call_spec.rb +4 -4
  222. data/spec/tty/table/row/data_spec.rb +5 -5
  223. data/spec/tty/table/row/each_spec.rb +1 -1
  224. data/spec/tty/table/row/equality_spec.rb +16 -16
  225. data/spec/tty/table/row/height_spec.rb +1 -1
  226. data/spec/tty/table/row/new_spec.rb +11 -11
  227. data/spec/tty/table/row/to_ary_spec.rb +3 -3
  228. data/spec/tty/table/to_s_spec.rb +8 -8
  229. data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
  230. data/spec/tty/table/validatable_spec.rb +14 -1
  231. data/spec/tty/terminal/color/code_spec.rb +3 -3
  232. data/spec/tty/terminal/color/remove_spec.rb +8 -9
  233. data/spec/tty/terminal/color/set_spec.rb +5 -6
  234. data/spec/tty/terminal/color_spec.rb +3 -5
  235. data/spec/tty/terminal/echo_spec.rb +3 -4
  236. data/spec/tty/terminal/home_spec.rb +12 -14
  237. data/spec/tty/terminal/page_spec.rb +5 -4
  238. data/spec/tty/terminal/pager/available_spec.rb +11 -11
  239. data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
  240. data/spec/tty/terminal/pager/command_spec.rb +2 -2
  241. data/spec/tty/terminal/pager/executables_spec.rb +3 -3
  242. data/spec/tty/terminal/pager/page_spec.rb +8 -10
  243. data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
  244. data/spec/tty/terminal/size_spec.rb +39 -36
  245. data/spec/tty/text/distance/distance_spec.rb +13 -13
  246. data/spec/tty/text/distance/initialize_spec.rb +4 -4
  247. data/spec/tty/text/distance_spec.rb +2 -2
  248. data/spec/tty/text/truncate_spec.rb +2 -3
  249. data/spec/tty/text/truncation/initialize_spec.rb +9 -9
  250. data/spec/tty/text/truncation/truncate_spec.rb +14 -14
  251. data/spec/tty/text/wrap_spec.rb +2 -3
  252. data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
  253. data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
  254. data/spec/tty/tty_spec.rb +22 -0
  255. data/spec/tty/vector/new_spec.rb +7 -7
  256. data/tasks/console.rake +10 -0
  257. data/tasks/coverage.rake +11 -0
  258. data/tasks/metrics/cane.rake +2 -0
  259. data/tasks/metrics/flog.rake +2 -0
  260. data/tasks/metrics/heckle.rake +15 -0
  261. data/tasks/metrics/reek.rake +2 -0
  262. data/tasks/spec.rake +29 -0
  263. data/tty.gemspec +5 -12
  264. metadata +34 -91
  265. data/.rvmrc +0 -34
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ff8d55e968e3331ebf153894ccbf0a049298bc6
4
+ data.tar.gz: 5cfbe8e57e25a74cb855e1501ce3c18c0a7b16b2
5
+ SHA512:
6
+ metadata.gz: cb5e763c659e1b78d82e179e4a25df354b7ab9939d99effe637044d5e27e0b9400025bb2bae37eeb9e350ae1f176a6b2b4227224f467d8ba8a6236cb67a80bbc
7
+ data.tar.gz: 138c0a16a982220b62b0859bbf19bef558e3a14978cbd1dcd3a57d7b706541cbafed1ffc2d6867c8c36797de30dd273a468d270c55d9268ae25d2a4694abc176
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --color
2
2
  --format progress
3
3
  --order random
4
+ --warnings
@@ -0,0 +1 @@
1
+ tty
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -1,16 +1,25 @@
1
1
  language: ruby
2
- before_install:
3
- - gem install bundler
2
+ bundler_args: --without yard guard benchmarks
3
+ script: "bundle exec rake ci"
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1.0
7
8
  - ruby-head
8
- - jruby-19mode
9
- - rbx-19mode
10
- - jruby-head
11
- - rbx-head
12
9
  matrix:
10
+ include:
11
+ - rvm: jruby-19mode
12
+ - rvm: jruby-20mode
13
+ - rvm: jruby-21mode
14
+ - rvm: jruby-head
15
+ - rvm: rbx-2
13
16
  allow_failures:
17
+ - rvm: jruby-20mode
18
+ - rvm: jruby-21mode
14
19
  - rvm: ruby-head
15
20
  - rvm: jruby-head
16
- - rvm: rbx-head
21
+ - rvm: rbx
22
+ - rvm: rbx-2
23
+ fast_finish: true
24
+ branches:
25
+ only: master
@@ -0,0 +1,6 @@
1
+ 0.1.0 (21 September, 2014)
2
+
3
+ * Simplify development dependency mangement
4
+ * Update test suite to the latest RSpec
5
+ * Improve method documentation across library
6
+ * Semantic changes across library to improve code readability
data/Gemfile CHANGED
@@ -1,4 +1,21 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in tty.gemspec
4
3
  gemspec
4
+
5
+ group :development do
6
+ gem 'rake', '~> 10.1.0'
7
+ gem 'rspec', '~> 3.1.0'
8
+ gem 'yard', '~> 0.8.7'
9
+ gem 'timecop', '~> 0.7.1'
10
+ end
11
+
12
+ group :metrics do
13
+ gem 'coveralls', '~> 0.7.0'
14
+ gem 'simplecov', '~> 0.8.2'
15
+ gem 'yardstick', '~> 0.9.9'
16
+ gem 'reek', '~> 1.3.7'
17
+ end
18
+
19
+ group :benchmarks do
20
+ gem 'benchmark_suite', '~> 1.0.0'
21
+ end
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # TTY
1
+ # [![Application icon](https://github.com/peter-murach/tty/raw/master/images/tty.png)][icon]
2
+ [icon]: http://peter-murach.github.io/tty/
2
3
  [![Gem Version](https://badge.fury.io/rb/tty.png)][gem]
3
4
  [![Build Status](https://secure.travis-ci.org/peter-murach/tty.png?branch=master)][travis]
4
5
  [![Code Climate](https://codeclimate.com/github/peter-murach/tty.png)][codeclimate]
@@ -9,17 +10,23 @@
9
10
  [codeclimate]: https://codeclimate.com/github/peter-murach/tty
10
11
  [coveralls]: https://coveralls.io/r/peter-murach/tty
11
12
 
12
- Toolbox for developing CLI clients in Ruby. This library provides a fluid interface for working with terminals.
13
+ TTY is a toolbox for developing beautiful command line clients in Ruby. It provides a fluid interface for gathering input from the user, querying system and terminal and displaying information back. It is not another command line options parser, rather a plumbing library that helps in common tasks.
14
+
15
+ ## Motivation
16
+
17
+ All too often libraries that interact with command line create their own interface logic that gathers input from users and displays information back. Many times utility files are created that contain methods for reading system or terminal properties. Shouldn't we focus our energy on building the actual client?
18
+
19
+ Even more so, any command line application needs a clear way of communicating its results back to terminal whether in tabular form, column form or colorfully indented text. Our time and energy should be spent in creating the tools not the foundation.
13
20
 
14
21
  ## Features
15
22
 
16
23
  Jump-start development of your command line app:
17
24
 
18
- * Table rendering with an easy-to-use API. [status: In Progress]
25
+ * Table rendering with an easy-to-use API. [status: ]
19
26
  * Terminal output colorization. [status: ✔ ]
20
27
  * Terminal output paging. [status: ✔ ]
21
- * System & command detection utilities. [status: In Progress]
22
- * Text manipulation(wrapping/truncation) [status: In Progress]
28
+ * System & command detection utilities. [status: ]
29
+ * Text manipulation(wrapping/truncation) [status: ]
23
30
  * Shell user interface. [status: In Progress]
24
31
  * File diffs. [status: TODO]
25
32
  * Progress bar. [status: TODO]
@@ -43,9 +50,25 @@ Or install it yourself as:
43
50
 
44
51
  $ gem install tty
45
52
 
53
+ ## Contents
54
+
55
+ * [1. Table](#1-table)
56
+ * [1.1 Rendering](#11-rendering)
57
+ * [1.2 Multiline](#12-multiline)
58
+ * [1.3 Border](#13-border)
59
+ * [1.4 Alignment](#14-alignment)
60
+ * [1.5 Padding](#15-padding)
61
+ * [1.6 Filter](#16-filter)
62
+ * [1.7 Width](#17-width)
63
+ * [2. Terminal](#2-terminal)
64
+ * [2.1 Color](#21-color)
65
+ * [2.2 Pager](#22-pager)
66
+ * [3. Shell](#3-shell)
67
+ * [4. System](#4-system)
68
+
46
69
  ## Usage
47
70
 
48
- ### Table
71
+ ### 1 Table
49
72
 
50
73
  To instantiate table pass 2-dimensional array:
51
74
 
@@ -91,9 +114,9 @@ table = TTY::Table.new do |t|
91
114
  end
92
115
  ```
93
116
 
94
- #### Rendering
117
+ #### 1.1 Rendering
95
118
 
96
- Once you have an instance of `TTY::Table` you can print it out to the stdout by doing:
119
+ Once you have an instance of `TTY::Table` you can print it out to the stdout like so:
97
120
 
98
121
  ```ruby
99
122
  table.to_s
@@ -124,7 +147,7 @@ width # constrain the table total width, otherwise dynamically
124
147
  # calculated from content and terminal size
125
148
  ```
126
149
 
127
- #### Multiline
150
+ #### 1.2 Multiline
128
151
 
129
152
  Renderer options may include `multiline` parameter. The `true` value will cause the table fields wrap at their natural line breaks or in case when the column widths are set the content will wrap.
130
153
 
@@ -154,7 +177,7 @@ table.render :ascii, multiline: false
154
177
  +------------------+-+
155
178
  ```
156
179
 
157
- #### Border
180
+ #### 1.3 Border
158
181
 
159
182
  To print border around data table you need to specify `renderer` type out of `basic`, `ascii`, `unicode`. By default `basic` is used. For instance, to output unicode border:
160
183
 
@@ -239,7 +262,7 @@ table.render do |renderer|
239
262
  end
240
263
  ```
241
264
 
242
- #### Alignment
265
+ #### 1.4 Alignment
243
266
 
244
267
  All columns are left aligned by default. You can enforce per column alignment by passing `column_aligns` option like so
245
268
 
@@ -265,7 +288,7 @@ table = TTY::Table.new do |t|
265
288
  end
266
289
  ```
267
290
 
268
- #### Padding
291
+ #### 1.5 Padding
269
292
 
270
293
  By default padding is not applied. You can add `padding` to table fields like so
271
294
 
@@ -299,7 +322,7 @@ table.render { |renderer|
299
322
  +-----+-------+----+---+-------+-----+
300
323
  ```
301
324
 
302
- #### Filter
325
+ #### 1.6 Filter
303
326
 
304
327
  You can define filters that will modify individual table fields value before they are rendered. A filter can be a callable such as proc. Here's an example that formats
305
328
 
@@ -334,7 +357,7 @@ table.render do |renderer|
334
357
  end
335
358
  ```
336
359
 
337
- #### Width
360
+ #### 1.7 Width
338
361
 
339
362
  To control table's column sizes pass `width`, `resize` options. By default table's natural column widths are calculated from the content. If the total table width does not fit in terminal window then the table is rotated vertically to preserve content.
340
363
 
@@ -354,7 +377,7 @@ table.render width: 80, resize: true
354
377
  +---------+-------+------------+
355
378
  ```
356
379
 
357
- ### Terminal
380
+ ### 2 Terminal
358
381
 
359
382
  To read general terminal properties you can use on of the helpers
360
383
 
@@ -367,6 +390,8 @@ term.echo(false) { } # switch off echo for the block
367
390
  term.page # page terminal output, on non unix systems falls back to ruby implementation
368
391
  ```
369
392
 
393
+ #### 2.1 Color
394
+
370
395
  To colorize your output do
371
396
 
372
397
  ```ruby
@@ -390,13 +415,15 @@ white
390
415
 
391
416
  To supply background color simply prefix it with `on_`. For example a green background would be `on_green`.
392
417
 
418
+ #### 2.2 Pager
419
+
393
420
  To page your output do
394
421
 
395
422
  ```ruby
396
423
  term.page 'long text...'
397
424
  ```
398
425
 
399
- ### Shell
426
+ ### 3 Shell
400
427
 
401
428
  Main responsibility is to interact with the prompt and provide convenience methods.
402
429
 
@@ -424,16 +451,16 @@ answer = shell.ask("What is your name?").read_string
424
451
  The library provides small DSL to help with parsing and asking precise questions
425
452
 
426
453
  ```ruby
427
- argument # :required or :optional
428
- character # turn character based input, otherwise line (default: false)
429
- clean # reset question
430
- default # default value used if none is provided
431
- echo # turn echo on and off (default: true)
432
- mask # mask characters i.e '****' (default: false)
433
- modify # apply answer modification :upcase, :downcase, :trim, :chomp etc..
434
- range # specify range '0-9', '0..9', '0...9' or negative '-1..-9'
435
- validate # regex against which stdin input is checked
436
- valid # a list of expected valid options
454
+ argument # :required or :optional
455
+ char # turn character based input, otherwise line (default: false)
456
+ clean # reset question
457
+ default # default value used if none is provided
458
+ echo # turn echo on and off (default: true)
459
+ mask # mask characters i.e '****' (default: false)
460
+ modify # apply answer modification :upcase, :downcase, :trim, :chomp etc..
461
+ range # specify range '0-9', '0..9', '0...9' or negative '-1..-9'
462
+ validate # regex against which stdin input is checked
463
+ valid # a list of expected valid options
437
464
  ```
438
465
 
439
466
  You can chain question methods or configure them inside a block
@@ -495,7 +522,7 @@ shell.suggest('sta', ['stage', 'stash', 'commit', 'branch'])
495
522
  stash
496
523
  ```
497
524
 
498
- ### System
525
+ ### 4 System
499
526
 
500
527
  ```ruby
501
528
  TTY::System.unix? # check if unix platform
@@ -527,4 +554,4 @@ TTY::System.editor.open('file path...')
527
554
 
528
555
  ## Copyright
529
556
 
530
- Copyright (c) 2012-2013 Piotr Murach. See LICENSE for further details.
557
+ Copyright (c) 2012-2014 Piotr Murach. See LICENSE for further details.
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.unshift File.expand_path('../lib', __FILE__)
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
1
+ # encoding: utf-8
5
2
 
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = FileList['spec/**/*_spec.rb']
8
- end
3
+ require "bundler/gem_tasks"
9
4
 
10
- FileList['tasks/**/*.rake'].each { |task| import task }
5
+ FileList['tasks/**/*.rake'].each(&method(:import))
11
6
 
12
- task :default => [:spec]
7
+ desc 'Run all specs'
8
+ task ci: %w[ spec ]
Binary file
data/lib/tty.rb CHANGED
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  require 'tty/version'
4
4
 
@@ -115,7 +115,12 @@ module TTY
115
115
  EMPTY_ARRAY = Array.new.freeze
116
116
 
117
117
  class << self
118
+ def included(base)
119
+ base.send :extend, ClassMethods
120
+ end
121
+ end
118
122
 
123
+ module ClassMethods
119
124
  # Return shared terminal instance
120
125
  #
121
126
  # @return [TTY::Terminal]
@@ -153,4 +158,5 @@ module TTY
153
158
  end
154
159
  end
155
160
 
161
+ extend ClassMethods
156
162
  end # TTY
@@ -1,11 +1,9 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module TTY
4
4
  class Coercer
5
-
6
5
  # A class responsible for boolean type coercion
7
6
  class Boolean
8
-
9
7
  # Coerce value to boolean type including range of strings such as
10
8
  #
11
9
  # @param [Object] value
@@ -16,7 +14,8 @@ module TTY
16
14
  # other values coerced to true are:
17
15
  # 1, t, T, TRUE, true, True, y, Y, YES, yes, Yes
18
16
  #
19
- # coerce("False") # => false
17
+ # @example
18
+ # coerce("False") # => false
20
19
  #
21
20
  # other values coerced to false are:
22
21
  # 0, f, F, FALSE, false, False, n, N, No, no, No
@@ -24,16 +23,14 @@ module TTY
24
23
  # @api public
25
24
  def self.coerce(value)
26
25
  case value.to_s
27
- when %r/^(yes|y|t(rue)?|1)$/i
26
+ when /^(yes|y|t(rue)?|1)$/i
28
27
  return true
29
- when %r/^(no|n|f(alse)?|0)$/i
28
+ when /^(no|n|f(alse)?|0)$/i
30
29
  return false
31
30
  else
32
- raise TypeError, "Expected boolean type, got #{value}"
31
+ fail TypeError, "Expected boolean type, got #{value}"
33
32
  end
34
33
  end
35
-
36
34
  end # Boolean
37
-
38
35
  end # Coercer
39
36
  end # TTY
@@ -1,23 +1,20 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module TTY
4
4
  class Coercer
5
-
6
- class Float
7
-
8
- def self.coerce(value, strict=true)
9
- begin
10
- Kernel.send(:Float, value.to_s)
11
- rescue
12
- if strict
13
- raise InvalidArgument, "#{value} could not be coerced into Float"
14
- else
15
- value.to_f
16
- end
17
- end
5
+ # Coerce values into float number
6
+ #
7
+ # @api public
8
+ class Float
9
+ def self.coerce(value, strict = true)
10
+ Kernel.send(:Float, value.to_s)
11
+ rescue
12
+ if strict
13
+ raise InvalidArgument, "#{value} could not be coerced into Float"
14
+ else
15
+ value.to_f
18
16
  end
19
-
20
- end # Float
21
-
17
+ end
18
+ end # Float
22
19
  end # Coercer
23
20
  end # TTY
@@ -1,23 +1,20 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
 
3
3
  module TTY
4
4
  class Coercer
5
-
6
- class Integer
7
-
8
- def self.coerce(value, strict=true)
9
- begin
10
- Kernel.send(:Integer, value.to_s)
11
- rescue
12
- if strict
13
- raise InvalidArgument, "#{value} could not be coerced into Integer"
14
- else
15
- value.to_i
16
- end
17
- end
5
+ # Coerce value into integer number
6
+ #
7
+ # @api public
8
+ class Integer
9
+ def self.coerce(value, strict = true)
10
+ Kernel.send(:Integer, value.to_s)
11
+ rescue
12
+ if strict
13
+ raise InvalidArgument, "#{value} could not be coerced into Integer"
14
+ else
15
+ value.to_i
18
16
  end
19
-
20
- end # Integer
21
-
17
+ end
18
+ end # Integer
22
19
  end # Coercer
23
20
  end # TTY