|
|
@ -2,12 +2,14 @@ |
|
|
|
-- Version 0.05 |
|
|
|
-- by: ASCII Benefactor |
|
|
|
-- April 2022 |
|
|
|
---------------------------------- |
|
|
|
-- |
|
|
|
------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
filename="dummy.txt" |
|
|
|
VER="v0.05" |
|
|
|
nc=require("nocurses") |
|
|
|
dofile("box.lua") |
|
|
|
-- dofile("func.lua") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -17,6 +19,10 @@ function at(s,p) |
|
|
|
return string.sub(s,p,p) |
|
|
|
end |
|
|
|
|
|
|
|
function len(s) |
|
|
|
return string.len(s) |
|
|
|
end |
|
|
|
|
|
|
|
----------------------------end small funcs ------ |
|
|
|
function start() |
|
|
|
nc.setunderline(true) |
|
|
@ -51,7 +57,7 @@ function cmd() |
|
|
|
nc.setfontcolor("YELLOW") |
|
|
|
inp = io.input():read("*l") |
|
|
|
nc.setfontcolor("WHITE") |
|
|
|
-- all commands start with a symbol |
|
|
|
-- all commands start with a symbol |
|
|
|
if at(inp,1)=="*" and string.len(inp)<=1 then |
|
|
|
print("You must enter a valid filename...") |
|
|
|
elseif at(inp,1)=="*" and string.len(inp)>1 then |
|
|
@ -63,7 +69,7 @@ function cmd() |
|
|
|
-- print("line [#"..currline.."]:") |
|
|
|
table.insert(lines_tbl,currline,"") |
|
|
|
currline=currline+1 |
|
|
|
-- if inp has > symbol, then its a literal line to write to file |
|
|
|
-- if inp has > symbol, then its a literal line to write to file |
|
|
|
elseif at(inp,1) == ">" and string.len(inp)>1 then |
|
|
|
table.insert(lines_tbl,currline,string.sub(inp,2)) |
|
|
|
currline=currline+1 |
|
|
@ -73,29 +79,26 @@ function cmd() |
|
|
|
write_file() |
|
|
|
elseif at(inp,1) == "=" and string.len(inp)==1 then |
|
|
|
display_text() |
|
|
|
elseif string.match(inp,"%d+%>%g+") and string.len(inp)>3 then |
|
|
|
-- FIXME FIXME FIXME ^^^^^^ |
|
|
|
lpos=string.match(inp,"%d") |
|
|
|
add_line(lpos,str) |
|
|
|
elseif at(inp,1)=="x" and at(inp,2)=="!" then |
|
|
|
break |
|
|
|
elseif at(inp,1)==":" and at(inp,2)=="g" and at(inp,3)=="o" and string.match(inp,"%d+")~= nil then |
|
|
|
currline=string.match(inp,"%d+") |
|
|
|
elseif at(inp,1)=="x" and #inp==1 then |
|
|
|
elseif at(inp,1)=="?" and #inp==1 then |
|
|
|
print_help() |
|
|
|
elseif at(inp,1)==":" and at(inp,2)=="q" then |
|
|
|
break |
|
|
|
else |
|
|
|
-- catchall -- |
|
|
|
nc.setfontcolor("RED") |
|
|
|
print("Unknown Command!") |
|
|
|
nc.setfontcolor("WHITE") |
|
|
|
if inp=="" then |
|
|
|
else |
|
|
|
nc.setfontcolor("RED") |
|
|
|
print("Unknown Command!") |
|
|
|
nc.setfontcolor("WHITE") |
|
|
|
end |
|
|
|
-- end of command defs ========================= |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_line(lpos,str) |
|
|
|
local str,lpos |
|
|
|
if currfile~=-1 then |
|
|
@ -126,8 +129,7 @@ function new_file(fn) --also load |
|
|
|
currfile:close() |
|
|
|
currfile = io.open(fn,"w+") |
|
|
|
elseif nc.getch()=="n" then |
|
|
|
anxietyattack=true |
|
|
|
pleb=true |
|
|
|
return 0 |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
@ -140,35 +142,56 @@ function display_file() -- Displays file proper |
|
|
|
print(lnum..":"..line) |
|
|
|
lnum=lnum+1 |
|
|
|
end |
|
|
|
print("=================================\n\n") |
|
|
|
end |
|
|
|
|
|
|
|
function print_help() |
|
|
|
local k |
|
|
|
nc.clrscr() |
|
|
|
nc.setfontcolor("GREEN") |
|
|
|
print(" VITE commands ") |
|
|
|
print("===============") |
|
|
|
print("* new file ") |
|
|
|
print("> insert line") |
|
|
|
print("= Show lines") |
|
|
|
print(": main commands") |
|
|
|
print("===================================") |
|
|
|
print("* new file ") |
|
|
|
print("> insert line") |
|
|
|
print("= Show lines") |
|
|
|
print(": main commands") |
|
|
|
|
|
|
|
print("enter any key to continue..." ) |
|
|
|
|
|
|
|
while k == null do |
|
|
|
k=nc.getch() |
|
|
|
end |
|
|
|
nc.clrscr() |
|
|
|
|
|
|
|
print(" Main ':' commands ") |
|
|
|
print("===================================") |
|
|
|
print(":q quit") |
|
|
|
print(":w Write pending files to file") |
|
|
|
print("k Show lines") |
|
|
|
print(": main commands") |
|
|
|
print("enter any key to continue..." ) |
|
|
|
|
|
|
|
while k == null do |
|
|
|
k=nc.getch() |
|
|
|
end |
|
|
|
print("End of Help") |
|
|
|
nc.setfontcolor("WHITE") |
|
|
|
end |
|
|
|
|
|
|
|
function rem_line(lnum) |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
function display_text() -- prints lines_tbl (bef flush) |
|
|
|
currfile:seek("set") |
|
|
|
local line |
|
|
|
nc.clrscr() |
|
|
|
nc.setfontcolor("CYAN") |
|
|
|
for k,ln in pairs(lines_tbl) do |
|
|
|
for lnum,lstr in pairs(lines_tbl) do |
|
|
|
-- nc.gotoxy(1,k) |
|
|
|
print(k..":"..ln) |
|
|
|
print(lnum..":"..lstr) |
|
|
|
end |
|
|
|
print("=================================\n\n") |
|
|
|
nc.setfontcolor("WHITE") |
|
|
|
end |
|
|
|
|
|
|
|
-- Program Loop Begin |
|
|
|
start() |
|
|
|