Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document=> text-table change width when cell text is changed. #173

Closed
nielsnl68 opened this issue May 7, 2021 · 7 comments
Closed

document=> text-table change width when cell text is changed. #173

nielsnl68 opened this issue May 7, 2021 · 7 comments

Comments

@nielsnl68
Copy link

@cronvel , could you look at this changed example of the text-table-test,js file,
it should be expanded over the screen, and that works fine until the content of a column happens then the table shrink in size? does it not respect the autoWidth settings at that point anymore?


"use strict" ;



//console.error( "\n\n\n\n\n\n\n\n" ) ;
const termkit = require( '../..' ) ;
const term = termkit.terminal ;

term.clear() ;

var document = term.createDocument( {
	palette: new termkit.Palette()
	//	backgroundAttr: { bgColor: 'magenta' , dim: true } ,
} ) ;

var textTable = new termkit.TextTable( {
	parent: document ,
	cellContents: [
		//*
		[ ' header #1 ' , ' header #2 ' , ' header #3 ' ] ,
		[ 'row #1' , 'a much bigger cell ', 'cell' ] ,
		[ 'row #2' , 'cell' , 'a medium cell' ] ,
		[ 'row #3' , 'cell' , 'cell' ] ,
		[ 'row #4' , 'cell\ with new nlines' , 'cell' ]
		//*/
		/*
		[ '1-1' , '2-1' , '3-1' ] ,
		[ '1-2' , '2-2' , '3-2' ] ,
		[ '1-3' , '2-3' , '3-3' ]
		//*/
	] ,
	contentHasMarkup: true ,
	x: 0 ,
	y: 2 ,
	hasBorder: true ,
    borderChars: {
        vertical: '│',
        horizontal: '',
        topLeft: '',
        topRight: '',
        bottomLeft: '',
        bottomRight: '',
        topTee: '',
        bottomTee: '',
        leftTee: '│',
        rightTee: '│',
        cross: '│'
    },
	borderAttr: { color: 'white' } ,
	textAttr: { bgColor: 'default' } ,
	//textAttr: { bgColor: 'black' } ,
	//firstCellTextAttr: { bgColor: 'blue' } ,
    firstRowTextAttr: { bgColor: 'blue', color:"brightWhite" } ,
	//firstColumnTextAttr: { bgColor: 'red' } ,
	//checkerEvenCellTextAttr: { bgColor: 'gray' } ,
	//evenCellTextAttr: { bgColor: 'gray' } ,
    evenRowTextAttr: { bgColor: 'gray' } ,
	//evenColumnTextAttr: { bgColor: 'gray' } ,
    selectedTextAttr: { bgColor: 'blue' },
    selectable: 'cell',
	autoWidth: 1 ,
	//width: term.width ,
    height: 20,
   shrinkToHeight: true,
  //  shrinkToWidth: true,
    expandToWidth: true,
    wordWrap: true,
    lineWrap: true ,
	fit: false ,	// Activate all expand/shrink + wordWrap
	//expandToWidth: true , shrinkToWidth: true , expandToHeight: true , shrinkToHeight: true , wordWrap: true ,
	//lineWrap: true ,
} ) ;

 
setTimeout( () => {
	textTable.setCellContent( 2 , 3 , "New ^R^+content^:! And BTW... We have to force some line break and so on..." ) ;
} , 1000 ) ;
//*/

setTimeout( () => {
	//textTable.setCellAttr( 1 , 2 , { bgColor: 'cyan' } ) ;
	textTable.setRowAttr( 2 , { bgColor: 'cyan' } ) ;
	//textTable.setColumnAttr( 1 , { bgColor: 'cyan' } ) ;
	//textTable.setTableAttr( { bgColor: 'cyan' } ) ;
} , 500 ) ;

setTimeout( () => {
	//textTable.resetCellAttr( 1 , 2 ) ;
	textTable.resetRowAttr( 2 ) ;
	//textTable.resetColumnAttr( 1 ) ;
	//textTable.resetTableAttr() ;
} , 1500 ) ;


term.on( 'key' , function( key ) {
	switch( key ) {
		case 'CTRL_C' :
			term.grabInput( false ) ;
			term.hideCursor( false ) ;
			term.styleReset() ;
			term.clear() ;
			process.exit() ;
			break ;
	}
} ) ;

But offcource i could have set a wrong settings that i;m not aware off.
@nielsnl68
Copy link
Author

BTW one thing i love to see to this widget is the option to add and remove rows later like changing the content or attributes.

@cronvel
Copy link
Owner

cronvel commented May 8, 2021

@nielsnl68 When defining your own borderChars, everything should be exactly 1 character. Replace empty strings with a space.

cronvel added a commit that referenced this issue May 8, 2021
@cronvel
Copy link
Owner

cronvel commented May 8, 2021

@nielsnl68 I just added a check for that, now it default to 1 space when a border type is empty.

@cronvel cronvel closed this as completed May 8, 2021
@nielsnl68
Copy link
Author

Thanks, but did you also saw that the whole table resized when textTable.setCellContent( 2 , 3 , "New ^R^+content^:! And BTW... We have to force some line break and so on..." ) ; is executed. That was the main reason i shown you this, sorry i was not clear about that.

@cronvel
Copy link
Owner

cronvel commented May 8, 2021

@nielsnl68 nope, the whole table uses 100% width even after setting the content. However rows/columns are indeed resized depending on the content, and that's the intended behavior.

@nielsnl68
Copy link
Author

nielsnl68 commented May 8, 2021

This is what i get before and after the content change:
Before:
before change content
After:
after change content

@cronvel
Copy link
Owner

cronvel commented May 8, 2021

@nginth Ah, I missed the second bug hiding behind the first...
It should really work now, on v2.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants