Advertisement
Guest User

vim

a guest
Aug 21st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local tArgs = {...}
  2. local filename = tArgs[1]
  3. if not filename then
  4.   print("Usage: \"vim <file>\"")
  5.   return
  6. end
  7.  
  8. local styles = {
  9.   text = {
  10.     bg = colors.black,
  11.     fg = colors.white,
  12.   },
  13.   infobar = {
  14.     bg = colors.lightGray,
  15.     fg = colors.black,
  16.   },
  17. }
  18.  
  19. local modes = {
  20.   [0] = " ", --normal
  21.   [1] = " -- INSERT --",
  22.   [2] = ":", --command
  23.   [3] = " -- VISUAL --",
  24.   [4] = " -- REPLACE --",
  25. }
  26.  
  27. local state = {
  28.   mode = 0, -- editor mode, see modes above
  29.   modified = false, --if the file was changed
  30.   scroll = {x=0,y=0,}, --the editor offset
  31.   cursor = {x=1,y=1,}, --cursor position in file
  32.   cmd = "", --current command, used in mode 2
  33. }
  34.  
  35. function style(name)
  36.   term.setBackgroundColor(styles[name].bg)
  37.   term.setTextColor(styles[name].fg)
  38. end
  39.  
  40. function infoBar(y)
  41.   --info line 1
  42.   style("infobar")
  43.   term.setCursorPos(1,y)
  44.   term.clearLine()
  45.   ---file name
  46.   term.write(" ["..filename.."]")
  47.   ---file modified
  48.   term.write((state.modified) and "[+]" or "[ ]")
  49.   ---cursor position
  50.   local posStr = state.cursor.y..","..state.cursor.x
  51.   local tX = term.getSize()
  52.   term.setCursorPos(tX-string.len(posStr),y)
  53.   term.write(posStr)
  54.   --info line 2
  55.   style("text")
  56.   term.setCursorPos(1,y+1)
  57.   term.clearLine()
  58.   ---write mode string
  59.   term.write(modes[state.mode])
  60.   ---write command if in command mode
  61.   if state.mode == 2 then
  62.     term.write(state.cmd)
  63.   end
  64. end
  65.  
  66. function draw()
  67.   local tX,tY = term.getSize()
  68.   infoBar(tY-1)
  69. end
  70.  
  71. local tmpx,tmpy=term.getCursorPos()
  72. draw()
  73. term.setCursorPos(tmpx,tmpy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement