[Turn off line numbering]1: arg list, headers, @rest; 2: var i, j, t, t1, trim_cols, header_sep, colsizes, len; 3: 4: if (!list) 5: return []; 6: [(colsizes ?= 0), (trim_cols ?= 0), (header_sep ?= " "), (len ?= 79)] = rest; 7: if (!headers) 8: headers = .make(list.length(), []); 9: if (type(headers[1]) == 'string) 10: headers = map i in (headers) to ([i]); 11: 12: // Find the column sizes 13: if (!colsizes) { 14: if (trim_cols) { 15: t = map i in (list) to (refresh() && i.element_maxlength() + 2); 16: t1 = filter i in [1 .. t.length()] where (t[i] > 2); 17: t = map i in (t1) to (t[i]); 18: list = map i in (t1) to (list[i]); 19: headers = map i in (t1) to (headers[i]); 20: } 21: colsizes = t ? map i in [1 .. headers.length()] to (refresh() && max(t[i], headers[i].element_maxlength() + 2)) : map i in [1 .. list.length()] to (refresh() && max(headers[i].element_maxlength(), list[i].element_maxlength()) + 2); 22: } 23: t = map i in (colsizes) to ("%" + i + "l").sum(); 24: t1 = map i in (colsizes) to ("%" + i + "{" + header_sep + "}l").sum(); 25: 26: // Now format the thing... 27: return map i in (headers.transpose()) to (refresh() && t1.format(@i).pad(len).trim('right)) + map i in (list.transpose()) to (refresh() && t.format(@i).pad(len).trim('right));
// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit