📄 term.cc
字号:
void term::bs( u_int cursor ){ if( _col == 0 ) {// if( __here -> id_mask == ID_LINE_S ) return; // update to use (ctrl) if( _row == 0 ) return;// if( __here -> last == NULL ) return; // _row == 0 if( __here -> last -> length + __here -> length > cols ) return; if( _row-- == _orig ) _orig--; _here = ( u_int )( __here -> last ); _col = __here -> length; if( cursor == 0 ) repos( xcol, xrow - xorig ); del_line( cursor ); return; } // else __here -> del( _pcol = --_col ); for_each_cursor_right( _row, _col, &term::dec_col ); // # parameters ? if( cursor == 0 ) repos( xcol, xrow - xorig ); else if( _row > xorig + note::rows || _row < xorig ) return; repos( 0, _row - xorig ); int it = 0; for(; it < 10; it++ ) printf( " " ); fflush( stdout ); write( __here -> text, 0, _row - xorig ); repos( xcol, xrow - xorig );}void term::update_to_top( u_int cursor, line* brand, line* old_bot, line* new_bot, line* top, u_int it ){// update s -> bot// if( s -> bot == __here ) s -> bot = bot;// if( it == 0 ) return; // nothing holds this ++it; for(; it > 0; top = top -> last ) { --it; if( top -> id_mask == ID_LINE_S ) { if( ( ( line_s* )top ) -> scr -> top -> last == NULL ) continue; if( ( ( line_s* )top ) -> scr -> bot -> next == __here ) ( ( line_s* )top ) -> scr -> bot -> next = brand; if( ( ( line_s* )top ) -> scr -> bot == old_bot ) ( ( line_s* )top ) -> scr -> bot = new_bot; } }}/*int term::update_above( u_int cursor, line* brand, line* above, u_int it ){ if( it == 0 ) return 0; // nothing holds this// if( above == NULL ) return 0; // oops for(; it != ( u_int )-1; --it ) { if( above -> id_mask == ID_LINE_S ) { if( ( ( line_s* )above ) -> scr -> top -> last == NULL ) continue; if( ( ( line_s* )above ) -> scr -> bot -> next == __here ) break; } above = above -> last; } if( above != NULL && above -> id_mask == ID_LINE_S && ( ( line_s* )above ) -> scr -> bot -> next == __here ) { ( ( line_s* )above ) -> scr -> bot -> next = brand; } return it + 1;}*/line* term::find_top( u_int cursor, u_int& r ){ if( _row == 0 ) return NULL; // nothing holds this line* top = __here -> last,* here = NULL; for(; r > 0; top = top -> last ) { --r; if( top -> id_mask == ID_LINE_S ) { if( ( ( line_s* )top ) -> scr -> top == NULL ) // special case with del_line return top; if( ( ( line_s* )top ) -> scr -> top -> last == NULL ) continue; here = top -> next; for(; here != ( ( line_s* )top ) -> scr -> bot && here != __here; here = here -> next ); if( here == __here ) { return top; } } } return NULL;}/*//if( it == 0 ){printf( "******* " );fflush( stdout );if( ( ( line_s* )above ) == NULL ) printf( "null\r\n" );else printf( "\t%d\r\n", _row );fflush( stdout );exit( 1 );return 0;}*/void term::collapse( u_int cursor ){ u_int x = _row; line* top = __here,* here = __here; int b; if( __here -> id_mask != ID_LINE_S ) { top = find_top( cursor, x ); b = _row - x; } else { if( ( ( line_s* )__here ) -> scr -> top -> last == NULL ) return; here = here -> next;// --rows; b = 1; } if( top == NULL ) return; _row = x; for(; here != ( ( line_s* )top ) -> scr -> bot; ++b ) { here = here -> next; if( here == NULL ) { printf( "******** %d %d\r\n", _row, b ); fflush( stdout ); return; } } if( _row > 0 ) { update_to_top( cursor, top, here, top, top -> last, _row - 1 ); } if( here -> next != NULL ) { here -> next -> last = top; if( here -> next -> id_mask == ID_LINE_S && ( ( line_s* )( here -> next ) ) -> scr -> top -> last != NULL ) ( ( line_s* )( here -> next ) ) -> scr -> top -> last = top; } top -> next = here -> next; here -> next = NULL; ( ( line_s* )top ) -> scr -> top -> last = NULL; _here = ( u_int )top; if( here == s -> bot ) s -> bot = __here;// s -> bot = ( ( line_s* )__here ) -> scr -> bot; int level = _row < note::rows - 1 ? note::rows - 1 : _row; // max for(; b > 0; --b, --rows ) { for_each_cursor_below( level, &term::dec_orig ); // fix: adapt to vary for_each_cursor_below( _row, &term::dec_row ); }// adjust _pcol, _col if( cursor != 0 // if _row == xorig, visible text was merged && ( _row >= xorig + note::rows || ( xrow > level && _row < xorig ) ) ) return;// printf( "%08X %08X %08X %d %d \r\n", ( u_int )x_here -> last, xhere// , ( u_int )x_here -> next, _row, rows ); redraw();}// note for del_line: update each _here before s -> del// for_each_cursor_here( _row, __here -> last -> length,// &term::cursor_lbs ); // does row--extern void _s();// void(vector::* v)( void* ) );void segv( int signal );int term::del_line_s( line_s* top ){ int r = 0; script* _s = top -> scr; line* lit = top -> next; if( lit == _s -> top ) // expanded for(; lit != _s -> bot -> next; ) { line* _lit; if( lit -> id_mask == ID_LINE_S ) { _lit = ( ( line_s* )lit ) -> scr -> bot -> next; r += del_line_s( ( line_s* )lit ); } else { _lit = lit -> next;// delete lit; s -> del( lit ); --rows; ++r; } lit = _lit; }// delete ( line_s* )top; s -> del( top ); --rows; return ++r;}#ifdef debug_flag#define del_line_top printf( "\r\ntop " ); debug();#define del_line_mid printf( "mid " ); debug();#define del_line_entry printf( "entry " ); debug();#define del_line_t printf( "t %d %d %d\r\n", b, _row, x ); fflush( stdout );#define del_line_ft printf( "ft %d %d %d\r\n", b, _row, x ); fflush( stdout );#define del_line_dl \ printf( "dl %d %d %d rows %d\r\n", b, _row, x, rows ); fflush( stdout );#define del_line_tst printf( "tst %d %d %d\r\n", b, _row, x );fflush( stdout );#define del_line_end printf( "end " ); debug(); \{printf( "%d %d %d %08X\r\n", b, _row, x, _here ); fflush( stdout ); debug();}#else#define del_line_top#define del_line_mid#define del_line_entry#define del_line_t#define del_line_ft#define del_line_dl#define del_line_tst#define del_line_end#endif // debugvoid term::del_line( u_int cursor ){ if( _row == rows - 1 ) return; int b = 1; // lines to delete bool exp_check = false; if( __here -> id_mask == ID_LINE_S // complex replacement procedure && ( ( line_s* )__here ) -> scr -> top == __here -> next ) // is expanded { exp_check = true; if( __here -> next == ( ( line_s* )__here ) -> scr -> bot // one line || ( __here -> next -> id_mask == ID_LINE_S && ( ( line_s* )( __here -> next ) ) -> scr -> bot == ( ( line_s* )__here ) -> scr -> bot ) ) { line* here = new line( __here ); // here is no longer here, has moved if( __here -> last != NULL ) { __here -> last -> next = here; if( __here -> last -> id_mask == ID_LINE_S && ( ( line_s* )( __here -> last ) ) -> scr -> top == __here ) ( ( line_s* )( __here -> last ) ) -> scr -> top = here; } if( _row > 0 ) //&& top != NULL update_to_top( cursor, here, __here, here , __here -> last, _row - 1 ); if( here -> next != NULL ) { here -> next -> last = here; } if( _row == 0 ) s -> top = here; delete ( line_s* )__here; _here = ( u_int )here; } } line* here = __here -> next; // the bottom line to delete if( here -> id_mask == ID_LINE_S ) {// return; // update to use (ctrl) if( ( ( line_s* )here ) -> scr -> top -> last != NULL ) { line* bot = ( ( line_s* )here ) -> scr -> bot; here = here -> next; for( ++b; here != bot; ++b ) { here = here -> next; } } //for_each_cursor_here( _row + 1, _col, &term::cursor_lbs ); // be inclusive of other cursors, to _row + b } else // ordinary line { for_each_cursor_here( _row + 1, _col, &term::cursor_lbs ); if( !exp_check ) // expanded __here -> merge( _pcol = _col ); } if( __here -> id_mask == ID_LINE_S // complex replacement procedure && ( ( line_s* )__here ) -> scr -> top == __here -> next ) // is expanded { ( ( line_s* )__here ) -> scr -> top = here -> next; } if( _row > 0 ) // what is brand if no line_s ? NULL { line* x = __here; _here = ( u_int )here; // replaced with here -> next or NULL if( here -> next == NULL ) update_to_top( cursor, NULL , here, x, x, _row ); else update_to_top( cursor, here -> next , here, here -> next, x, _row ); _here = ( u_int )x; } line* temp = __here; _row += b; u_int x = _row; _here = ( u_int )here; int level = _row < note::rows - 1 ? note::rows - 1 : _row; // max for(;;) // here not initialized within loop { if( b == 0 ) { break; } if( b > 1 && x > _row - b ) { line* top = find_top( cursor, x ); if( top == NULL ) x = _row - b; else if( x < _row && x > _row - b ) { _here = ( u_int )top; _row = x; if( __here -> last -> id_mask == ID_LINE_S // expanded && ( ( line_s* )( __here -> last ) ) -> scr -> top == __here ) { ( ( line_s* )( __here -> last ) ) -> scr -> top = NULL; } b -= del_line_s( ( line_s* )__here ); x = _row = x - 1; // move away from this top row _here = ( u_int )( __here -> last ); continue; } } if( __here == s -> bot ) s -> bot = temp; // the line above the deletion here = __here -> last; delete __here -> text; s -> del( __here ); --rows; --_row; level = _row < note::rows - 1 ? note::rows - 1 : _row; // max for_each_cursor_below( level, &term::dec_orig ); for_each_cursor_below( _row, &term::dec_row ); if( --b == 0 ) break; _here = ( u_int )here; } _here = ( u_int )temp; if( _row >= xorig + note::rows || ( xrow > level && _row < xorig ) ) return; redraw();}void term::del( u_int cursor ){ if( __here -> length == ( _pcol = _col ) ) { del_line( cursor ); return; } __here -> del( _col ); for_each_cursor_right( _row, _col, &term::dec_col ); if( _row >= xorig + note::rows || _row < xorig ) return; repos( 0, _row - xorig ); int it = 0; for(; it < 10; it++ ) printf( " " ); fflush( stdout ); write( __here -> text, 0, _row - xorig ); repos( xcol, xrow - xorig );}#include <stdio.h>char term::pipe( u_int cursor, register char c ){ if( __here -> length == cols ) return c; __here -> ins( _col, c ); for_each_cursor_right( _row, _col, &term::inc_col ); _pcol = ++_col; if( _row >= xorig + note::rows || _row < xorig ) return c; repos( 0, _row - xorig ); printf( "\x1B[k" ); // erase to eol fflush( stdout ); write( __here -> text, 0, _row - xorig ); repos( xcol, xrow - xorig ); return c;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -