Text-mode spreadsheet reader

Good morning,

I feel dumb. Maybe you can help change that but let me first try to
exclude misunderstandings.
-) If a text-mode spreadsheet reader exists already, I do not care to
know and will continue my own development anyway.
-) The program in development will not use libraries like ncruses
(conio) or similar and all the user-interface will be pure text.
-) I have already created such a text-mode spreadsheet reader for
OpenDocument spreadsheets, but at the time was bound to one type of file
with well-defined formats, that my Interface could blindly rely on.
-) The interface will provide functions to let a user set the width of
table-columns, in order to show entire cell-contents, where it has to be
clipped otherwise.

The problem that I am currently facing is quickly explained and is not
at all specific to spreadsheets or ruby. And I feel, that it had been
addressed many times by programmers… Alas, I appear unable to find my
own solution.

Question: How would YOU deal with multi-line cell-content ?

Example : puts “%10s |” %content.to_s

TILT.


Solidarité avec les ZADistes de Testet!

Michael U. wrote in post #1161519:

Good morning,

The problem that I am currently facing is quickly explained and is not
at all specific to spreadsheets or ruby. And I feel, that it had been
addressed many times by programmers… Alas, I appear unable to find my
own solution.

Question: How would YOU deal with multi-line cell-content ?

two representationn:

  • logic : array of row of cell, each contain multilines data
  • physics: array (or hash) fraction of line

transform logic to physic then print phycics line by line

===============================================
def draw(map)
screen=Hash.new {|h,k| h[k]=""}
nbcoll=0
irow=0
map.each {|row|
mi=0
row.each_with_index { |cell,icell|
cell.split(/\n/m).each_with_index { |str,i|
screen[[irow+i,icell]]=str
nbcoll= [nbcoll,icell].max
mi=[mi,i].max
}
}
irow+=mi+1
}
nbrow=irow

size=80/nbcoll
puts"=============================="
puts (0…nbrow).each_with_object("") {|r,str|
(0…nbcoll).each_with_object(str) {|c,str2|
str2 << ("%#{size}s" % screen[[r,c]])[0…(size-1)]
}
str << “\n”
}
end

map=(1…10).map { (1…10).map { “a” } }
draw map

map=(1…10).map { (1…10).map { “-” } }
map[2][2]=“xxx\nbbb\nccc”
map[8][7]=“yyy\nbbb”
draw map

map=(1…10).map { (1…10).map { “8\n-” } }
map[2][2]=“xxx\nbbb\nccc”
map[2][5]=“zzz\nbbb”
map[8][7]=“yyy\nbbb”
draw map

Thank you very much for this work, Regis!

two representationn:

  • logic : array of row of cell, each contain multilines data
  • physics: array (or hash) fraction of line

transform logic to physic then print phycics line by line

This is a great inspiration, first of all. I see that there is some
scientific background hidden somewhere and I really appreciate that you
even put it into working code!

At last, I cannot flee by claiming laziness to think, but admit my
downright inability to recognize the complexity of the task. :frowning:

Tomorrow, at day, I will scrutinize your method thoroughly. Chances are,
I use it as is and just add cell-borders.

===============================================
def draw(map)
screen=Hash.new {|h,k| h[k]=""}
nbcoll=0
irow=0
map.each {|row|
mi=0
row.each_with_index { |cell,icell|
cell.split(/\n/m).each_with_index { |str,i|
screen[[irow+i,icell]]=str
nbcoll= [nbcoll,icell].max
mi=[mi,i].max
}
}
irow+=mi+1
}
nbrow=irow

size=80/nbcoll
puts"=============================="
puts (0…nbrow).each_with_object("") {|r,str|
(0…nbcoll).each_with_object(str) {|c,str2|
str2 << ("%#{size}s" % screen[[r,c]])[0…(size-1)]
}
str << “\n”
}
end

map=(1…10).map { (1…10).map { “a” } }
draw map

map=(1…10).map { (1…10).map { “-” } }
map[2][2]=“xxx\nbbb\nccc”
map[8][7]=“yyy\nbbb”
draw map

map=(1…10).map { (1…10).map { “8\n-” } }
map[2][2]=“xxx\nbbb\nccc”
map[2][5]=“zzz\nbbb”
map[8][7]=“yyy\nbbb”
draw map