diff --git a/R2H2.lua b/R2H2.lua index 8db3a9f..d9c2b44 100644 --- a/R2H2.lua +++ b/R2H2.lua @@ -236,6 +236,7 @@ function convertToHeonian(text) -- output if autocopy then CopyToClipboard(string.sub(transcribed_text,0,-1)) end + if transcribed_text == nil then transcribed_text = "" end return transcribed_text end end \ No newline at end of file diff --git a/add_word.lua b/add_word.lua index a36f304..2f93c68 100644 --- a/add_word.lua +++ b/add_word.lua @@ -4,8 +4,9 @@ function addWord() local file = io.open(data_get, "r") local pos = 0 +-- all this is old code, not useful now, but still in case i need it <: -- get insertion point - pos = file:seek("end",-9) + pos = file:seek("end") -- store after local after = file:read("*all") @@ -32,14 +33,14 @@ function addWord() local file = io.open(data_output, "w+") file:write(before) - file:write("\ntable.insert(t,{\"") + file:write("\n") for i=1, #modify do if i > 1 then - file:write("\",\"") + file:write(" ") end file:write(modify[i]) end - file:write("\"})\n") + file:write("") file:write(after) file:close() end diff --git a/color.lua b/color.lua index c5655ff..56d1604 100644 --- a/color.lua +++ b/color.lua @@ -39,14 +39,17 @@ EFFECT = Enum { } function makeTextEffect(Effect, Text) + Text = Text or "" return "\027["..tostring(Effect-1).."m"..Text.."\027[0;m" end function colorText(Color, Text) + Text = Text or "" return "\027[38;5;"..tostring(Color-1).."m"..Text.."\027[0;m" end function colorTextBackground(Color, Text) + Text = Text or "" return "\027[48;5;"..tostring(Color-1).."m"..Text.."\027[0;m" end diff --git a/edit_word.lua b/edit_word.lua index 4290307..d9c3592 100644 --- a/edit_word.lua +++ b/edit_word.lua @@ -130,14 +130,14 @@ function editWord(number) --rewrite with new info local file = io.open(data_output, "w+") file:write(before) - file:write("table.insert(t,{\"") + file:write("\n") for i=1, #modify do if i > 1 then - file:write("\",\"") + file:write(" ") end file:write(modify[i]) end - file:write("\"})") + file:write("") file:write(after) file:close() end diff --git a/get_words.lua b/get_words.lua new file mode 100644 index 0000000..9c606c3 --- /dev/null +++ b/get_words.lua @@ -0,0 +1,49 @@ +function getWords(path) + local file = io.open(path,"r") + local text = file:read("*all") + file:close() + + local t = {} -- this table will hold our words!!! words format is {word, translation, types, canon origin, meta origin, notes} last three are optional. + + local p = 0 -- current position, nil if at end of file + while p do + p = p + 1 + + local new_word_data = "" + + -- this isnt the whole word yet, but all the data around it separated with tabs, so lets get what we want. + -- careful if its uh end of file tho! + local np = string.find(text,"\n",p) -- np is the next word. this is so we can slice it + if np then + new_word_data = string.sub(text, p, np-1) + else + new_word_data = string.sub(text, p) + end + + if new_word_data ~= "" then + local new_word = {} -- we'll hold it all here once spliced + local wp = 0 -- word data position! + while wp do -- nil if at end of string so. + wp = wp + 1 -- lets move past the tab we just found + + local wnp = string.find(new_word_data, " ",wp) + local stuff = "" + -- we now splice the word every tab and add it to the uhhh + if wnp then + stuff = string.sub(new_word_data, wp, wnp-1) or stuff + else + stuff = string.sub(new_word_data,wp) or stuff + end + + table.insert(new_word,stuff) + wp = wnp + end + -- now we add the word ot the word table + table.insert(t, new_word) + end + -- and move on the next + p = np + end + -- now we just. return the table. + return t +end \ No newline at end of file diff --git a/heonian-content b/heonian-content index 6a40a51..8616391 160000 --- a/heonian-content +++ b/heonian-content @@ -1 +1 @@ -Subproject commit 6a40a51d6ea7cf2bc2261ae783e8e7731b3fa007 +Subproject commit 86163910b2236a27a8cfab8817a07f1450dfa770 diff --git a/lexicon b/lexicon index 5316c0d..70da679 100755 --- a/lexicon +++ b/lexicon @@ -16,12 +16,13 @@ require "search_list" require "remove_word" require "add_word" require "edit_word" +require "get_words" require "lessons" -data_get = "heonian-content/words.lua" -data_output = "heonian-content/words.lua" +data_get = "heonian-content/words" +data_output = "heonian-content/words" -words = dofile(data_get) +words = getWords(data_get) for _, v in pairs(arg) do if v == "-h" diff --git a/output_sizes.lua b/output_sizes.lua index eb8cfcc..f18ca25 100644 --- a/output_sizes.lua +++ b/output_sizes.lua @@ -9,7 +9,7 @@ function adjustTableSizes(tbl) words_max_length[j+1] = length + 1 end end - local length = string.len(convertToHeonian(this_word[1])) + local length = string.len(this_word[1]) if length + 1 > words_max_length[1] then words_max_length[1] = length + 1 end