ZM7NOBRMD5HHA35Y4JDC76EOA2RD4KQOQCPURXYKXA6ABMKOJIGQC
QW7YRY25MDAIA2IZULYIDHEXTI5AHAKNXH4NPQB5W5VMVXJZPQCAC
RKRBRQ4YYVMFLMOG6ZWV2R5Z56V2QCZM2C6HHT6XRHN6KC5JJU3AC
V5SYDHPQ7IKNLZZ3NJ24FDW3IG4O23AASLP2DTKOBPWUUZ5KUPOAC
I64IPGJXWRTGHHVAYJUBUIWFR4BY6NM5P7TLTV4JOD7K4BVYDECQC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
H2DPLWMVRFYTO2CQTG54FMT2LF3B6UKLXH32CUA22DNQJVP5XBNQC
UBA2ZUCP3JP5SGM2R5O5X5VP6DY64Y76MH65UPSHNWEUXRPZISPQC
36Z442IVPXHZ7D2QI26YLN3TDDEMDRQ2GKBYQAD6NUHQZVCCY4VAC
3PSFWAILGRA4OYXWS2DX7VF332AIBPYBXHEA4GIQY2XEJVD65UMAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
M7UODV5HDRZKAS3BKGLNU5Z5HM4KZDM4QIB2S3E6S7NAWGJY3MJAC
YJ6ASFBGEATFRCO2OF2AA4EPOBLWXTIV6YZMHALW3QVR7XTOSJPAC
5OVKHVY6TJK53NCEUGSFBMHDENBJ25IEZNBWCI6QRCRLRKG5K7NAC
4KC7I3E2DIKLIP7LQRKB5WFA2Z5XZXAU46RFHNFQU5BVEJPDX6UQC
2L5MEZV344TOZLVY3432RHJFIRVXFD6O3GWLL5O4CV66BGAFTURQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
-- render fragment
App.color(fg)
App.screen.print(screen_line, State.left,y)
-- render colorized text
local x = State.left
for frag in screen_line:gmatch('%S*%s*') do
if fg then
App.color(fg)
else
select_color(frag)
end
App.screen.print(frag, x,y)
x = x+App.width(frag)
end
-- State transitions while colorizing a single line.
-- Just for comments and strings.
-- Limitation: each fragment gets a uniform color so we can only change color
-- at word boundaries.
Next_state = {
normal={
{prefix='--[[', target='block_comment'}, -- only single-line for now
{prefix='--', target='comment'},
-- these don't mostly work well until we can change color within words
-- {prefix='"', target='dstring'},
-- {prefix="'", target='sstring'},
{prefix='[[', target='block_string'}, -- only single line for now
},
dstring={
{suffix='"', target='normal'},
},
sstring={
{suffix="'", target='normal'},
},
block_string={
{suffix=']]', target='normal'},
},
block_comment={
{suffix=']]', target='normal'},
},
-- comments are a sink
}
Comment_color = {r=0, g=0, b=1}
String_color = {r=0, g=0.5, b=0.5}
Divider_color = {r=0.7, g=0.7, b=0.7}
Colors = {
normal=Text_color,
comment=Comment_color,
sstring=String_color,
dstring=String_color,
block_string=String_color,
block_comment=Comment_color,
}
Current_state = 'normal'
function initialize_color()
--? print('new line')
Current_state = 'normal'
end
function select_color(frag)
--? print('before', '^'..frag..'$', Current_state)
switch_color_based_on_prefix(frag)
--? print('using color', Current_state, Colors[Current_state])
App.color(Colors[Current_state])
switch_color_based_on_suffix(frag)
--? print('state after suffix', Current_state)
end
function switch_color_based_on_prefix(frag)
if Next_state[Current_state] == nil then
return
end
frag = rtrim(frag)
for _,edge in pairs(Next_state[Current_state]) do
if edge.prefix and starts_with(frag, edge.prefix) then
Current_state = edge.target
break
end
end
end
function switch_color_based_on_suffix(frag)
if Next_state[Current_state] == nil then
return
end
frag = rtrim(frag)
for _,edge in pairs(Next_state[Current_state]) do
if edge.suffix and ends_with(frag, edge.suffix) then
Current_state = edge.target
break
end
end
end
Line_number_padding = 0
on.mouse_release = function(x,y, mouse_button)
edit.mouse_release(Editor_state, x,y, mouse_button)
end
on.mouse_press = function(x,y, mouse_button)
edit.mouse_press(Editor_state, x,y, mouse_button)
end
on.key_release = function(key, scancode)
edit.key_release(Editor_state, key, scancode)
end
on.text_input = function(t)
edit.text_input(Editor_state, t)
end
on.keychord_press = function(chord, key)
edit.keychord_press(Editor_state, chord, key)
end
on.draw = function()
love.graphics.rectangle('line', 100-5-Line_number_padding,100-5, 400+10, 200+10, 5,5)
edit.draw(Editor_state)
end
on.initialize = function()
love.graphics.setFont(love.graphics.newFont(20))
Line_height = math.floor(love.graphics.getFont():getHeight()*1.3)
Line_number_padding = Line_number_width*App.width('m')
Editor_state = edit.initialize_state(100, 100, 400, love.graphics.getFont():getHeight(), Line_height)
Text.redraw_all(Editor_state)
end
Line_height = 0
Editor_state = nil