diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-09 13:52:11 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-09 13:55:58 +0100 |
commit | 5b91fe424ee7358367f998af8c1903362f9e2abd (patch) | |
tree | e6941715a3fbd4b82a6420f978edacf7e862d88a /buffer.cpp | |
parent | 4addb711c6a1a282b0a59bf03e850a86ba2ead69 (diff) |
Bugfixing
Diffstat (limited to 'buffer.cpp')
-rw-r--r-- | buffer.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -2,6 +2,7 @@ #include <fstream> #include <cassert> #include <cmath> +#include <cinttypes> #include <termio.h> #include "buffer.h" @@ -46,12 +47,11 @@ static string showChar(char c){ "0123456789abcdef"[(unsigned char)c%16]}; } -/*static i64 charWidth(char c){ - return showChar(c).size(); -}*/ - vector<Buffer::ScreenLine> Buffer::layoutLine(const string &line,i64 linenum,i64 width){ assert(width>=4); + if(line.size()==0){ + return {{linenum,0,0,{}}}; + } vector<ScreenLine> layout; vector<Cell> cur; i64 x=0; @@ -67,7 +67,7 @@ vector<Buffer::ScreenLine> Buffer::layoutLine(const string &line,i64 linenum,i64 fromx=i; x=0; } - Cell cell={'\0',repr.size()!=1}; + Cell cell={'\0',repr.size()!=1,i}; for(char rc : repr){ cell.c=rc; cur.push_back(cell); @@ -95,7 +95,7 @@ void Buffer::performInitialLayout(i64 width,i64 height){ //Layout the line the cursor is on. screen=layoutLine(tb[cursor.line],cursor.line,width); i64 cursorScreenY=0; - while(cursorScreenY+1<(i64)screen.size()&&screen[cursorScreenY+1].fromx>cursor.x){ + while(cursorScreenY+1<(i64)screen.size()&&screen[cursorScreenY+1].fromx<=cursor.x){ cursorScreenY++; } @@ -125,9 +125,10 @@ void Buffer::performInitialLayout(i64 width,i64 height){ while(bottomLine<tb.numLines()&&(i64)screen.size()<height){ vector<ScreenLine> layout=layoutLine(tb[bottomLine],bottomLine,width); screen.insert(screen.end(),layout.begin(),layout.end()); + // cerr<<"Added bottomLine="<<bottomLine<<" (tb.numLines()="<<tb.numLines()<<")"<<endl; bottomLine++; } - if((i64)screen.size()<height){ + if((i64)screen.size()>height){ //Oops, we overran a bit. Prune the end so that we fill the screen exactly. screen.resize(height); } else if((i64)screen.size()<height){ @@ -170,7 +171,7 @@ void Buffer::renewLayout(i64 topLine,i64 topPart,i64 width,i64 height){ i64 bottomLine=topLine+1; while(bottomLine<tb.numLines()&&(i64)screen.size()<height){ vector<ScreenLine> layout=layoutLine(tb[bottomLine],bottomLine,width); - screen.insert(screen.begin(),layout.begin(),layout.end()); + screen.insert(screen.end(),layout.begin(),layout.end()); bottomLine++; } @@ -198,8 +199,14 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){ lastWidth=newWidth; lastHeight=height; } + + setstyle(&textStyle); + fillrect(atx,aty,width,height,' '); + pushcursor(); i64 y; + i64 curScreenX=-1,curScreenY=-1; + // cerr<<"Buffer::show: screen.size()="<<screen.size()<<endl; for(y=0;y<(i64)screen.size();y++){ moveto(atx,aty+y); setstyle(&gutterStyle); @@ -207,15 +214,25 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){ for(i64 i=0;i<nspaces;i++){ tputc(' '); } - tprintf("%lld ",screen[y].line+1); + tprintf("%" PRIi64 " ",screen[y].line+1); + i64 screenX=atx+gutterWidth; setstyle(&textStyle); for(const Cell &cell : screen[y].cells){ if(cell.special)setstyle(&specialStyle); else setstyle(&textStyle); tputc(cell.c); + if(curScreenX==-1&&cell.linex==cursor.x&&screen[y].line==cursor.line){ + curScreenX=screenX; + curScreenY=aty+y; + } + screenX++; } } setstyle(&textStyle); if(y<height)fillrect(atx,aty+y,width,height-y,' '); + popcursor(); + if(curScreenX!=-1){ + moveto(curScreenX,curScreenY); + } } |