viewworkbook 0.3 → 1.0

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.
Binary file
@@ -131,4 +131,15 @@ Other Information
131
131
  Viewworkbook has been developed by Michael Uplawski
132
132
  <michael.uplawski@uplawski.eu>
133
133
 
134
+ This document
135
+ -------------
136
+ .. _CC By-ND 4.0: https://creativecommons.org/licenses/by-nd/4.0/
137
+ .. |date| date::
138
+
139
+ ©Michael Uplawski <michael.uplawski@uplawski.eu>
140
+
141
+ License: `CC BY-ND 4.0`_
142
+
143
+ Date: |date|
144
+
134
145
  **Ω**
data/lib/column.rb CHANGED
@@ -64,8 +64,6 @@ class Column
64
64
  # set the column width to w
65
65
  def self::col_width=(w)
66
66
  @@col_width = w
67
- debug(@number.to_s << ' ' <<"self::col_width=(#{w}), calling resize")
68
-
69
67
  @@columns.each {|col| col.resize(w)}
70
68
  end
71
69
 
@@ -53,6 +53,7 @@ class SheetInterface
53
53
  end
54
54
 
55
55
  def initialize(wb, num)
56
+ # set_level('debug')
56
57
  @workbook = wb.sheet(num)
57
58
  @menu = nil
58
59
  @status = Status.new
@@ -60,6 +61,16 @@ class SheetInterface
60
61
  end
61
62
 
62
63
  private
64
+ =begin
65
+ Interrupts the screen refresh to display a debug message,
66
+ if the log level is BasicLogging::DEBUG.
67
+ =end
68
+ def pause_debug(text)
69
+ if @@log_level == BasicLogging::DEBUG
70
+ debug(text)
71
+ wait_for_user
72
+ end
73
+ end
63
74
  =begin
64
75
  returns [width, height] in columns and lines of the current
65
76
  terminal-window.
@@ -190,8 +201,8 @@ class SheetInterface
190
201
  end
191
202
 
192
203
  if sn && !sn.to_s.empty?
193
- debug('calling workbook.sheet with ' << sn.to_s)
194
- debug('@workbook is of type ' << @workbook.class.name)
204
+ pause_debug('calling workbook.sheet with ' << sn.to_s)
205
+ pause_debug('@workbook is of type ' << @workbook.class.name)
195
206
  set_sheet(sn)
196
207
  end
197
208
  construct
@@ -208,10 +219,24 @@ class SheetInterface
208
219
  save_Menu.add_action(Action.new(:name => 'current sheet', :key => 'c') do
209
220
  file = new_file()
210
221
  if(file)
211
- File::open(file, 'w+') {|out| draw(out) }
212
- @status.message = green('... done')
222
+ num = 0
223
+ begin
224
+ content = draw(false)
225
+ pause_debug(__LINE__.to_s << 'have content – writing to ' << file)
226
+ num = File::write(file, content )
227
+ pause_debug(__LINE__.to_s << 'wrote ' << num.to_s << ' bytes')
228
+ rescue Exception => ex
229
+ @status.message = red( 'cannot write to ' << file << ': ' << ex.message)
230
+ # raise ex
231
+ end
232
+ if num > 0
233
+ @status.message = green('... done (' << num.to_s << ' bytes written)')
234
+ else
235
+ @status.message = red('Cannot write to ' << file << ' (' << num.to_s << ' bytes written)')
236
+ end
237
+ construct
213
238
  end
214
- construct
239
+ # end action - close parenthesis
215
240
  end)
216
241
 
217
242
  save_Menu.add_action(Action.new(:name => 'all sheets', :key => 'a') do
@@ -223,12 +248,15 @@ class SheetInterface
223
248
  begin
224
249
  File::open(file, 'w+') do |out|
225
250
  @workbook.sheets.each do |s|
226
- debug('writing sheet ' << s)
227
251
  set_sheet(s)
228
252
  construct(false)
229
- draw(out)
253
+ debug(__LINE__.to_s << 'writing sheet ' << s.to_s)
254
+ wait_for_user if @@log_level == BasicLogging::DEBUG
255
+ out.write draw(false)
230
256
  end
231
257
  end
258
+ rescue Errno => ex
259
+ @status.message = red(__LINE__.dup << 'cannot write to ' << file << ':' << ex.message )
232
260
  rescue Interrupt
233
261
  puts bold(red("Interrupted by user. Bye!"))
234
262
  exit true
@@ -237,6 +265,7 @@ class SheetInterface
237
265
  end
238
266
  set_sheet(current_sheet)
239
267
  construct
268
+ # end action - close parenthesis
240
269
  end)
241
270
 
242
271
  col_Menu = Menu.new(:name=>'column', :key => 'c')
@@ -255,7 +284,7 @@ class SheetInterface
255
284
  if(@rows[row] && @columns[col])
256
285
  cell = @rows[row].cells.detect {|c| c.col == col}
257
286
  if(cell)
