viewworkbook 0.1.3 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +126 -0
- data/bin/viewworkbook +12 -10
- data/lib/action.rb +6 -14
- data/lib/basic_logging.rb +178 -0
- data/lib/cell.rb +9 -18
- data/lib/color_output.rb +16 -0
- data/lib/column.rb +9 -17
- data/lib/file_checking.rb +36 -11
- data/lib/menu.rb +7 -23
- data/lib/row.rb +8 -16
- data/lib/scrollable.rb +8 -17
- data/lib/sheetdata.rb +41 -57
- data/lib/sheetinterface.rb +10 -24
- data/lib/translating.rb +6 -12
- data/lib/user_input.rb +4 -11
- data/lib/viewworkbook.rb +20 -31
- data/viewworkbook.gemspec +20 -0
- metadata +19 -38
- data/lib/log.conf +0 -62
- data/lib/logging.rb +0 -195
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ea17c22ed36a2ee8c245622927a8aaa61b9f3b728ad8187d1ba7b12f9ee96ce
|
4
|
+
data.tar.gz: ed2fed97be3c121166774666db444c4f5012e1c669087e22bb45e656c3d7f5dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5a5120bd2585eda4981751ca381250eba81efac51e8238da37fb0c60820c3c466da5af6fc97d8d65a9f249647f64c53c1d18727cef93fa778dc50683ea496c7
|
7
|
+
data.tar.gz: ad2f49b95c35e2d05e3ee5fa1f4954de464286abcefc213ce04c59d910b333ebe66be6e1ddf6cbf518ab0fc5a58a0d6ac2fd25fe1fba35875d130b15b0a31676
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
Viewworkbook
|
2
|
+
========================
|
3
|
+
view spreadsheet files in a terminal window
|
4
|
+
--------------------------
|
5
|
+
|
6
|
+
SYNOPSIS
|
7
|
+
========================
|
8
|
+
viewworkbook \<spreadsheet\>
|
9
|
+
|
10
|
+
DESCRIPTION
|
11
|
+
========================
|
12
|
+
Viewworkbook lets you read spreadsheet-files in text-mode, in a terminal
|
13
|
+
window. It reproduces the tables which are contained in a spreadsheet file and
|
14
|
+
lets you navigate through the sheets. The visible part of a sheet is limited
|
15
|
+
laterally and horizontally by the terminal-size but can be scrolled. You can
|
16
|
+
adapt the width of table-columns, to render the table more readable and
|
17
|
+
finally, if you wish, save tables to a text-file. To the author of the
|
18
|
+
program, the utility serves to take a quick glance at spreadsheets that are
|
19
|
+
received via email, in the Mutt mail-client, which is itself a terminal
|
20
|
+
application.
|
21
|
+
|
22
|
+
The supported spreadsheet formats are those which are handled by the Ruby-gem
|
23
|
+
"**roo**" (February 2017):
|
24
|
+
|
25
|
+
- Microsoft™'s **xls** and **xlsx**,
|
26
|
+
|
27
|
+
- the OpenDocument spreadsheet **ods**
|
28
|
+
|
29
|
+
- and the SoftMaker™ spreadsheet formats **pmd** and **pmdx**.
|
30
|
+
|
31
|
+
Options
|
32
|
+
========================
|
33
|
+
Other than the path to the spreadsheet file, viewworkbook does currently not
|
34
|
+
interpret any command line arguments.
|
35
|
+
|
36
|
+
Menu commands
|
37
|
+
========================
|
38
|
+
A list of commands and their associated hotkeys (in parenthesis) is shown
|
39
|
+
below the current table:
|
40
|
+
|
41
|
+
| | | | | | | | | |
|
42
|
+
|--|--------|--------|--------|--------|--------|--------|--------|------|
|
43
|
+
|11| 12.2 | July | 34000 | 5% | prior | 1957 | true | |
|
44
|
+
|12| 2.33 | July | 1234 | 12.2% | prior | 1966 | true | |
|
45
|
+
|13| 50.0 | August | 334566 | 12% | in | 1966 | false | |
|
46
|
+
| | A| B| C| D| E| F| G| |
|
47
|
+
|
48
|
+
|
49
|
+
**value (v) * save to file (f) * sheet (s) * column (c) * up(i) * down(k) * left(j) * right(l) * quit (q) ***
|
50
|
+
|
51
|
+
When you enter one of the hotkeys, a command can be executed directly (like "q"
|
52
|
+
to terminate the program), a sub-menu may be shown (like with "c" which shall
|
53
|
+
give you control on column properties) or you are confronted with an input
|
54
|
+
invitation (like with "v", where you have to enter a cell-reference). Read on
|
55
|
+
for an explanation of each menu command.
|
56
|
+
|
57
|
+
* **value (v)**
|
58
|
+
display the value from a cell. This is useful, when columns are not wide
|
59
|
+
nough to show complete values. After entering "**v**", you are
|
60
|
+
immediately invited to enter a cell reference. Cells are referenced in
|
61
|
+
the format "Column:Row", e.g. D:12 for the cell in column "D" and row
|
62
|
+
"12".
|
63
|
+
|
64
|
+
* **save to file (f)**
|
65
|
+
Save the current or all tables to a text file. The command does initially
|
66
|
+
show two alternative sub-commands:
|
67
|
+
|
68
|
+
* **Current sheet (c) * all sheets (a)**
|
69
|
+
Independently of your choice, in the next step you will have to enter the
|
70
|
+
path to the output file. You will be warned, if the file already exists
|
71
|
+
and may choose to either overwrite the existing file or name a different
|
72
|
+
one.
|
73
|
+
|
74
|
+
* **sheet (s)**
|
75
|
+
Navigate to a different sheet in the current workbook. You may choose
|
76
|
+
between a sheet-number and the name of a sheet. If you want to indicate
|
77
|
+
the next sheet **by name**, the list of all available names is first
|
78
|
+
shown. You just type right away the one that you want.
|
79
|
+
|
80
|
+
* **column (c)**
|
81
|
+
Alter the properties of the table-columns. At the time of this writing
|
82
|
+
(February 2017) the only property that can be changed, is the width of all
|
83
|
+
columns. When you enter "**c**" the subcommand column width (w) is shown.
|
84
|
+
After entering "**w**" you can enter the desired width in characters.
|
85
|
+
|
86
|
+
* **Arrows(i, j, k, l)**
|
87
|
+
Navigate in a sheet that is too big to be displayed entirely at once.
|
88
|
+
These hotkeys correspond to the default navigation keys in the vi editor.
|
89
|
+
|
90
|
+
* **quit (q)**
|
91
|
+
Enter "**q**" to quit the program at any moment except when an input
|
92
|
+
invitation is shown.
|
93
|
+
|
94
|
+
Hidden (menu-)commands
|
95
|
+
------------------------
|
96
|
+
There is currently only one such command available:
|
97
|
+
The **Escape-key** will interrupt an unfinished action and refresh the display.
|
98
|
+
|
99
|
+
Other Information
|
100
|
+
==================
|
101
|
+
|
102
|
+
Development and source code
|
103
|
+
---------------------------
|
104
|
+
Viewworkbook has been written in Ruby. As Ruby is an interpreted programming
|
105
|
+
language, the executable file and all those that it may refer to at one
|
106
|
+
point in time, are themselves the source-files of the current
|
107
|
+
program-version. You can open them in any text-editor to scrutinize the
|
108
|
+
source-code. If you have received the program as a Ruby-gem, you can also
|
109
|
+
decompress a copy of the gem-file with **tar -x**, then **tar -xzf**.
|
110
|
+
|
111
|
+
Bugs
|
112
|
+
----
|
113
|
+
Negative values are not always displayed, when very long (like 15 ciphers).
|
114
|
+
Enlarging the column-width further does not have an effect.
|
115
|
+
|
116
|
+
License
|
117
|
+
-------
|
118
|
+
Viewworkbook is distributed under the conditions of the WTFPL-2 or later
|
119
|
+
version; see https://wtfpl2.com for details.
|
120
|
+
|
121
|
+
Author
|
122
|
+
------
|
123
|
+
Viewworkbook has been developed by Michael Uplawski
|
124
|
+
<michael.uplawski@uplawski.eu>
|
125
|
+
|
126
|
+
*Ω*
|
data/bin/viewworkbook
CHANGED
@@ -2,26 +2,28 @@
|
|
2
2
|
#encoding: UTF-8
|
3
3
|
=begin
|
4
4
|
/***************************************************************************
|
5
|
-
* ©
|
5
|
+
* ©2016-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
6
|
* *
|
7
7
|
* This program is free software; you can redistribute it and/or modify *
|
8
|
-
* it under the terms of the
|
9
|
-
*
|
10
|
-
* (at your option) any later version. *
|
8
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
11
10
|
* *
|
12
11
|
* This program is distributed in the hope that it will be useful, *
|
13
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
* GNU General Public License for more details. *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
16
14
|
* *
|
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
15
|
***************************************************************************/
|
22
16
|
=end
|
23
17
|
|
24
18
|
require_relative "../lib/viewworkbook.rb"
|
19
|
+
require_relative "../lib/basic_logging.rb"
|
20
|
+
|
21
|
+
BasicLogging::set_target STDOUT
|
22
|
+
BasicLogging::set_level BasicLogging::INFO
|
23
|
+
|
24
|
+
# comment in for verbose output
|
25
|
+
# BasicLogging::set_target "/tmp/viewworkbook.log"
|
26
|
+
# BasicLogging::set_level BasicLogging::DEBUG
|
25
27
|
|
26
28
|
if(ARGV.compact.empty?)
|
27
29
|
puts purple("\n\tYou must name a valid spreadsheet file! Aborting\n")
|
data/lib/action.rb
CHANGED
@@ -1,32 +1,25 @@
|
|
1
1
|
#encoding: UTF-8
|
2
|
-
|
3
2
|
=begin
|
4
3
|
/***************************************************************************
|
5
|
-
*
|
4
|
+
* ©2016-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
5
|
* *
|
7
6
|
* This program is free software; you can redistribute it and/or modify *
|
8
|
-
* it under the terms of the
|
9
|
-
*
|
10
|
-
* (at your option) any later version. *
|
7
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
8
|
+
* http://www.wtfpl.net/about/ *
|
11
9
|
* *
|
12
10
|
* This program is distributed in the hope that it will be useful, *
|
13
11
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
* GNU General Public License for more details. *
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
16
13
|
* *
|
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
14
|
***************************************************************************/
|
22
15
|
=end
|
23
16
|
|
24
|
-
require_relative '
|
17
|
+
require_relative 'basic_logging'
|
25
18
|
|
26
19
|
# An Action is executed on a user's request.
|
27
20
|
# It has a name, an associated closure and hotkey.
|
28
21
|
class Action
|
29
|
-
include
|
22
|
+
include BasicLogging
|
30
23
|
|
31
24
|
class ActionError < StandardError
|
32
25
|
end
|
@@ -39,7 +32,6 @@ class Action
|
|
39
32
|
|
40
33
|
|
41
34
|
def initialize(options = {}, &b)
|
42
|
-
init_logger(STDOUT, Logger::INFO)
|
43
35
|
|
44
36
|
@name = options[:name]
|
45
37
|
@key = options[:key]
|
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
#encoding: UTF-8
|
3
|
+
=begin
|
4
|
+
/***************************************************************************
|
5
|
+
* ©2023-2024, 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 WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
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. *
|
14
|
+
* *
|
15
|
+
***************************************************************************/
|
16
|
+
=end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Simplified logging.
|
20
|
+
# See example code at the bottom of this file.
|
21
|
+
# Execute this file to see the output.
|
22
|
+
#
|
23
|
+
|
24
|
+
#require 'time'
|
25
|
+
|
26
|
+
module BasicLogging
|
27
|
+
|
28
|
+
DEBUG = 0
|
29
|
+
INFO = 1
|
30
|
+
WARN = 2
|
31
|
+
ERROR = 3
|
32
|
+
FATAL = 4
|
33
|
+
UNKNOWN = nil
|
34
|
+
|
35
|
+
# this is mainly for the translation of method calls into log levels
|
36
|
+
Levels = {:debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR,
|
37
|
+
:fatal => FATAL, :unknown => UNKNOWN}
|
38
|
+
|
39
|
+
@@log_level = UNKNOWN
|
40
|
+
@@target = STDOUT
|
41
|
+
@@muted = []
|
42
|
+
|
43
|
+
# do not log, if caller is obj (class or instance)
|
44
|
+
def self.mute(obj)
|
45
|
+
name = obj.class == Class ? obj.name.dup : obj.class.name
|
46
|
+
@@muted << name
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.is_muted?(obj)
|
50
|
+
name = obj.class == Class ? obj.name.dup : obj.class.name
|
51
|
+
@@muted.include?(name)
|
52
|
+
end
|
53
|
+
|
54
|
+
# set the log level
|
55
|
+
def self::set_level(lv)
|
56
|
+
if lv.respond_to?(:to_str)
|
57
|
+
lv = Levels[lv.to_sym]
|
58
|
+
end
|
59
|
+
if(!lv || (lv.respond_to?(:to_int) && lv >= DEBUG && lv <= FATAL) )
|
60
|
+
@@log_level = lv
|
61
|
+
else
|
62
|
+
STDERR.puts __FILE__.dup << ": ERROR : invalid log level \"" << lv.to_s << "\""
|
63
|
+
STDERR.puts "Keepinng old log level " << Levels.keys.detect {| k| Levels[k] == @@log_level}.to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_level(lv)
|
68
|
+
BasicLogging::set_level(lv)
|
69
|
+
end
|
70
|
+
|
71
|
+
# set the log target
|
72
|
+
def self::set_target(tg)
|
73
|
+
if tg.respond_to?(:to_io)
|
74
|
+
@@target = tg
|
75
|
+
elsif(!File::exist?(tg) || ( File.file?(tg) && File.writable?(tg) ) )
|
76
|
+
@@target = File.open(tg, 'w+')
|
77
|
+
else
|
78
|
+
STDERR.puts __FILE__.dup << ': ERROR : target ' << tg << ' cannot be set'
|
79
|
+
STDERR.puts "Keeping old target " << @@target.inspect
|
80
|
+
return
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_target(tg)
|
85
|
+
BasicLogging::set_target(tg)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Output of log messages, depending on the log level set for the calling class
|
89
|
+
# and the name of the alias method which is actually called.
|
90
|
+
def log(message)
|
91
|
+
if !BasicLogging.is_muted?(self)
|
92
|
+
# how has this method been called?
|
93
|
+
mlevel = __callee__
|
94
|
+
if Levels.has_key?(mlevel) && Levels[mlevel] <= FATAL
|
95
|
+
# output only for levels equal or above the value that corresponds to
|
96
|
+
# the calling alias.
|
97
|
+
format_log( message, mlevel) if @@log_level && Levels[mlevel] >= @@log_level
|
98
|
+
else
|
99
|
+
STDERR.puts __FILE__.dup << ": ERROR : invalid log level \"" << mlevel.to_s << "\""
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
alias :debug :log
|
105
|
+
alias :info :log
|
106
|
+
alias :warn :log
|
107
|
+
alias :error :log
|
108
|
+
alias :fatal :log
|
109
|
+
|
110
|
+
attr_reader :target, :log_level
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
# 1 format_log for all loggers.
|
115
|
+
def format_log(message, mlevel)
|
116
|
+
# indicate if a registered class or the registered object of a class is calling.
|
117
|
+
name = self.class == Class ? self.name.dup << ' [class]' : self.class.name
|
118
|
+
@@target.puts '' << name << ' ' << mlevel.to_s << ' ' << Time.now.strftime("%H:%M:%S:%6N") << ': ' << message
|
119
|
+
end
|
120
|
+
end
|
121
|
+
#---------test: execute file----------
|
122
|
+
if $0 == __FILE__
|
123
|
+
Array.extend(BasicLogging)
|
124
|
+
Array.set_level(BasicLogging::INFO)
|
125
|
+
Array.info('TEST')
|
126
|
+
ar = Array.new
|
127
|
+
ar.extend(BasicLogging)
|
128
|
+
# --- no output :
|
129
|
+
l = __LINE__
|
130
|
+
ar.debug(l.next.to_s << ': debug-test 0')
|
131
|
+
# output
|
132
|
+
ar.set_level(BasicLogging::DEBUG)
|
133
|
+
l = __LINE__
|
134
|
+
ar.debug(l.next.to_s << ': debug-test 1')
|
135
|
+
|
136
|
+
obj = Object.new
|
137
|
+
obj.extend(BasicLogging)
|
138
|
+
obj.set_level(BasicLogging::DEBUG)
|
139
|
+
puts "--------debug-----------"
|
140
|
+
obj.debug('debug')
|
141
|
+
obj.info('info')
|
142
|
+
obj.warn('warn')
|
143
|
+
obj.error('error')
|
144
|
+
obj.fatal('fatal')
|
145
|
+
puts "--------info-----------"
|
146
|
+
obj.set_level("info")
|
147
|
+
obj.debug('debug')
|
148
|
+
obj.info('info')
|
149
|
+
obj.warn('warn')
|
150
|
+
obj.error('error')
|
151
|
+
obj.fatal('fatal')
|
152
|
+
puts "--------fatal-----------"
|
153
|
+
obj.set_level("fatal")
|
154
|
+
obj.debug('debug')
|
155
|
+
obj.info('info')
|
156
|
+
obj.warn('warn')
|
157
|
+
obj.error('error')
|
158
|
+
obj.fatal('fatal')
|
159
|
+
puts "--------UNKNOWN-----------"
|
160
|
+
obj.set_level(nil)
|
161
|
+
obj.debug('debug')
|
162
|
+
obj.info('info')
|
163
|
+
obj.warn('warn')
|
164
|
+
obj.error('error')
|
165
|
+
obj.fatal('fatal')
|
166
|
+
puts " ------ Output into file ----"
|
167
|
+
obj.set_target "/tmp/test_log.log"
|
168
|
+
puts " ------ INFO -----------"
|
169
|
+
obj.set_level BasicLogging::INFO
|
170
|
+
obj.info('info output')
|
171
|
+
|
172
|
+
obj.info('info output 2')
|
173
|
+
puts "---------- invalid -------"
|
174
|
+
obj.set_target "/dev/sr0"
|
175
|
+
obj.set_level "power"
|
176
|
+
end
|
177
|
+
|
178
|
+
# EOF
|
data/lib/cell.rb
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
#encoding: UTF-8
|
2
|
-
|
3
2
|
=begin
|
4
3
|
/***************************************************************************
|
5
|
-
*
|
4
|
+
* ©2016-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
5
|
* *
|
7
6
|
* This program is free software; you can redistribute it and/or modify *
|
8
|
-
* it under the terms of the
|
9
|
-
*
|
10
|
-
* (at your option) any later version. *
|
7
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
8
|
+
* http://www.wtfpl.net/about/ *
|
11
9
|
* *
|
12
10
|
* This program is distributed in the hope that it will be useful, *
|
13
11
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
* GNU General Public License for more details. *
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
16
13
|
* *
|
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
14
|
***************************************************************************/
|
22
15
|
=end
|
23
|
-
|
24
|
-
require_relative 'logging'
|
16
|
+
require_relative 'basic_logging'
|
25
17
|
require_relative 'row'
|
26
18
|
require_relative 'column'
|
27
19
|
|
@@ -32,19 +24,18 @@ class Cell
|
|
32
24
|
@@DEF_TYPE=Integer
|
33
25
|
@@split_pattern = nil
|
34
26
|
|
35
|
-
|
36
|
-
@@log = self.init_logger
|
27
|
+
include BasicLogging
|
37
28
|
|
38
29
|
def initialize(row = nil, col = nil, value = nil)
|
39
|
-
@log = @@log
|
40
30
|
@row = row if row
|
41
31
|
@col = col if col
|
32
|
+
@debinfo = '(' << @col.number.to_s << ':' << @row.number.to_s << ') '
|
42
33
|
@type_class = @@DEF_TYPE
|
43
34
|
@value = value
|
44
35
|
split_value
|
45
36
|
set_limits
|
46
37
|
@row.resize
|
47
|
-
|
38
|
+
debug(@debinfo << "cell.initialize, lines is #{@lines}, value is #{value}, ideal_width is #{@ideal_width}")
|
48
39
|
end
|
49
40
|
|
50
41
|
def to_cell()
|
@@ -70,7 +61,7 @@ class Cell
|
|
70
61
|
@@split_pattern = nil
|
71
62
|
@value = value
|
72
63
|
split_value
|
73
|
-
|
64
|
+
debug(@debinfo << 'after split_value, lines is ' << @lines.to_s)
|
74
65
|
end
|
75
66
|
|
76
67
|
def col
|
data/lib/color_output.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
#encoding 'UTF-8'
|
2
2
|
|
3
|
+
=begin
|
4
|
+
/***************************************************************************
|
5
|
+
* ©2016-2024, 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 WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
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. *
|
14
|
+
* *
|
15
|
+
***************************************************************************/
|
16
|
+
=end
|
17
|
+
|
18
|
+
|
3
19
|
# functions to apply colors to terminal output
|
4
20
|
|
5
21
|
COLORS = {:default => 9, :black => 0, :red => 1, :green => 2, :yellow => 3, :blue => 4, :purple => 5, :cyan => 6, :white => 7 }
|
data/lib/column.rb
CHANGED
@@ -2,38 +2,30 @@
|
|
2
2
|
|
3
3
|
=begin
|
4
4
|
/***************************************************************************
|
5
|
-
*
|
5
|
+
* ©2016-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
6
6
|
* *
|
7
7
|
* This program is free software; you can redistribute it and/or modify *
|
8
|
-
* it under the terms of the
|
9
|
-
*
|
10
|
-
* (at your option) any later version. *
|
8
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
9
|
+
* http://www.wtfpl.net/about/ *
|
11
10
|
* *
|
12
11
|
* This program is distributed in the hope that it will be useful, *
|
13
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
15
|
-
* GNU General Public License for more details. *
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
16
14
|
* *
|
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
15
|
***************************************************************************/
|
22
16
|
=end
|
23
17
|
|
24
18
|
|
25
|
-
require_relative '
|
19
|
+
require_relative 'basic_logging'
|
26
20
|
|
27
21
|
# Objects of this class represent columns in a spreadsheet table
|
28
22
|
|
29
23
|
class Column
|
30
|
-
|
31
|
-
@@log = self.init_logger
|
24
|
+
include BasicLogging
|
32
25
|
@@DEF_WIDTH=15
|
33
26
|
@@col_width=@@DEF_WIDTH
|
34
27
|
@@columns = Array.new
|
35
28
|
def initialize(number = nil)
|
36
|
-
@log = @@log
|
37
29
|
@number = number
|
38
30
|
@cells = Array.new
|
39
31
|
@width = @@col_width
|
@@ -48,7 +40,7 @@ class Column
|
|
48
40
|
n_cell = Cell.new( cell, @number)
|
49
41
|
else
|
50
42
|
msg = 'For a new cell, a row-number must be specified'
|
51
|
-
|
43
|
+
error(yellow(msg))
|
52
44
|
raise StandardError(msg)
|
53
45
|
end
|
54
46
|
@cells.insert(n_cell.row, n_cell)
|
@@ -68,14 +60,14 @@ class Column
|
|
68
60
|
|
69
61
|
def self::col_width=(w)
|
70
62
|
@@col_width = w
|
71
|
-
@
|
63
|
+
debug(@number.to_s << ' ' <<"self::col_width=(#{w}), calling resize")
|
72
64
|
|
73
65
|
@@columns.each {|col| col.resize(w)}
|
74
66
|
end
|
75
67
|
|
76
68
|
def resize(width)
|
77
69
|
@width = width
|
78
|
-
@
|
70
|
+
debug(@number.to_s << ' ' <<'calling resize')
|
79
71
|
@cells.each {|cell| cell.resize}
|
80
72
|
end
|
81
73
|
|
data/lib/file_checking.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
=begin
|
3
3
|
/***************************************************************************
|
4
|
-
* ©2011-
|
4
|
+
* ©2011-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
5
5
|
* *
|
6
6
|
* This program is free software; you can redistribute it and/or modify *
|
7
|
-
* it under the terms of the
|
8
|
-
*
|
9
|
-
* (at your option) any later version. *
|
7
|
+
* it under the terms of the WTFPL 2.0 or later, see *
|
8
|
+
* http://www.wtfpl.net/about/ *
|
10
9
|
* *
|
11
10
|
* This program is distributed in the hope that it will be useful, *
|
12
11
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
-
* GNU General Public License for more details. *
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
15
13
|
* *
|
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
14
|
***************************************************************************/
|
21
15
|
=end
|
22
16
|
|
17
|
+
require 'filemagic'
|
18
|
+
|
23
19
|
=begin
|
24
20
|
A module to facilitate frequently occuring checks on
|
25
21
|
file-system objects
|
@@ -39,6 +35,10 @@ module File_Checking
|
|
39
35
|
:directory => "is not a directory!",
|
40
36
|
:file? => "is not a file!",
|
41
37
|
:file => "is not a file!",
|
38
|
+
:type => "is not of the sought file-type (not '%s', but '%s')!",
|
39
|
+
:type? => "is not of the sought file-type (not '%s', but '%s')!",
|
40
|
+
:mime => "does not have the sought mime-type (not '%s', but '%s')!",
|
41
|
+
:mime? => "does not have the sought mime-type (not '%s', but '%s')!",
|
42
42
|
}
|
43
43
|
|
44
44
|
# Checks if the file with the name from the first
|
@@ -76,12 +76,37 @@ module File_Checking
|
|
76
76
|
end
|
77
77
|
msg
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
|
+
def self.mime_check(file, mime_type)
|
81
|
+
fm = FileMagic.mime
|
82
|
+
fd = fm.fd(File.new(file) ).split(';')[0]
|
83
|
+
if fd != mime_type.strip
|
84
|
+
return file.dup << ' ' << (@@text_messages[:mime] %[mime_type, fd])
|
85
|
+
end
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.magic_check(file, magic)
|
90
|
+
fm = FileMagic.fm
|
91
|
+
fd = fm.fd(File.new(file) ).split(';')[0]
|
92
|
+
if fd != magic.strip
|
93
|
+
return file.dup << ' ' << (@@text_messages[:type] %[magic, fd])
|
94
|
+
end
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
end # module
|
80
99
|
|
81
100
|
=begin
|
82
101
|
# example
|
83
102
|
|
84
103
|
include File_Checking
|
85
104
|
msg = file_check('some_file.txt', [:exist?, :readable?, 'writable'])
|
105
|
+
# same as
|
106
|
+
# msg = file_check('some_file.txt', [:exist, :readable, 'writable?'])
|
107
|
+
|
108
|
+
msg ||= magic_check('some_file.txt', [:type?], 'OpenDocument Text'
|
109
|
+
msg ||= mime_check('some_file.txt', [:mime?], 'application/vnd.oasis.opendocument.text'
|
86
110
|
puts msg if msg
|
87
111
|
=end
|
112
|
+
# E O F
|