line_by_line 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d20ff0c0484599e200aad63ca99603d87563d5463115e22435ab21179714c079
4
+ data.tar.gz: 6f3c7d2106176f5edaa5c9f96d3163a18f6503db17a46604e5a33f861a736a85
5
+ SHA512:
6
+ metadata.gz: abd06c83ca32fdca8eb342b5325b2d87b0cb40af526aa9939cebcbd2bc26767182d922e376d528f52316dedfeef025eeb2d12d074f30bd6162e65bd2b7687e17
7
+ data.tar.gz: 98a0e843221129be61af9e542e6216f93a0da3f6586d79e628601a26b049c7b58dd4499634a44805a5b419c777a1e2742aba9d8583e0012d41ba323bca5cf780
data/bin/line_by_line ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: UTF-8
3
+ =begin
4
+ /***************************************************************************
5
+ * ©2015-2015 Michael Uplawski <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************
22
+ =end
23
+
24
+ require_relative "../lib/line_by_line.rb"
25
+
26
+ LineByLine.new(ARGV)
@@ -0,0 +1,429 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <meta name="generator" content="Docutils 0.13.1: http://docutils.sourceforge.net/" />
7
+ <title>Line_by_line</title>
8
+ <style type="text/css">
9
+
10
+ /*
11
+ :Author: David Goodger (goodger@python.org)
12
+ :Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
13
+ :Copyright: This stylesheet has been placed in the public domain.
14
+
15
+ Default cascading style sheet for the HTML output of Docutils.
16
+
17
+ See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
18
+ customize this style sheet.
19
+ */
20
+
21
+ /* used to remove borders from tables and images */
22
+ .borderless, table.borderless td, table.borderless th {
23
+ border: 0 }
24
+
25
+ table.borderless td, table.borderless th {
26
+ /* Override padding for "table.docutils td" with "! important".
27
+ The right padding separates the table cells. */
28
+ padding: 0 0.5em 0 0 ! important }
29
+
30
+ .first {
31
+ /* Override more specific margin styles with "! important". */
32
+ margin-top: 0 ! important }
33
+
34
+ .last, .with-subtitle {
35
+ margin-bottom: 0 ! important }
36
+
37
+ .hidden {
38
+ display: none }
39
+
40
+ .subscript {
41
+ vertical-align: sub;
42
+ font-size: smaller }
43
+
44
+ .superscript {
45
+ vertical-align: super;
46
+ font-size: smaller }
47
+
48
+ a.toc-backref {
49
+ text-decoration: none ;
50
+ color: black }
51
+
52
+ blockquote.epigraph {
53
+ margin: 2em 5em ; }
54
+
55
+ dl.docutils dd {
56
+ margin-bottom: 0.5em }
57
+
58
+ object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
59
+ overflow: hidden;
60
+ }
61
+
62
+ /* Uncomment (and remove this text!) to get bold-faced definition list terms
63
+ dl.docutils dt {
64
+ font-weight: bold }
65
+ */
66
+
67
+ div.abstract {
68
+ margin: 2em 5em }
69
+
70
+ div.abstract p.topic-title {
71
+ font-weight: bold ;
72
+ text-align: center }
73
+
74
+ div.admonition, div.attention, div.caution, div.danger, div.error,
75
+ div.hint, div.important, div.note, div.tip, div.warning {
76
+ margin: 2em ;
77
+ border: medium outset ;
78
+ padding: 1em }
79
+
80
+ div.admonition p.admonition-title, div.hint p.admonition-title,
81
+ div.important p.admonition-title, div.note p.admonition-title,
82
+ div.tip p.admonition-title {
83
+ font-weight: bold ;
84
+ font-family: sans-serif }
85
+
86
+ div.attention p.admonition-title, div.caution p.admonition-title,
87
+ div.danger p.admonition-title, div.error p.admonition-title,
88
+ div.warning p.admonition-title, .code .error {
89
+ color: red ;
90
+ font-weight: bold ;
91
+ font-family: sans-serif }
92
+
93
+ /* Uncomment (and remove this text!) to get reduced vertical space in
94
+ compound paragraphs.
95
+ div.compound .compound-first, div.compound .compound-middle {
96
+ margin-bottom: 0.5em }
97
+
98
+ div.compound .compound-last, div.compound .compound-middle {
99
+ margin-top: 0.5em }
100
+ */
101
+
102
+ div.dedication {
103
+ margin: 2em 5em ;
104
+ text-align: center ;
105
+ font-style: italic }
106
+
107
+ div.dedication p.topic-title {
108
+ font-weight: bold ;
109
+ font-style: normal }
110
+
111
+ div.figure {
112
+ margin-left: 2em ;
113
+ margin-right: 2em }
114
+
115
+ div.footer, div.header {
116
+ clear: both;
117
+ font-size: smaller }
118
+
119
+ div.line-block {
120
+ display: block ;
121
+ margin-top: 1em ;
122
+ margin-bottom: 1em }
123
+
124
+ div.line-block div.line-block {
125
+ margin-top: 0 ;
126
+ margin-bottom: 0 ;
127
+ margin-left: 1.5em }
128
+
129
+ div.sidebar {
130
+ margin: 0 0 0.5em 1em ;
131
+ border: medium outset ;
132
+ padding: 1em ;
133
+ background-color: #ffffee ;
134
+ width: 40% ;
135
+ float: right ;
136
+ clear: right }
137
+
138
+ div.sidebar p.rubric {
139
+ font-family: sans-serif ;
140
+ font-size: medium }
141
+
142
+ div.system-messages {
143
+ margin: 5em }
144
+
145
+ div.system-messages h1 {
146
+ color: red }
147
+
148
+ div.system-message {
149
+ border: medium outset ;
150
+ padding: 1em }
151
+
152
+ div.system-message p.system-message-title {
153
+ color: red ;
154
+ font-weight: bold }
155
+
156
+ div.topic {
157
+ margin: 2em }
158
+
159
+ h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
160
+ h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
161
+ margin-top: 0.4em }
162
+
163
+ h1.title {
164
+ text-align: center }
165
+
166
+ h2.subtitle {
167
+ text-align: center }
168
+
169
+ hr.docutils {
170
+ width: 75% }
171
+
172
+ img.align-left, .figure.align-left, object.align-left, table.align-left {
173
+ clear: left ;
174
+ float: left ;
175
+ margin-right: 1em }
176
+
177
+ img.align-right, .figure.align-right, object.align-right, table.align-right {
178
+ clear: right ;
179
+ float: right ;
180
+ margin-left: 1em }
181
+
182
+ img.align-center, .figure.align-center, object.align-center {
183
+ display: block;
184
+ margin-left: auto;
185
+ margin-right: auto;
186
+ }
187
+
188
+ table.align-center {
189
+ margin-left: auto;
190
+ margin-right: auto;
191
+ }
192
+
193
+ .align-left {
194
+ text-align: left }
195
+
196
+ .align-center {
197
+ clear: both ;
198
+ text-align: center }
199
+
200
+ .align-right {
201
+ text-align: right }
202
+
203
+ /* reset inner alignment in figures */
204
+ div.align-right {
205
+ text-align: inherit }
206
+
207
+ /* div.align-center * { */
208
+ /* text-align: left } */
209
+
210
+ .align-top {
211
+ vertical-align: top }
212
+
213
+ .align-middle {
214
+ vertical-align: middle }
215
+
216
+ .align-bottom {
217
+ vertical-align: bottom }
218
+
219
+ ol.simple, ul.simple {
220
+ margin-bottom: 1em }
221
+
222
+ ol.arabic {
223
+ list-style: decimal }
224
+
225
+ ol.loweralpha {
226
+ list-style: lower-alpha }
227
+
228
+ ol.upperalpha {
229
+ list-style: upper-alpha }
230
+
231
+ ol.lowerroman {
232
+ list-style: lower-roman }
233
+
234
+ ol.upperroman {
235
+ list-style: upper-roman }
236
+
237
+ p.attribution {
238
+ text-align: right ;
239
+ margin-left: 50% }
240
+
241
+ p.caption {
242
+ font-style: italic }
243
+
244
+ p.credits {
245
+ font-style: italic ;
246
+ font-size: smaller }
247
+
248
+ p.label {
249
+ white-space: nowrap }
250
+
251
+ p.rubric {
252
+ font-weight: bold ;
253
+ font-size: larger ;
254
+ color: maroon ;
255
+ text-align: center }
256
+
257
+ p.sidebar-title {
258
+ font-family: sans-serif ;
259
+ font-weight: bold ;
260
+ font-size: larger }
261
+
262
+ p.sidebar-subtitle {
263
+ font-family: sans-serif ;
264
+ font-weight: bold }
265
+
266
+ p.topic-title {
267
+ font-weight: bold }
268
+
269
+ pre.address {
270
+ margin-bottom: 0 ;
271
+ margin-top: 0 ;
272
+ font: inherit }
273
+
274
+ pre.literal-block, pre.doctest-block, pre.math, pre.code {
275
+ margin-left: 2em ;
276
+ margin-right: 2em }
277
+
278
+ pre.code .ln { color: grey; } /* line numbers */
279
+ pre.code, code { background-color: #eeeeee }
280
+ pre.code .comment, code .comment { color: #5C6576 }
281
+ pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
282
+ pre.code .literal.string, code .literal.string { color: #0C5404 }
283
+ pre.code .name.builtin, code .name.builtin { color: #352B84 }
284
+ pre.code .deleted, code .deleted { background-color: #DEB0A1}
285
+ pre.code .inserted, code .inserted { background-color: #A3D289}
286
+
287
+ span.classifier {
288
+ font-family: sans-serif ;
289
+ font-style: oblique }
290
+
291
+ span.classifier-delimiter {
292
+ font-family: sans-serif ;
293
+ font-weight: bold }
294
+
295
+ span.interpreted {
296
+ font-family: sans-serif }
297
+
298
+ span.option {
299
+ white-space: nowrap }
300
+
301
+ span.pre {
302
+ white-space: pre }
303
+
304
+ span.problematic {
305
+ color: red }
306
+
307
+ span.section-subtitle {
308
+ /* font-size relative to parent (h1..h6 element) */
309
+ font-size: 80% }
310
+
311
+ table.citation {
312
+ border-left: solid 1px gray;
313
+ margin-left: 1px }
314
+
315
+ table.docinfo {
316
+ margin: 2em 4em }
317
+
318
+ table.docutils {
319
+ margin-top: 0.5em ;
320
+ margin-bottom: 0.5em }
321
+
322
+ table.footnote {
323
+ border-left: solid 1px black;
324
+ margin-left: 1px }
325
+
326
+ table.docutils td, table.docutils th,
327
+ table.docinfo td, table.docinfo th {
328
+ padding-left: 0.5em ;
329
+ padding-right: 0.5em ;
330
+ vertical-align: top }
331
+
332
+ table.docutils th.field-name, table.docinfo th.docinfo-name {
333
+ font-weight: bold ;
334
+ text-align: left ;
335
+ white-space: nowrap ;
336
+ padding-left: 0 }
337
+
338
+ /* "booktabs" style (no vertical lines) */
339
+ table.docutils.booktabs {
340
+ border: 0px;
341
+ border-top: 2px solid;
342
+ border-bottom: 2px solid;
343
+ border-collapse: collapse;
344
+ }
345
+ table.docutils.booktabs * {
346
+ border: 0px;
347
+ }
348
+ table.docutils.booktabs th {
349
+ border-bottom: thin solid;
350
+ text-align: left;
351
+ }
352
+
353
+ h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
354
+ h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
355
+ font-size: 100% }
356
+
357
+ ul.auto-toc {
358
+ list-style-type: none }
359
+
360
+ </style>
361
+ </head>
362
+ <body>
363
+ <div class="document" id="line-by-line">
364
+ <h1 class="title">Line_By_Line</h1>
365
+ <h2 class="subtitle" id="display-the-content-of-text-files-line-by-line">Display the content of text-files line by line</h2>
366
+
367
+ <div class="section" id="synopsis">
368
+ <h1>Synopsis</h1>
369
+ <p>line_by_line -s [textfile] &lt;options&gt;</p>
370
+ </div>
371
+ <div class="section" id="description">
372
+ <h1>Description</h1>
373
+ <p><em>line_by_line</em> will print out the content of a text file one line at a time,
374
+ and the next line only after the user has pushed a key. The default-behavior is
375
+ to progress character by character through a line of text, to create the
376
+ impression of the text just being typed, while you read along. You can impose
377
+ with the option <em>-f</em>, that a whole line is displayed at once, instead and with
378
+ the option <em>-l</em> determine the line-number where the output shall start.</p>
379
+ </div>
380
+ <div class="section" id="options">
381
+ <h1>Options</h1>
382
+ <div class="section" id="specific-options">
383
+ <h2>Specific options:</h2>
384
+ <blockquote>
385
+ <p>-s, --source FILE read this file (<strong>MANDATORY</strong>)</p>
386
+ <p>-f, --fast display at once entire lines</p>
387
+ <p>-l, --line LINE start reading file at line 'line'</p>
388
+ </blockquote>
389
+ </div>
390
+ <div class="section" id="common-options">
391
+ <h2>Common options:</h2>
392
+ <blockquote>
393
+ <p>-h, --help Show the short help message</p>
394
+ <p>-v, --version Show version and program information</p>
395
+ </blockquote>
396
+ </div>
397
+ </div>
398
+ <div class="section" id="other-information">
399
+ <h1>Other Information</h1>
400
+ <table class="docutils field-list" frame="void" rules="none">
401
+ <col class="field-name" />
402
+ <col class="field-body" />
403
+ <tbody valign="top">
404
+ <tr class="field"><th class="field-name">License:</th><td class="field-body"><em>line_by_line</em> is distributed as Free Software under the conditions
405
+ of the Gnu General Public License, version 3 or later
406
+ (<a class="reference external" href="http://gnu.org/licenses/gpl.html">http://gnu.org/licenses/gpl.html</a>).</td>
407
+ </tr>
408
+ <tr class="field"><th class="field-name">Version:</th><td class="field-body">0.8 (May 2017)</td>
409
+ </tr>
410
+ <tr class="field"><th class="field-name" colspan="2">Development and Source Code:</th></tr>
411
+ <tr class="field"><td>&nbsp;</td><td class="field-body"><em>line_by_line</em> is programmed in Ruby and
412
+ distributed as a Ruby-Gem. If you have installed
413
+ the program from this Gem-file, find the
414
+ gem-folder for your ruby-version (something like
415
+ /usr/lib/ruby/gems/[version]/gems/line_by_line)
416
+ and access the source-files there. Otherwise you
417
+ can also unpack the gem-file with <em>tar -xf</em> then
418
+ decompress the data-archive with <em>gunzip</em>.</td>
419
+ </tr>
420
+ <tr class="field"><th class="field-name">Author:</th><td class="field-body"><em>line_by_line</em> has been developed by Michael Uplawski
421
+ &lt;<a class="reference external" href="mailto:michael.uplawski&#64;uplawski.eu">michael.uplawski&#64;uplawski.eu</a>&gt;</td>
422
+ </tr>
423
+ </tbody>
424
+ </table>
425
+ <p><strong>Ω</strong></p>
426
+ </div>
427
+ </div>
428
+ </body>
429
+ </html>
Binary file
@@ -0,0 +1,61 @@
1
+ =========================
2
+ Line_By_Line
3
+ =========================
4
+ -------------------------------------------------
5
+ Display the content of text-files line by line
6
+ -------------------------------------------------
7
+
8
+ Synopsis
9
+ =========
10
+ line_by_line -s [textfile] <options>
11
+
12
+ Description
13
+ ============
14
+ *line_by_line* will print out the content of a text file one line at a time,
15
+ and the next line only after the user has pushed a key. The default-behavior is
16
+ to progress character by character through a line of text, to create the
17
+ impression of the text just being typed, while you read along. You can impose
18
+ with the option *-f*, that a whole line is displayed at once, instead and with
19
+ the option *-l* determine the line-number where the output shall start.
20
+
21
+ Options
22
+ =========
23
+ Specific options:
24
+ ------------------
25
+
26
+ -s, --source FILE read this file (**MANDATORY**)
27
+
28
+ -f, --fast display at once entire lines
29
+
30
+ -l, --line LINE start reading file at line 'line'
31
+
32
+ Common options:
33
+ ----------------
34
+
35
+ -h, --help Show the short help message
36
+
37
+ -v, --version Show version and program information
38
+
39
+ Other Information
40
+ ==================
41
+
42
+ :License: *line_by_line* is distributed as Free Software under the conditions
43
+ of the Gnu General Public License, version 3 or later
44
+ (http://gnu.org/licenses/gpl.html).
45
+
46
+
47
+ :Version: 0.8 (May 2017)
48
+
49
+ :Development and Source Code: *line_by_line* is programmed in Ruby and
50
+ distributed as a Ruby-Gem. If you have installed
51
+ the program from this Gem-file, find the
52
+ gem-folder for your ruby-version (something like
53
+ /usr/lib/ruby/gems/[version]/gems/line_by_line)
54
+ and access the source-files there. Otherwise you
55
+ can also unpack the gem-file with *tar -xf* then
56
+ decompress the data-archive with *gunzip*.
57
+
58
+ :Author: *line_by_line* has been developed by Michael Uplawski
59
+ <michael.uplawski@uplawski.eu>
60
+
61
+ **Ω**
data/lib/argparser.rb ADDED
@@ -0,0 +1,81 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2015-2021 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+
23
+
24
+ require 'optparse'
25
+ require 'optparse/time'
26
+ require 'ostruct'
27
+ require_relative 'logging'
28
+ require_relative 'version'
29
+
30
+ class ArgParser
31
+ include Logging
32
+
33
+ # Returns a structure describing the options.
34
+ #
35
+ def self.parse(args)
36
+ # The options specified on the command line will be collected in <b>options</b>.
37
+ # We set default values here.
38
+ options = OpenStruct.new
39
+ options.fast = false
40
+ options.line = 0
41
+ options.file = nil
42
+
43
+ op = OptionParser.new do |opts|
44
+ opts.banner = "Usage:\t" << "%s -s [textfile] <options>" %($0) <<"\n"
45
+
46
+ opts.separator ""
47
+ opts.separator "Specific options:"
48
+
49
+ opts.on('-' << "sFILE", '--' << "source FILE", "read this file") do |file|
50
+ options.file = file
51
+ end
52
+
53
+ opts.on('-' << "f", '--' << "fast", "display at once entire lines") do |fast|
54
+ options.fast = true
55
+ end
56
+ opts.on('-' << 'lLINE', '--' << "line LINE", "start reading file at line 'line'") do |line|
57
+ options.line = line.to_i - 1
58
+ end
59
+
60
+ opts.separator ""
61
+ opts.separator ("Common options") << ':'
62
+
63
+ # No argument, shows at tail. This will print an options summary.
64
+ opts.on_tail(("-h"), ("--help"), ("Show this message") ) do
65
+ puts opts
66
+ exit true
67
+ end
68
+
69
+ opts.on_tail(("-v"), ("--version"), ("Show version and program information") ) do
70
+ puts "\t#{APPNAME}, version #{VERSION} (called as #{$0})"
71
+ puts "\t© 2015-#{YEAR} #{AUTHOR} #{AMAIL}>"
72
+ exit true
73
+ end
74
+ end
75
+
76
+ op.parse!(args)
77
+ options
78
+ end # parse()
79
+
80
+ end
81
+
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: UTF-8
3
+ =begin
4
+ /***************************************************************************
5
+ * ©2015-2016 Michael Uplawski <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************
22
+ =end
23
+
24
+ require_relative 'logging'
25
+ require_relative 'argparser'
26
+ require_relative 'user_input'
27
+
28
+ =begin
29
+ Shows a text-file line by line
30
+ =end
31
+ class LineByLine
32
+ include Logging
33
+
34
+ def initialize(args)
35
+ init_logger()
36
+ if(args.empty?)
37
+ @log.warn("\n\n\tNo Arguments!\n")
38
+ @log.info("Call with option \"-h\" to see some options\n")
39
+ exit true
40
+ end
41
+ options = ArgParser::parse(args)
42
+
43
+ # file = args[0]
44
+ file = options.file
45
+ advance = options.line
46
+
47
+ @log.debug('file is ' << file.to_s)
48
+ if(file && File::exist?(file) && File::readable?(file))
49
+ f = File.open(file)
50
+ system('clear')
51
+ until f.eof
52
+ c = nil
53
+ begin
54
+ until(advance == 0 || f.eof) do
55
+ f.readline
56
+ advance -= 1
57
+ end
58
+ line = ''
59
+ loop do
60
+ line = f.readline
61
+ if(options.fast )
62
+ print line
63
+ else
64
+ char_by_char line
65
+ end
66
+ last_char = line.strip[-1]
67
+ @log.debug 'last char of |' << line.strip << '| is ' << (last_char ? last_char : 'N I L')
68
+ break unless ('↵' == last_char || '\\' == last_char )
69
+ end
70
+ unless "\n" == line
71
+ c = wait_for_user
72
+ end
73
+ rescue Interrupt
74
+ @log.info("\n\n\tprogram interrupted by user")
75
+ exit true
76
+ end
77
+ # key 'f'
78
+ if(102 == c)
79
+ options.fast = true
80
+ # key 's'
81
+ elsif(115 == c)
82
+ options.fast = false
83
+ # keys ctrl+c, ctrl+d, 'q'
84
+ elsif(4 == c || 3 == c || 113 == c)
85
+ exit true
86
+ end
87
+ end
88
+ else
89
+ @log.error("File %s is unsuitable as input to %s"%[file, $0])
90
+ end
91
+ end
92
+
93
+ private
94
+ def char_by_char(line)
95
+ line.split('').each do |c|
96
+ if ('↵' != c && '\\' != c)
97
+ @log.debug('printing ' << c)
98
+ print c;
99
+ sleep 0.1
100
+ end
101
+ end
102
+ end
103
+ def usage
104
+ usage = %~ Usage: %s [text-file]~ %$0
105
+ print usage
106
+ end
107
+ end
108
+
109
+ if $0 == __FILE__
110
+ LineByLine.new(ARGV)
111
+ end
data/lib/log.conf ADDED
@@ -0,0 +1,55 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2013 - 2015 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+
22
+ A simplified logger configuration. Set the level for each individual logger
23
+ below. Choose a different log-device or log-file if you like. Keep the
24
+ formatting intact. Do not change other sections of this file.
25
+ =end
26
+
27
+ # Do not touch from here ----->
28
+ require 'logger'
29
+
30
+ debug = Logger::DEBUG
31
+ info = Logger::INFO
32
+ error = Logger::ERROR
33
+ fatal = Logger::FATAL
34
+ warn = Logger::WARN
35
+ unknown = Logger::UNKNOWN
36
+ {
37
+ # <---------------- to here !
38
+
39
+ # Enter your settings here, but take into consideration that not all
40
+ # the named classes will really produce readable output. Well, you can
41
+ # always try... Either name just the log-level or make the log-level
42
+ # precede the output-device or output-file like in the examples.
43
+
44
+ # Example: naming a log-file
45
+ #
46
+ # :HtmlBuilder => [info, 'C:\temp\htmlbuilder.log'],
47
+ #
48
+ # :HtmlBuilder => [debug, '/tmp/htmlbuilder.log'],
49
+
50
+ :LineByLine => info,
51
+
52
+ # And ignore the remainder, too.
53
+ }
54
+
55
+ #eof
data/lib/logging.rb ADDED
@@ -0,0 +1,115 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2011-2016 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+ require 'logger'
23
+
24
+ # Creates for each implementing object a member @log and precede its
25
+ # output with the name of the class of the object.
26
+ module Logging
27
+
28
+ @@have_log = false
29
+ @@LOG_CONF = File.dirname(File.absolute_path(__FILE__)) << File::Separator << 'log.conf'
30
+
31
+ def init_logger(target = STDOUT, level = Logger::INFO)
32
+ # allow to override the set log-levels with an
33
+ # external configuration (log.conf).
34
+ log_conf
35
+ # Or use the defaults as set here or elsewhere...
36
+
37
+ @level ||= level
38
+ @target ||= target
39
+
40
+ @log = Logger.new(@target)
41
+ @log.level = @level
42
+
43
+ @log.formatter = proc do |severity, datetime, progname, msg|
44
+ t = Time.now
45
+ "#{self.class.name}: #{severity} #{t.hour}-#{t.min}-#{t.sec}: #{msg}\n"
46
+ end
47
+ if ! @@have_log
48
+ @log.debug self.class.name.dup << ' reading logging-configuration from ' << @@LOG_CONF
49
+ @@have_log = true
50
+ end
51
+
52
+ end
53
+
54
+ def log_target=(target)
55
+ @target = target
56
+ @log = Logger.new(@@target)
57
+ @log.level = @level
58
+ end
59
+ def log_level=(level)
60
+ @level = level
61
+ @log.level = @level
62
+ end
63
+
64
+ private
65
+
66
+ def byte_units(bytes)
67
+ m = bytes / 1000000
68
+ k = (bytes - m) / 1000
69
+ b = bytes - m - k
70
+
71
+ end
72
+
73
+ # Override or set the log-level and target-device, as set in a file 'log.conf'.
74
+ # I do not like the look of this, but it works just the way I want it to.
75
+ # "HEAVANS! Isn't there a standard way to do this in Ruby, for Christ's sake?", you say.
76
+ # Heck, I don't care. <= Read that again, I say.
77
+ def log_conf
78
+ config = level = target = nil
79
+ # puts 'log-config is in ' << @@LOG_CONF
80
+ if(File::exist?(@@LOG_CONF) )
81
+ begin
82
+ conf = File.read(@@LOG_CONF)
83
+ config = instance_eval(conf)
84
+ rescue Exception => ex
85
+ STDERR.puts "WARNING! Cannot evaluate the logger-configuration!" << ' ' << ex.message
86
+ STDERR.puts "Default log-levels apply."
87
+ end
88
+ else
89
+ puts "Default log-levels apply."
90
+ end
91
+
92
+ if(config && config.respond_to?(:to_hash) )
93
+ config.default = nil
94
+ config = config[self.class.name.to_sym]
95
+ if(config )
96
+ if(config.respond_to?(:to_ary) && config.size == 2)
97
+ @level, @target = config
98
+ @target.downcase!
99
+ logdir = File.dirname(@target)
100
+ [:exist?, :directory?, :writable?].each do |m|
101
+ msg = (!File.send(m, logdir) ? ' not ' << m.to_s : nil)
102
+ if(msg)
103
+ STDERR.puts "WARNING! A logfile for '%s' cannot be written to %s (%s)!" %[self.class.name, logdir, msg]
104
+ @target = nil
105
+ end
106
+
107
+ end
108
+ # msg = file_check(logdir, :exist?, :directory?, :writable?)
109
+ else
110
+ @level = config
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
data/lib/user_input.rb ADDED
@@ -0,0 +1,41 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ /***************************************************************************
5
+ * Copyright © 2014, Michael Uplawski <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************/
22
+ =end
23
+
24
+ require 'io/wait'
25
+ require 'io/console'
26
+
27
+ def wait_for_user()
28
+ # @log.debug('wait_for_user() ')
29
+ char = nil
30
+ STDIN.raw do
31
+ STDIN.noecho do
32
+ until (STDIN.ready?)
33
+ sleep(0.1)
34
+ end
35
+
36
+ char = (STDIN.read_nonblock(1).ord rescue nil)
37
+ end
38
+ end
39
+ return char
40
+ end
41
+
data/lib/version.rb ADDED
@@ -0,0 +1,27 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2021-2021 Michael Uplawski <michael.uplawski@uplawski.eu> *
5
+ * *
6
+ * This program is free software; you can redistribute it and/or modify *
7
+ * it under the terms of the GNU General Public License as published by *
8
+ * the Free Software Foundation; either version 3 of the License, or *
9
+ * (at your option) any later version. *
10
+ * *
11
+ * This program is distributed in the hope that it will be useful, *
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
+ * GNU General Public License for more details. *
15
+ * *
16
+ * You should have received a copy of the GNU General Public License *
17
+ * along with this program; if not, write to the *
18
+ * Free Software Foundation, Inc., *
19
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
+ ***************************************************************************/
21
+ =end
22
+ APPNAME = "Line By Line"
23
+ VERSION = 1.0
24
+ YEAR = 2021
25
+ SUMMARY = "version information (argument -v) updated."
26
+ AUTHOR = "Michael Uplawski"
27
+ AMAIL = "<michael.uplawski@uplawski.eu>"
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: line_by_line
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Michael Uplawski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "Display the content of a text-file line by line:\nline_by_line -s [text-file]\t\tcharacter
14
+ by character or\nline_by_line -s [text-file] --fast\t\twhole lines.\n\npush return
15
+ for the next line. Call with parameter --help (-h) for a usage-message"
16
+ email: "<michael.uplawski@uplawski.eu>"
17
+ executables:
18
+ - line_by_line
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/line_by_line
23
+ - doc/html/line_by_line.html
24
+ - doc/man/line_by_line.1.gz
25
+ - doc/rst/line_by_line.rst
26
+ - lib/argparser.rb
27
+ - lib/line_by_line.rb
28
+ - lib/log.conf
29
+ - lib/logging.rb
30
+ - lib/user_input.rb
31
+ - lib/version.rb
32
+ homepage: http://www.rubygems.org/gems/line_by_line
33
+ licenses:
34
+ - GPL-3.0
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.1.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements:
51
+ - ''
52
+ rubygems_version: 3.2.5
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: version information (argument -v) updated.
56
+ test_files: []