Compare commits

...

2 Commits

Author SHA1 Message Date
asciibene 81c8185df9 added box.lua 8 months ago
asciibene a8d346dd70 Minor Improvements v0.05 8 months ago
  1. 15
      box.lua
  2. 89
      vite.lua

@ -0,0 +1,15 @@
-- various 'UI' functions
-- ::asciibene::
function draw_pane(ttl)
local bxlen=#ttl+4
local bylen=3
for i=1,bylen do
if i==1 or i==3 then
print(string.rep("*",bxlen))
elseif i==2 then
print("*".." "..ttl.." ".."*")
end
end
end

@ -1,19 +1,26 @@
--Vi Inspired Textual Editor === VITE
-- Version alpha 0.02
filename="./dummy.txt"
VER="v0.02"
-- Version 0.05
-- by: ASCII Benefactor
-- April 2022
----------------------------------
--
filename="dummy.txt"
VER="v0.05"
nc=require("nocurses")
dofile("box.lua")
-- Small Funcs Start ------------------------------
function at(s,p)
return string.sub(s,p,p)
end
----------------------------end small funcs
----------------------------end small funcs ------
function start()
nc.setunderline(true)
print("VITE === Vi Inspired Textual Editor === "..VER)
print("VITE === Vi Inspired Text Editor === "..VER)
nc.setunderline(false)
currline=-1
currfile=-1
@ -21,24 +28,26 @@ function start()
cmd()
--after closing
if currfile ~= -1 then
print("closing vite...bye")
print("Closing VITE...bye!")
currfile:close()
else
print("Closing VITE...bye!")
end
end
-- list of Commands
-- ----------------
-- * = newfile
-- > = appendtext
-- : = commands
--
-- : = main commands
-- = = Display pending lines
-- ? = Display Help
function cmd()
while inp~=":q" do
-- main loop
if currline== -1 then
print("No file opened")
elseif currline~=-1 then
print(currline..":")
end
while true do
---------------------- main loop
if currline ~= -1 then print(currline..":") end -- InfoLine TM
nc.setfontcolor("YELLOW")
inp = io.input():read("*l")
nc.setfontcolor("WHITE")
@ -51,7 +60,9 @@ function cmd()
print("New File:"..newfn.."\n")
currline=1
elseif at(inp,1) == ">" and string.len(inp)==1 then
print("line [#"..currline.."]:")
-- print("line [#"..currline.."]:")
table.insert(lines_tbl,currline,"")
currline=currline+1
-- 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))
@ -62,15 +73,22 @@ 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)>2 then
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 #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")
-- end of command def ==========
-- end of command defs =========================
end
end
@ -91,7 +109,7 @@ function write_file() -- flush data to the file":w"
if currfile~=-1 then
currfile:write(table.concat(lines_tbl,"\n").."\n")
print("Flushed buffer unto "..newfn)
-- TODO Show filesize
-- TODO Show filesize XXX
else
print("No file to write to !")
end
@ -101,14 +119,20 @@ function new_file(fn) --also load
if currfile==-1 then
currfile = io.open(fn,"w+")
elseif currfile~=-1 then
currfile:close()
-- XXX Make it ask for confirm
-- XXX make it display whats going on
currfile = io.open(fn,"w+")
nc.setfontcolor("RED")
print("Confirm Close file?")
nc.setfontcolor("WHITE")
if nc.getch()=="y" or nc.getch()=="Y" then
currfile:close()
currfile = io.open(fn,"w+")
elseif nc.getch()=="n" then
anxietyattack=true
pleb=true
end
end
end
function display_file()
function display_file() -- Displays file proper
currfile:seek("set")
local lnum = 1
for line in currfile:lines() do
@ -118,18 +142,33 @@ function display_file()
end
print("=================================\n\n")
end
function display_text() -- prints lines_tbl
function print_help()
nc.clrscr()
nc.setfontcolor("GREEN")
print(" VITE commands ")
print("===============")
print("* new file ")
print("> insert line")
print("= Show lines")
print(": main commands")
nc.setfontcolor("WHITE")
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
nc.gotoxy(1,k)
-- nc.gotoxy(1,k)
print(k..":"..ln)
end
print("=================================\n\n")
nc.setfontcolor("WHITE")
end
start()

Loading…
Cancel
Save