2013-07-18 22:56:05 +00:00
var blessed = require ( '../' )
2013-07-28 19:29:07 +00:00
, screen ;
screen = blessed . screen ( {
dump : _ _dirname + '/logs/widget.log'
} ) ;
2013-07-04 04:15:09 +00:00
2013-07-18 22:56:05 +00:00
screen . append ( blessed . text ( {
2013-06-06 09:03:25 +00:00
top : 0 ,
left : 2 ,
2013-06-13 09:14:14 +00:00
width : '100%' ,
2013-06-16 09:21:57 +00:00
//bg: 'blue',
content : '{green-fg}Welcome{/green-fg} to my {red-fg,ul}program{/red-fg,ul}' ,
2013-07-14 11:57:15 +00:00
bg : '#0000ff' ,
2013-07-23 10:04:04 +00:00
// bg: blessed.colors.match('#0000ff'),
2013-06-14 01:21:41 +00:00
tags : true ,
2013-06-13 09:14:14 +00:00
align : 'center'
2013-06-06 09:03:25 +00:00
} ) ) ;
2013-07-18 22:56:05 +00:00
screen . append ( blessed . line ( {
2013-06-06 09:03:25 +00:00
orientation : 'horizontal' ,
top : 1 ,
left : 0 ,
right : 0
} ) ) ;
2013-06-01 07:06:04 +00:00
/ *
2013-07-18 22:56:05 +00:00
screen . append ( blessed . box ( {
2013-06-01 07:06:04 +00:00
fg : 4 ,
bg : - 1 ,
2013-06-01 05:29:31 +00:00
border : {
type : 'ascii' ,
2013-06-01 07:06:04 +00:00
fg : - 1 ,
bg : - 1
2013-06-01 05:29:31 +00:00
} ,
content : 'Hello world!' ,
width : '50%' ,
height : '50%' ,
top : 'center' ,
left : 'center'
} ) ) ;
2013-07-18 22:56:05 +00:00
screen . children [ 0 ] . append ( blessed . box ( {
2013-06-01 07:06:04 +00:00
fg : 4 ,
bg : 3 ,
border : {
type : 'bg' ,
fg : 0 ,
bg : 1 ,
ch : '/'
} ,
content : 'Foobar' ,
width : '50%' ,
height : '50%' ,
top : 'center' ,
left : 'center'
} ) ) ;
* /
2013-07-18 22:56:05 +00:00
var list = blessed . list ( {
2013-06-13 09:14:14 +00:00
align : 'center' ,
2013-06-06 10:39:44 +00:00
mouse : true ,
2013-06-13 07:16:32 +00:00
fg : 'blue' ,
bg : 'default' ,
2013-06-01 07:06:04 +00:00
border : {
type : 'ascii' ,
2013-06-13 07:16:32 +00:00
fg : 'default' ,
bg : 'default'
2013-06-01 07:06:04 +00:00
} ,
width : '50%' ,
height : '50%' ,
top : 'center' ,
left : 'center' ,
2013-06-13 07:16:32 +00:00
selectedBg : 'green' ,
2013-06-01 07:06:04 +00:00
items : [
2013-06-03 03:29:26 +00:00
'one' ,
'two' ,
'three' ,
'four' ,
'five' ,
'six' ,
'seven' ,
'eight' ,
'nine' ,
'ten'
2013-07-19 06:57:17 +00:00
] ,
scrollbar : {
ch : ' ' ,
2013-07-27 11:58:50 +00:00
track : {
bg : 'yellow'
} ,
style : {
inverse : true
}
2013-07-19 06:57:17 +00:00
}
2013-06-06 09:03:25 +00:00
} ) ;
2013-06-01 07:06:04 +00:00
2013-06-06 09:03:25 +00:00
screen . append ( list ) ;
2013-06-09 13:33:23 +00:00
list . select ( 0 ) ;
2013-06-06 09:03:25 +00:00
2013-07-18 22:56:05 +00:00
list . prepend ( blessed . text ( {
2013-06-01 10:47:18 +00:00
left : 2 ,
content : ' My list '
} ) ) ;
2013-07-30 13:50:49 +00:00
if ( screen . autoPadding ) {
list . children [ 0 ] . rleft = - list . ileft + 2 ;
list . children [ 0 ] . rtop = - list . itop ;
}
2013-06-06 09:03:25 +00:00
list . on ( 'keypress' , function ( ch , key ) {
2013-06-09 13:33:23 +00:00
if ( key . name === 'up' || key . name === 'k' ) {
2013-06-06 09:03:25 +00:00
list . up ( ) ;
2013-06-01 10:47:18 +00:00
screen . render ( ) ;
return ;
2013-06-09 13:33:23 +00:00
} else if ( key . name === 'down' || key . name === 'j' ) {
2013-06-06 09:03:25 +00:00
list . down ( ) ;
2013-06-01 10:47:18 +00:00
screen . render ( ) ;
return ;
}
2013-06-06 09:03:25 +00:00
} ) ;
2013-07-18 22:56:05 +00:00
var progress = blessed . progressbar ( {
2013-06-13 07:16:32 +00:00
fg : 'blue' ,
bg : 'default' ,
barBg : 'default' ,
barFg : 'blue' ,
2013-06-06 09:03:25 +00:00
border : {
type : 'ascii' ,
2013-06-13 07:16:32 +00:00
fg : 'default' ,
bg : 'default'
2013-06-06 09:03:25 +00:00
} ,
ch : ':' ,
2013-06-12 09:18:47 +00:00
//orientation: 'vertical',
//height: 10,
//width: 3,
2013-06-06 09:03:25 +00:00
width : '50%' ,
height : 3 ,
right : 0 ,
bottom : 0 ,
filled : 50
} ) ;
screen . append ( progress ) ;
2013-06-06 12:57:50 +00:00
var lorem = 'Lorem ipsum \x1b[41mdolor sit amet, \nconsectetur adipisicing elit, \x1b[43msed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' ;
2013-06-06 09:03:25 +00:00
2013-06-10 01:41:25 +00:00
var lorem = require ( 'fs' ) . readFileSync ( _ _dirname + '/git.diff' , 'utf8' ) ;
2013-06-06 14:24:03 +00:00
2013-06-09 13:33:23 +00:00
//lorem = lorem.replace(/\x1b[^m]*m/g, '');
2013-07-18 22:56:05 +00:00
var stext = blessed . scrollabletext ( {
2013-06-14 00:02:02 +00:00
//padding: 1,
2013-06-06 10:39:44 +00:00
mouse : true ,
2013-06-06 09:03:25 +00:00
content : lorem ,
2013-06-13 07:16:32 +00:00
fg : 'blue' ,
2013-07-28 15:52:13 +00:00
bg : 'black' ,
2013-06-06 09:03:25 +00:00
border : {
type : 'ascii' ,
2013-06-13 07:16:32 +00:00
fg : 'default' ,
bg : 'default'
2013-06-06 09:03:25 +00:00
} ,
width : '50%' ,
2013-06-06 14:24:03 +00:00
//height: 4,
height : 6 ,
2013-06-06 09:03:25 +00:00
left : 0 ,
2013-07-21 10:31:24 +00:00
bottom : 0 ,
scrollbar : {
inverse : true
}
2013-06-06 09:03:25 +00:00
} ) ;
screen . append ( stext ) ;
stext . on ( 'keypress' , function ( ch , key ) {
2013-06-09 13:33:23 +00:00
if ( key . name === 'up' || key . name === 'k' ) {
2013-06-06 09:03:25 +00:00
stext . scroll ( - 1 ) ;
screen . render ( ) ;
return ;
2013-06-09 13:33:23 +00:00
} else if ( key . name === 'down' || key . name === 'j' ) {
2013-06-06 09:03:25 +00:00
stext . scroll ( 1 ) ;
screen . render ( ) ;
return ;
}
} ) ;
screen . on ( 'element focus' , function ( old , cur ) {
2013-07-16 22:50:02 +00:00
if ( old . border ) old . style . border . fg = 'default' ;
if ( cur . border ) cur . style . border . fg = 'green' ;
2013-06-06 09:03:25 +00:00
screen . render ( ) ;
} ) ;
2013-06-16 14:31:55 +00:00
/ *
screen . on ( 'element mouseover' , function ( el ) {
el . _bg = el . bg ;
el . bg = 1 ;
screen . render ( ) ;
} ) ;
screen . on ( 'element mouseout' , function ( el ) {
el . bg = el . _bg ;
screen . render ( ) ;
} ) ;
* /
2013-07-18 22:56:05 +00:00
var input = blessed . textbox ( {
2013-06-09 18:14:42 +00:00
mouse : true ,
2013-06-09 20:02:12 +00:00
label : ' My Input ' ,
2013-06-09 18:14:42 +00:00
content : '' ,
2013-06-13 07:16:32 +00:00
fg : 'blue' ,
bg : 'default' ,
barBg : 'default' ,
barFg : 'blue' ,
2013-06-09 18:14:42 +00:00
border : {
type : 'ascii' ,
2013-06-13 07:16:32 +00:00
fg : 'default' ,
bg : 'default'
2013-06-09 18:14:42 +00:00
} ,
width : '30%' ,
height : 3 ,
right : 0 ,
2013-07-29 20:49:25 +00:00
top : 2 ,
keys : true ,
vi : true ,
mouse : true
//inputOnFocus: true
2013-06-09 18:14:42 +00:00
} ) ;
2013-07-29 20:49:25 +00:00
input . on ( 'submit' , function ( value ) {
if ( value ) screen . children [ 0 ] . setContent ( value ) ;
2013-07-19 03:49:06 +00:00
input . clearInput ( ) ;
2013-07-29 20:49:25 +00:00
screen . render ( ) ;
2013-07-19 03:49:06 +00:00
} ) ;
2013-06-09 18:14:42 +00:00
screen . append ( input ) ;
2013-08-01 00:21:10 +00:00
var button = blessed . button ( {
2013-06-16 09:21:57 +00:00
//content: 'Click me!',
content : 'Click\nme!' ,
shrink : true ,
2013-08-01 00:21:10 +00:00
mouse : true ,
2013-06-16 09:21:57 +00:00
border : {
type : 'ascii'
} ,
fg : 'red' ,
bg : 'blue' ,
//height: 3,
right : 4 ,
//bottom: 6,
bottom : 2 ,
padding : 0
} ) ;
button . on ( 'press' , function ( ) {
button . setContent ( 'Clicked!' ) ;
2013-07-29 20:49:25 +00:00
screen . render ( ) ;
2013-06-16 09:21:57 +00:00
} ) ;
screen . append ( button ) ;
2013-06-09 18:14:42 +00:00
screen . on ( 'keypress' , function ( ch , key ) {
2013-06-06 09:03:25 +00:00
if ( key . name === 'tab' ) {
return key . shift
2013-07-29 20:49:25 +00:00
? screen . focusPrevious ( )
2013-06-06 09:03:25 +00:00
: screen . focusNext ( ) ;
}
2013-07-29 20:49:25 +00:00
//if (key.name === 'i') {
// return input.readInput(function(err, value) {
// ;
// });
//}
//if (key.name === 'e') {
// return input.readEditor(function(err, value) {
// ;
// });
//}
2013-06-01 05:29:31 +00:00
if ( key . name === 'escape' || key . name === 'q' ) {
2013-06-01 07:06:04 +00:00
return process . exit ( 0 ) ;
2013-06-01 05:29:31 +00:00
}
} ) ;
2013-07-14 15:06:28 +00:00
screen . key ( 'C-z' , function ( ) {
screen . sigtstp ( ) ;
} ) ;
2013-06-06 09:03:25 +00:00
list . focus ( ) ;
2013-06-01 05:29:31 +00:00
2013-06-09 20:21:58 +00:00
//screen.on('element click', function(el) {
// el.focus();
//});
2013-06-01 05:29:31 +00:00
screen . render ( ) ;
2013-06-06 09:03:25 +00:00
2013-06-06 10:38:30 +00:00
setInterval ( function ( ) {
2013-06-09 20:21:58 +00:00
progress . toggle ( ) ;
2013-06-09 16:47:02 +00:00
screen . render ( ) ;
2013-06-09 20:21:58 +00:00
} , 2000 ) ;
2013-06-06 10:38:30 +00:00
2013-06-06 09:03:25 +00:00
( function fill ( ) {
2013-06-09 19:32:29 +00:00
if ( progress . filled === 100 ) {
progress . reset ( ) ;
}
2013-06-06 09:03:25 +00:00
progress . progress ( 2 ) ;
screen . render ( ) ;
setTimeout ( fill , 300 ) ;
2013-06-11 14:09:57 +00:00
progress . top -= 2 ;
2013-06-06 09:03:25 +00:00
} ) ( ) ;