summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-09 13:52:11 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-09 13:55:58 +0100
commit5b91fe424ee7358367f998af8c1903362f9e2abd (patch)
treee6941715a3fbd4b82a6420f978edacf7e862d88a
parent4addb711c6a1a282b0a59bf03e850a86ba2ead69 (diff)
Bugfixing
-rw-r--r--buffer.cpp35
-rw-r--r--buffer.h1
-rw-r--r--main.cpp3
-rw-r--r--manager.cpp7
4 files changed, 33 insertions, 13 deletions
diff --git a/buffer.cpp b/buffer.cpp
index e32492b..2123de1 100644
--- a/buffer.cpp
+++ b/buffer.cpp
@@ -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);
+ }
}
diff --git a/buffer.h b/buffer.h
index 19b81ee..fd9b062 100644
--- a/buffer.h
+++ b/buffer.h
@@ -19,6 +19,7 @@ class Buffer{
struct Cell{
char c;
bool special;
+ i64 linex; //position in line
};
struct ScreenLine{
i64 line,part; //part: n'th screen line of the logical line `line`
diff --git a/main.cpp b/main.cpp
index ec25d28..f637804 100644
--- a/main.cpp
+++ b/main.cpp
@@ -11,6 +11,9 @@ int main(int argc,char **argv){
__asm("int3\n\t");
});
+ freopen("editor.log","w",stderr);
+ setvbuf(stderr,nullptr,_IONBF,0);
+
installCLhandler(true);
Manager manager;
for(int i=1;i<argc;i++){
diff --git a/manager.cpp b/manager.cpp
index 01c9e01..7f9fa89 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -15,9 +15,7 @@ void Manager::receive(const Command &cmd){
if(cmd[0]=="open_file"){
buffers.emplace_back(this);
buffers.back().receive(cmd);
- } else if(cmd[0]=="insert_char"){
- if(activeIdx==-1)bel();
- else buffers[activeIdx].receive(cmd);
+ if(activeIdx==-1)activeIdx=buffers.size()-1;
} else if(cmd[0]=="error"){
pushcursor();
Size termsize=gettermsize();
@@ -29,7 +27,8 @@ void Manager::receive(const Command &cmd){
} else if(cmd[0]=="quit_app"){
should_quit=true;
} else {
- THROW("Unknown command");
+ if(activeIdx==-1)bel();
+ else buffers[activeIdx].receive(cmd);
}
}