From 9b18e35aaaafadc0aec04d8321f4f64f0c202094 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 21 Nov 2023 08:53:19 -0800 Subject: [PATCH] bring back syntax highlighting (but so ugly) --- 0012-on.draw | 2 +- 0091-Foreground_color | 7 ++++++- colorize.lua | 8 ++++++-- edit.lua | 3 ++- search.lua | 2 +- select.lua | 2 +- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/0012-on.draw b/0012-on.draw index 6938fb4..51fedbc 100644 --- a/0012-on.draw +++ b/0012-on.draw @@ -4,7 +4,7 @@ on.draw = function() draw_canvas() if Show_code then draw_editor_border() - edit.draw(Current_pane.editor_state, --[[fg]] Foreground_color, --[[hide_cursor]] nil, --[[show_line_numbers]] true) + edit.draw(Current_pane.editor_state, --[[implicitly use Foreground_color]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true) draw_scrollbar(Current_pane.editor_state) draw_output_border() edit.draw(Current_pane.output_editor_state, Foreground_color, --[[hide cursor]] true) diff --git a/0091-Foreground_color b/0091-Foreground_color index 9d4e0b3..69d345a 100644 --- a/0091-Foreground_color +++ b/0091-Foreground_color @@ -1 +1,6 @@ -Foreground_color = {r=0, g=0, b=0} \ No newline at end of file +-- Foreground_color comes predefined, and we have to be careful +-- to use the precise table instance used by colorize.lua +-- +-- This 'definition' is only here to remind us of this global, +-- and this gotcha. +Foreground_color = Foreground_color diff --git a/colorize.lua b/colorize.lua index 6a0a7e5..19412c5 100644 --- a/colorize.lua +++ b/colorize.lua @@ -31,7 +31,7 @@ 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, + normal=Foreground_color, comment=Comment_color, sstring=String_color, dstring=String_color, @@ -47,9 +47,13 @@ function initialize_color() end function select_color(frag) +--? if frag == 'do ' then --? print('before', '^'..frag..'$', Current_state) +--? end switch_color_based_on_prefix(frag) ---? print('using color', Current_state, Colors[Current_state]) +--? if frag == 'do ' then +--? print('using color', Current_state, Colors[Current_state], Colors[Current_state].r, Colors[Current_state].g, Colors[Current_state].b) +--? end App.color(Colors[Current_state]) switch_color_based_on_suffix(frag) --? print('state after suffix', Current_state) diff --git a/edit.lua b/edit.lua index 67f1548..b8b7fb6 100644 --- a/edit.lua +++ b/edit.lua @@ -1,5 +1,6 @@ -- some constants people might like to tweak -Text_color = {r=0, g=0, b=0} +Text_color = {r=0, g=0, b=0} -- only used in tests +Foreground_color = {r=0, g=0, b=0} Cursor_color = {r=1, g=0, b=0} Highlight_color = {r=0.7, g=0.7, b=0.9} -- selected text Line_number_color = {r=0.4, g=0.4, b=0.4} diff --git a/search.lua b/search.lua index 4e7df0c..bc92d76 100644 --- a/search.lua +++ b/search.lua @@ -11,7 +11,7 @@ function Text.draw_search_bar(State) love.graphics.rectangle('fill', 20, y-6, App.screen.width-40, h+2, 2,2) love.graphics.setColor(0.6,0.6,0.6) love.graphics.rectangle('line', 20, y-6, App.screen.width-40, h+2, 2,2) - App.color(Text_color) + App.color(Foreground_color) App.screen.print(State.search_term, 25,y-5) Text.draw_cursor(State, 25+App.width(State.search_term),y-5, Cursor_color) end diff --git a/select.lua b/select.lua index 41ef162..9a646b9 100644 --- a/select.lua +++ b/select.lua @@ -62,7 +62,7 @@ function Text.draw_highlight(State, line, x,y, pos, lo,hi) local s = line.data:sub(lo_offset, hi_offset-1) App.color(Highlight_color) love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height) - App.color(Text_color) + App.color(Foreground_color) return lo_px end end