# HG changeset patch # User Mike Pavone # Date 1342332184 25200 # Node ID 0a55ee387d69f4c815d9485ae609d99c3500c836 # Parent f7a1daaec925497fa70eb98dd58a2a6aa6fb79da Change grid order diff -r f7a1daaec925 -r 0a55ee387d69 src/sim.tp --- a/src/sim.tp Sat Jul 14 21:27:36 2012 -0700 +++ b/src/sim.tp Sat Jul 14 23:03:04 2012 -0700 @@ -102,13 +102,19 @@ self } printGrid <- { - grid foreach: :index value { - os write: 2 (value str) - if: index % width = width - 1 { + cur <- (grid length) - width + col <- 0 + while: {cur >= 0} do: { + os write: 2 ((grid get: cur) str) + cur <- cur + 1 + col <- col + 1 + if: col = width { + col <- 0 + cur <- cur - (width + width) os write: 2 "\n" } } - } + } } foreach: in_grid :index el{ nextGrid append: el @@ -119,38 +125,39 @@ } ret } + fromStr <- :str { strLen <- str byte_length: maxCol <- 0 - col <- 0 - rows <- 0 nl <- (cellTypes newline) id blank <- cellTypes empty + lines <- #[] + curline <- #[] eachbyte: str :index element { if: element = nl { + col <- curline length maxCol <- if: col > maxCol {col} else: {maxCol} - col <- 0 - rows <- rows + 1 + lines append: curline + curline <- #[] } else: { - col <- col + 1 + curline append: (cellTypes find: element) } } - col <- 0 grid <- #[] - eachbyte: str :index element { - if: element = nl { - // add spaces - while: { col < maxCol } do: { - grid append: blank - col <- col + 1 - } - col <- 0 - } else: { - grid append: (cellTypes find: element) - col <- col + 1 + cur <- (lines length) - 1 + while: { cur >= 0 } do: { + curline <- (lines get: cur) + foreach: curline :idx el { + grid append: el } + extra <- maxCol - (curline length) + while: { extra > 0 } do: { + grid append: blank + extra <- extra - 1 + } + cur <- cur - 1 } - new: grid maxCol rows + new: grid maxCol (lines length) } }