258
- @status.message = "#{cell_coord[0].upcase}:#{cell_coord[1]} is \"" << cell.value.to_s << "\" (%d)" %cell.value.to_s.length
287
+ @status.message = yellow("value in #{cell_coord[0].upcase}:#{cell_coord[1]} is \"" << cell.value.to_s << "\" (%d)" %cell.value.to_s.length)
259
288
  else
260
289
  @status.message = red('invalid cell')
261
290
  end
@@ -280,10 +309,12 @@ class SheetInterface
280
309
  end
281
310
  # This is hard to describe.
282
311
  # The function basically draws a table on screen.
283
- def draw(out = STDOUT)
312
+ def draw(on_screen = true)
284
313
  if(@rows && !@rows.empty?)
285
314
  # Welcome to hell.
286
- on_screen = STDOUT == out
315
+ debug 'drawing on screen' if on_screen
316
+ wait_for_user if on_screen && @@log_level == BasicLogging::DEBUG
317
+
287
318
  col_w = Column::col_width
288
319
  num_c = @rows[0].cells.length()
289
320
  num_r = @rows.length
@@ -294,46 +325,33 @@ class SheetInterface
294
325
  #-----
295
326
 
296
327
  table_view << @workbook.default_sheet << "\n"
297
- #out.puts @workbook.default_sheet
298
328
  table_view << ('┌' << '─' * num_r.to_s.length << '┬' << (('─' * col_w) << '┬' ) * (num_c -1) ) << (('─' * col_w) << '┐' ) << "\n"
299
- # out.puts ('┌' << '─' * num_r.to_s.length << '┬' << (('─' * col_w) << '┬' ) * (num_c -1) ) << (('─' * col_w) << '┐' )
300
329
  lh = 0
301
330
  @rows.each do |row|
302
331
 
303
332
  if(row == @rows.first)
304
333
  ch = 'A'
305
334
  table_view << "│%#{num_r.to_s.length}s" %" "
306
- #out.print "│%#{num_r.to_s.length}s" %" "
307
335
  table_view << '│'
308
- # out.print '│'
309
336
  row.each do |c|
310
337
  head = "%#{col_w}s" %ch
311
338
  head = bold(head) if(on_screen)
312
- # out.print(head << "|")
313
339
  table_view << (head << "│")
314
340
  ch = ch.next
315
341
  end
316
- # out.puts
317
342
  table_view << "\n"
318
343
  hline = ('├' << ('─' * (num_r.to_s.length) ) <<'┼' << (('─' * col_w) << '┼' ) * (num_c - 1) ) << (('─' * col_w) << '┤')if !hline
319
344
  table_view << hline << "\n"
320
- # out.puts hline
321
345
  end
322
346
  lh += 1
323
347
  table_view << "│"
324
- # out.print "│"
325
348
  line_head = "%#{num_r.to_s.length}s" %lh.to_s
326
349
  line_head = bold(line_head) if on_screen
327
350
  table_view << line_head
328
- # out.print line_head
329
-
330
- # out.print "│" << bold("%#{num_r.to_s.length}s" %line_head)
331
351
 
332
352
  row.height.times do |li|
333
353
  table_view << "│%#{num_r.to_s.length}s" %" " if li > 0
334
- # out.print "│%#{num_r.to_s.length}s" %" " if li > 0
335
354
  table_view << '│'
336
- # out.print '│'
337
355
  row.each do |cell|
338
356
  line = cell.line(li)
339
357
  content = "%#{col_w}s│" %line
@@ -341,15 +359,12 @@ class SheetInterface
341
359
  content = red(content)
342
360
  end
343
361
  table_view << content
344
- # out.print content
345
362
  end
346
363
  table_view << "\n"
347
- # out.puts
348
364
  end
349
365
  hlline = ('│' << (('─' * col_w) << '│' ) * num_c ) if !hline
350
366
 
351
367
  table_view << hline << "\n"
352
- # out.puts hline
353
368
 
354
369
  # Some of the following code may go to a function as it repeats the
355
370
  # procedure from the beginning of the table. I am currently unwilling to
@@ -359,26 +374,20 @@ class SheetInterface
359
374
  if(row == @rows.last)
360
375
  ch = 'A'
361
376
  table_view << "│%#{num_r.to_s.length}s" %" "
362
- # out.print "│%#{num_r.to_s.length}s" %" "
363
377
  table_view << '│'
364
- # out.print '│'
365
378
  row.each do |c|
366
379
  head = "%#{col_w}s" %ch
367
380
  head = bold(head) if on_screen
368
381
  table_view << ( head << '│')
369
- # out.print( head << '│')
370
382
  ch = ch.next
371
383
  end
372
384
  table_view << "\n"
373
- # out.puts
374
385
  hline = ('└' << ('─' * (num_r.to_s.length) ) << '┴' << (('─' * col_w) << '┴' ) * (num_c - 1) ) << (('─' * col_w) << '┘' )
375
386
 
