diff options
| -rw-r--r-- | buffer.cpp | 27 | ||||
| -rw-r--r-- | buffer.h | 19 | ||||
| -rw-r--r-- | config.cpp | 3 | ||||
| -rw-r--r-- | manager.cpp | 40 | ||||
| -rw-r--r-- | manager.h | 2 | 
5 files changed, 74 insertions, 17 deletions
| @@ -16,6 +16,9 @@ using namespace std;  Buffer::Buffer(Manager *manager)  	:manager(manager){} +Buffer::Buffer(Manager *manager,bool singleLineMode) +	:manager(manager),singleLineMode(singleLineMode){} +  void Buffer::handleCommand(const Command &cmd){  	//TODO: optimise the relayoutScreen's in this function @@ -391,7 +394,7 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){  	static const Style textStyle={9,9,false,false};  	static const Style specialStyle={5,9,false,false}; -	i64 gutterWidth=numberWidth(tb.numLines())+2; +	i64 gutterWidth=singleLineMode ? 0 : numberWidth(tb.numLines())+2;  	i64 newWidth=width-gutterWidth;  	if(newWidth!=lastWidth||height!=lastHeight||screen.size()==0){  		if(lastWidth==-1)performInitialLayout(newWidth,height); @@ -408,14 +411,16 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){  	i64 curScreenX=-1,curScreenY=-1;  	// cerr<<"Buffer::show: screen.size()="<<screen.size()<<endl;  	for(y=0;y<(i64)screen.size();y++){ -		if(screen[y].fromx==0){ -			setstyle(&gutterStyle); -			moveto(atx+gutterWidth-1-numberWidth(screen[y].line+1),aty+y); -			tprintf("%" PRIi64,screen[y].line+1); -		} else if(y==0){ -			setstyle(&gutterContinuationStyle); -			moveto(atx+gutterWidth-2-numberWidth(screen[y].line+1),aty+y); -			tprintf("^%" PRIi64,screen[y].line+1); +		if(!singleLineMode){ +			if(screen[y].fromx==0){ +				setstyle(&gutterStyle); +				moveto(atx+gutterWidth-1-numberWidth(screen[y].line+1),aty+y); +				tprintf("%" PRIi64,screen[y].line+1); +			} else if(y==0){ +				setstyle(&gutterContinuationStyle); +				moveto(atx+gutterWidth-2-numberWidth(screen[y].line+1),aty+y); +				tprintf("^%" PRIi64,screen[y].line+1); +			}  		}  		moveto(atx+gutterWidth,aty+y); @@ -448,3 +453,7 @@ void Buffer::show(i64 atx,i64 aty,i64 width,i64 height){  		moveto(curScreenX,curScreenY);  	}  } + +string Buffer::getText() const { +	return tb.fullText(); +} @@ -13,9 +13,6 @@ using namespace std;  class Manager;  class Buffer{ -	TextBlob tb; -	Manager *manager; -  	struct Cell{  		char c;  		bool special; @@ -26,18 +23,25 @@ class Buffer{  		i64 fromx; //starting at what x into the line does this screen line have text  		vector<Cell> cells;  	}; -	vector<ScreenLine> screen; -	i64 lastWidth=-1,lastHeight=-1; //excluding the gutter  	struct Cursorpos{  		i64 line,x;  	}; -	Cursorpos cursor={0,0};  	struct Screenpos{  		i64 y,x;  	}; +	Manager *const manager; +	const bool singleLineMode=false; + +	TextBlob tb; + +	vector<ScreenLine> screen; +	i64 lastWidth=-1,lastHeight=-1; //excluding the gutter + +	Cursorpos cursor={0,0}; +  	vector<ScreenLine> layoutLine(const string &line,i64 linenum,i64 width);  	void performInitialLayout(i64 width,i64 height);  	void renewLayout(i64 topLine,i64 topPart,i64 width,i64 height); @@ -52,7 +56,10 @@ public:  	string filename;  	Buffer(Manager *manager); +	Buffer(Manager *manager,bool singleLineMode);  	void receive(const Command &cmd);  	void show(i64 atx,i64 aty,i64 width,i64 height); + +	string getText() const;  }; @@ -9,7 +9,8 @@ using namespace std;  KeyInputMachine global_keyinput({ -	{{KEY_CTRL+'X',KEY_CTRL+'Q'},{"quit_app"}}, +	{{KEY_CTRL+'Q'},{"quit_app"}}, +	{{KEY_ALT+';'},{"display_prompt"}},  	{{KEY_BACKSPACE},{"delete_backward"}},  	{{KEY_DELETE},{"delete_forward"}},  	{{'\n'},{"insert_newline"}}, diff --git a/manager.cpp b/manager.cpp index 951d84b..059a33f 100644 --- a/manager.cpp +++ b/manager.cpp @@ -19,13 +19,16 @@ void Manager::receive(const Command &cmd){  	} else if(cmd[0]=="error"){  		pushcursor();  		Size termsize=gettermsize(); -		moveto(0,termsize.h-1);  		Style errorStyle={1,9,true,false}; +		fillrect(0,termsize.h-1,termsize.w,1,' '); +		moveto(0,termsize.h-1);  		setstyle(&errorStyle);  		tprintf("%s",cmd[1].data());  		popcursor();  	} else if(cmd[0]=="quit_app"){  		should_quit=true; +	} else if(cmd[0]=="display_prompt"){ +		runPrompt();  	} else {  		if(activeIdx==-1)bel();  		else buffers[activeIdx].receive(cmd); @@ -151,3 +154,38 @@ int Manager::io(){  	return 0;  } + + +void Manager::runPrompt(){ +	Size termsize=gettermsize(); +	moveto(0,termsize.h-1); +	tputc(':'); + +	global_keyinput.cancel(); + +	string inputLine; +	Buffer promptBuffer(this,true); +	while(true){ +		termsize=gettermsize(); +		promptBuffer.show(1,termsize.h-1,termsize.w-1,1); +		redraw(); + +		int key=tgetkey(); + +		Either<bool,Command> ret=global_keyinput.input(key); +		if(ret.isLeft()){ +			if(!ret.fromLeft()){ +				bel(); +			} +		} else { +			if(ret.fromRight()[0]=="insert_newline"){ +				inputLine=promptBuffer.getText(); +				break; +			} else { +				promptBuffer.receive(ret.fromRight()); +			} +		} +	} + +	receive({"error",inputLine}); +} @@ -14,6 +14,8 @@ class Manager{  	i64 activeIdx;  	bool should_quit=false; +	void runPrompt(); +  public:  	Manager(); | 
