Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local filename = tArgs[1]
- if not filename then
- print("Usage: \"vim <file>\"")
- return
- end
- local styles = {
- text = {
- bg = colors.black,
- fg = colors.white,
- },
- infobar = {
- bg = colors.lightGray,
- fg = colors.black,
- },
- }
- local modes = {
- [0] = " ", --normal
- [1] = " -- INSERT --",
- [2] = ":", --command
- [3] = " -- VISUAL --",
- [4] = " -- REPLACE --",
- }
- local state = {
- mode = 0, -- editor mode, see modes above
- modified = false, --if the file was changed
- scroll = {x=0,y=0,}, --the editor offset
- cursor = {x=1,y=1,}, --cursor position in file
- cmd = "", --current command, used in mode 2
- }
- function style(name)
- term.setBackgroundColor(styles[name].bg)
- term.setTextColor(styles[name].fg)
- end
- function infoBar(y)
- --info line 1
- style("infobar")
- term.setCursorPos(1,y)
- term.clearLine()
- ---file name
- term.write(" ["..filename.."]")
- ---file modified
- term.write((state.modified) and "[+]" or "[ ]")
- ---cursor position
- local posStr = state.cursor.y..","..state.cursor.x
- local tX = term.getSize()
- term.setCursorPos(tX-string.len(posStr),y)
- term.write(posStr)
- --info line 2
- style("text")
- term.setCursorPos(1,y+1)
- term.clearLine()
- ---write mode string
- term.write(modes[state.mode])
- ---write command if in command mode
- if state.mode == 2 then
- term.write(state.cmd)
- end
- end
- function draw()
- local tX,tY = term.getSize()
- infoBar(tY-1)
- end
- local tmpx,tmpy=term.getCursorPos()
- draw()
- term.setCursorPos(tmpx,tmpy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement