Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 44 lines (32 sloc) 0.762 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43


module Rendering
     ( render
     , cls
     , goto
     , home
     , commandHome
     , writeAt
     )
where

import EditBuffer
import IO

yExtent :: Int
yExtent = 40

home :: Location
home = (0,0)

commandHome :: Location
commandHome = (0, yExtent + 1)

cls :: IO ()
cls = putStr "\ESC[2J"

render :: EditBuffer -> IO ()
render (EditBuffer topLine (x,y) contents) = do
  writeAt home $ window screenLines
  goto (x, y - topLine)
    where window = unlines . take yExtent . drop topLine
          screenLines = (lines contents) ++ (repeat "~")

goto :: Location -> IO ()
goto (x,y) =
  putStr ("\ESC[" ++ show (y + 1) ++ "; " ++ show (x + 1) ++ "H")

writeAt :: Location -> String -> IO ()
writeAt location xs = do
  goto location
  putStr xs

Something went wrong with that request. Please try again.