376
387
  table_view << hline << "\n"
377
- # out.puts hline
378
388
  end
379
389
 
380
390
  end
381
-
382
391
  return table_view
383
392
  else
384
393
  return nil
data/lib/user_input.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #encoding: UTF-8
2
2
  =begin
3
3
  /***************************************************************************
4
- * ©2014-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
4
+ * ©2014-2026, Michael Uplawski <michael.uplawski@uplawski.eu> *
5
5
  * *
6
6
  * This program is free software; you can redistribute it and/or modify *
7
7
  * it under the terms of the WTFPL 2.0 or later, see *
@@ -20,17 +20,19 @@ require 'io/console'
20
20
  # unblocking read from STDIN
21
21
 
22
22
  def wait_for_user()
23
- char = nil
23
+ char = nil
24
24
  # char = STDIN.raw(&:getc)
25
- STDIN.raw do
26
- STDIN.noecho do
27
- until (STDIN.ready?)
28
- sleep(0.1)
29
- end
25
+ STDIN.raw do
26
+ STDIN.noecho do
27
+ #modified for Ruby 4.x
28
+ # until (STDIN.ready?)
29
+ until IO.select([STDIN], nil, nil, 0)
30
+ sleep(0.1)
31
+ end
30
32
 
31
- char = (STDIN.read_nonblock(1).ord rescue nil)
32
- end
33
- end
33
+ char = (STDIN.read_nonblock(1).ord rescue nil)
34
+ end
35
+ end
34
36
  return char
35
37
  end
36
38
 
data/viewworkbook.gemspec CHANGED
@@ -1,9 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'viewworkbook'
3
- s.version = '0.3'
4
- s.date = '2025-08-29'
5
- s.summary = "Documentation text improved, "
6
- s.summary << "List of dependencies completed."
3
+ s.version = '1.0'
4
+ s.date = '2026-04-10'
5
+ s.summary = "Content can – again – be writtenn to a text-file, "
6
+ s.summary << "Ruby 4.0 compatibility, "
7
+ s.summary << "Minor Bug-fix."
7
8
  s.description = "View spreadsheet files in a text-console."
8
9
  s.authors = ["Michael Uplawski"]
9
10
  s.email = 'michael.uplawski@uplawski.eu'
@@ -12,12 +13,12 @@ Gem::Specification.new do |s|
12
13
  %w~busy_function_test.rb busy_indicator.rb~.collect{|f| 'lib/busy_indicator/' << f} + ["README.md", "viewworkbook.gemspec"]
13
14
  s.homepage = 'http://rubygems.org/gems/viewworkbook'
14
15
  s.requirements = 'roo, roo-xls, ruby-filemagic'
15
- s.add_runtime_dependency 'roo', '~> 2.4', '>= 2.4.0'
16
+ s.add_runtime_dependency 'roo', '~> 2.10', '>= 2.10.1'
16
17
  s.add_runtime_dependency 'roo-xls', '~> 1.2', '>= 1.2.0'
17
- s.add_runtime_dependency 'ruby-filemagic', '~> 0.3', '>= 0.3.2'
18
+ s.add_runtime_dependency 'ruby-filemagic', '~> 0.7', '>= 0.7.3'
18
19
  s.executables = 'viewworkbook'
19
20
  s.license = 'Nonstandard'
20
- s.required_ruby_version = '>= 3.0'
21
+ s.required_ruby_version = '>= 4.0'
21
22
  s.metadata = {
22
23
  "homepage_uri" => 'https://www.uplawski.eu/software/viewworkbook/',
23
24
  "documentation_uri" => 'https://www.uplawski.eu/software/viewworkbook/viewworkbook.html'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viewworkbook
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Uplawski
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-29 00:00:00.000000000 Z
10
+ date: 2026-04-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: roo
@@ -15,20 +15,20 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.4'
18
+ version: '2.10'
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 2.4.0
21
+ version: 2.10.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '2.4'
28
+ version: '2.10'
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 2.4.0
31
+ version: 2.10.1
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: roo-xls
34
34
  requirement: !ruby/object:Gem::Requirement
@@ -55,20 +55,20 @@ dependencies:
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: '0.3'
58
+ version: '0.7'
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.2
61
+ version: 0.7.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.3'
68
+ version: '0.7'
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: 0.3.2
71
+ version: 0.7.3
72
72
  description: View spreadsheet files in a text-console.
73
73
  email: michael.uplawski@uplawski.eu
74
74
  executables:
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '3.0'
116
+ version: '4.0'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
@@ -121,7 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements:
123
123
  - roo, roo-xls, ruby-filemagic
124
- rubygems_version: 3.6.7
124
+ rubygems_version: 4.0.10
125
125
  specification_version: 4
126
- summary: Documentation text improved,List of dependencies completed.
126
+ summary: Content can again be writtenn to a text-file,Ruby 4.0 compatibility,
127
+ Minor Bug-fix.
127
128
  test_files: []