diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 15:50:01 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 15:50:01 -0700 |
commit | 39b2c849c415f8efe56e40fabf414a0799fb2145 (patch) | |
tree | 2da0da354da56acc08f3f6354ac79bd33bcfa795 | |
parent | d011c0ce325b69ed413666a5adb31156c1a26c41 (diff) | |
parent | 89222f86a0dc3dd774ce46afaa1ba791ed65dba9 (diff) | |
download | text.love-39b2c849c415f8efe56e40fabf414a0799fb2145.tar.gz |
Merge lines.love
-rw-r--r-- | file.lua | 10 | ||||
-rw-r--r-- | text.lua | 14 |
2 files changed, 23 insertions, 1 deletions
diff --git a/file.lua b/file.lua index 94514b2..e95c14d 100644 --- a/file.lua +++ b/file.lua @@ -1,4 +1,14 @@ -- primitives for saving to file and loading from file +function file_exists(filename) + local infile = App.open_for_reading(filename) + if infile then + infile:close() + return true + else + return false + end +end + function load_from_disk(State) local infile = App.open_for_reading(State.filename) State.lines = load_from_file(infile) diff --git a/text.lua b/text.lua index 0e79e8d..48db699 100644 --- a/text.lua +++ b/text.lua @@ -9,7 +9,6 @@ require 'text_tests' -- draw a line starting from startpos to screen at y between State.left and State.right -- return the final y, and position of start of final screen line drawn function Text.draw(State, line_index, y, startpos) - App.color(Text_color) local line = State.lines[line_index] local line_cache = State.line_cache[line_index] line_cache.starty = y @@ -20,6 +19,7 @@ function Text.draw(State, line_index, y, startpos) local screen_line_starting_pos = startpos Text.compute_fragments(State, line_index) for _, f in ipairs(line_cache.fragments) do + App.color(Text_color) local frag, frag_text = f.data, f.text local frag_len = utf8.len(frag) --? print('text.draw:', frag, 'at', line_index,pos, 'after', x,y) @@ -917,3 +917,15 @@ function Text.clear_screen_line_cache(State, line_index) State.line_cache[line_index].fragments = nil State.line_cache[line_index].screen_line_starting_pos = nil end + +function trim(s) + return s:gsub('^%s+', ''):gsub('%s+$', '') +end + +function ltrim(s) + return s:gsub('^%s+', '') +end + +function rtrim(s) + return s:gsub('%s+$', '') +end |