Fixes for line handling behavior.

This commit is contained in:
Bruce Hill 2018-04-09 18:59:00 -07:00
parent a8e4ed4ac6
commit 44120abce6
2 changed files with 10 additions and 15 deletions

14
ldt.lua
View File

@ -1,5 +1,6 @@
local C = require("curses")
local re = require('re')
local line_matcher = re.compile('lines<-{| line ("\n" line)* |} line<-{[^\n]*}')
local ldb
local AUTO = { }
local PARENT = { }
@ -39,7 +40,9 @@ end
local wrap_text
wrap_text = function(text, width)
local lines = { }
for line in text:gmatch("[^\n]*") do
local _list_0 = line_matcher:match(text)
for _index_0 = 1, #_list_0 do
local line = _list_0[_index_0]
while #line > width do
table.insert(lines, line:sub(1, width))
line = line:sub(width + 1, -1)
@ -362,7 +365,6 @@ do
end
NumberedPad = _class_0
end
local line_matcher = re.compile('lines<-{|(line "\n")* line|} line<-{[^\n]*}')
local expansions = { }
local KEY = { }
local VALUE = { }
@ -839,7 +841,6 @@ do
self.full_refresh = function()
local old_location = self.selected and self.chstr_locations and self.chstr_locations[self.selected]
self.chstrs, self.chstr_locations = { }, { }
line_matcher = re.compile('lines<-{|(line "\n")* line|} line<-{[^\n]*}')
local W = width - 3
local lines = make_lines(TOP_LOCATION, self.data, W)
for i, line in ipairs(lines) do
@ -931,7 +932,7 @@ local file_cache = setmetatable({ }, {
if not file then
return nil
end
local contents = file:read("*a")
local contents = file:read("a"):sub(1, -2)
self[filename] = contents
return contents
end
@ -1110,10 +1111,7 @@ ldb = {
end
file_contents = file_contents or file_cache[filename]
if file_contents then
local src_lines = { }
for line in (file_contents .. '\n'):gmatch("([^\n]*)\n") do
table.insert(src_lines, line)
end
local src_lines = line_matcher:match(file_contents)
pads.src = NumberedPad("(S)ource Code", pads.err.height, 0, pads.stack.height, pads.stack.x, src_lines, function(self, i)
if i == line_no and i == self.selected then
return Color("yellow on red bold")

View File

@ -1,5 +1,6 @@
C = require "curses"
re = require 're'
line_matcher = re.compile('lines<-{| line ("\n" line)* |} line<-{[^\n]*}')
local ldb
AUTO = {} -- Singleton
PARENT = {} -- Singleton
@ -34,7 +35,7 @@ callstack_range = ->
wrap_text = (text, width)->
lines = {}
for line in text\gmatch("[^\n]*")
for line in *line_matcher\match(text)
while #line > width
table.insert(lines, line\sub(1,width))
line = line\sub(width+1,-1)
@ -242,7 +243,6 @@ class NumberedPad extends Pad
super @label, @y, @x, height, width, unpack(cols)
line_matcher = re.compile('lines<-{|(line "\n")* line|} line<-{[^\n]*}')
expansions = {}
KEY = {}
VALUE = {}
@ -442,7 +442,6 @@ class DataViewer extends Pad
@full_refresh = ->
old_location = @selected and @chstr_locations and @chstr_locations[@selected]
@chstrs, @chstr_locations = {}, {}
line_matcher = re.compile('lines<-{|(line "\n")* line|} line<-{[^\n]*}')
W = width-3
lines = make_lines(TOP_LOCATION, @data, W)
for i,line in ipairs(lines)
@ -585,7 +584,7 @@ if not ok then to_lua = -> nil
file_cache = setmetatable({}, {__index:(filename)=>
file = io.open(filename)
if not file then return nil
contents = file\read("*a")
contents = file\read("a")\sub(1,-2) -- drop the trailing "\n" that Lua adds for some reason
@[filename] = contents
return contents
})
@ -724,9 +723,7 @@ ldb = {
pads.src\erase!
file_contents = file_contents or file_cache[filename]
if file_contents
src_lines = {}
for line in (file_contents..'\n')\gmatch("([^\n]*)\n")
table.insert src_lines, line
src_lines = line_matcher\match(file_contents)
pads.src = NumberedPad "(S)ource Code", pads.err.height,0,
pads.stack.height,pads.stack.x, src_lines, (i)=>
return if i == line_no and i == @selected then Color("yellow on red bold")