@@ -32,12 +32,10 @@ if (!Blockly.Blocks)
3232Blockly . Blocks . console_print = {
3333 init : function ( ) {
3434 this . setColour ( colorPalette . getColor ( 'protocols' ) ) ;
35- this . appendDummyInput ( )
36- . appendField ( "Terminal print text" )
37- . appendField ( quotes . newQuote_ ( true ) )
38- . appendField ( new Blockly . FieldTextInput ( '' ) , 'TEXT' )
39- . appendField ( quotes . newQuote_ ( false ) ) ;
40-
35+ this . appendValueInput ( 'MESSAGE' )
36+ . setCheck ( 'String' )
37+ . appendField ( "Terminal print text" ) ;
38+ this . setInputsInline ( true ) ;
4139 this . setPreviousStatement ( true , null ) ;
4240 this . setNextStatement ( true , null ) ;
4341 }
@@ -47,27 +45,44 @@ Blockly.Blocks.console_print_variables = {
4745 init : function ( ) {
4846 this . setColour ( colorPalette . getColor ( 'protocols' ) ) ;
4947 this . appendValueInput ( 'VALUE' )
50- . appendField ( "Terminal print number" ) ;
51-
48+ . appendField ( "Terminal print number" ) ;
49+ this . appendDummyInput ( )
50+ . appendField ( "as" )
51+ . appendField ( new Blockly . FieldDropdown ( [
52+ [ 'Decimal' , 'DEC' ] ,
53+ [ 'Hexadecimal' , 'HEX' ] ,
54+ [ 'Binary' , 'BIN' ]
55+ ] ) , "FORMAT" ) ;
5256 this . setInputsInline ( true ) ;
5357 this . setPreviousStatement ( true , null ) ;
5458 this . setNextStatement ( true , null ) ;
5559 }
5660} ;
5761
58-
62+ // Terminal print text
5963Blockly . propc . console_print = function ( ) {
60- var text = this . getFieldValue ( 'TEXT' ) ;
64+ var text = Blockly . propc . valueToCode ( this , 'MESSAGE' , Blockly . propc . ORDER_ATOMIC ) ;
6165 Blockly . propc . serial_terminal_ = true ;
62-
63- return 'print("' + text + '");\n' ;
66+ return 'print(' + text + ');' ;
6467} ;
6568
6669Blockly . propc . console_print_variables = function ( ) {
67- var value = Blockly . propc . valueToCode ( this , 'VALUE' , Blockly . propc . ORDER_ATOMIC ) || '1000' ;
70+ // var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC) || '1000';
71+ var value = Blockly . propc . valueToCode ( this , 'VALUE' , Blockly . propc . ORDER_ATOMIC ) ;
72+ var format = this . getFieldValue ( 'FORMAT' ) ;
6873 Blockly . propc . serial_terminal_ = true ;
6974
70- return 'print("%d", ' + value + ');\n' ;
75+ var code = 'print(' ;
76+ if ( format === 'BIN' ) {
77+ code += '"%b"' ;
78+ } else if ( format === 'HEX' ) {
79+ code += '"%x"' ;
80+ } else {
81+ code += '"%d"' ;
82+ }
83+
84+ code += ', ' + value + ');' ;
85+ return code ;
7186} ;
7287
7388Blockly . Blocks . console_newline = {
@@ -120,38 +135,50 @@ Blockly.Blocks.console_move_to_row = {
120135 }
121136} ;
122137
123- Blockly . propc . console_newline = function ( ) {
124- Blockly . propc . serial_terminal_ = true ;
125- return 'print("\\r");' ;
138+ Blockly . Blocks . console_move_to_position = {
139+ init : function ( ) {
140+ this . setColour ( colorPalette . getColor ( 'protocols' ) ) ;
141+ this . appendDummyInput ( )
142+ . appendField ( "Terminal move to row" ) ;
143+ this . appendValueInput ( 'ROW' )
144+ . setCheck ( 'Number' ) ;
145+ this . appendDummyInput ( )
146+ . appendField ( "column" ) ;
147+ this . appendValueInput ( 'COLUMN' )
148+ . setCheck ( 'Number' ) ;
149+
150+ this . setInputsInline ( true ) ;
151+ this . setPreviousStatement ( true , null ) ;
152+ this . setNextStatement ( true , null ) ;
153+ }
126154} ;
127155
128- Blockly . propc . console_clear = function ( ) {
156+ Blockly . propc . console_newline = function ( ) {
129157 Blockly . propc . serial_terminal_ = true ;
130- return 'print("\\x10" );' ;
158+ return 'term_cmd(CR );' ;
131159} ;
132160
133- Blockly . propc . console_move_to_column = function ( ) {
134- var column = Blockly . propc . valueToCode ( this , 'COLUMNS' , Blockly . propc . ORDER_NONE ) ;
161+ Blockly . propc . console_clear = function ( ) {
135162 Blockly . propc . serial_terminal_ = true ;
136-
137- if ( Number ( column ) < 0 ) {
138- column = 0 ;
139- } else if ( Number ( column ) > 255 ) {
140- column = 255 ;
141- }
142-
143- return 'print("\\x0E%c", ' + column + ');' ;
163+ return 'term_cmd(CLS);' ;
144164} ;
145165
146- Blockly . propc . console_move_to_row = function ( ) {
147- var row = Blockly . propc . valueToCode ( this , 'ROWS' , Blockly . propc . ORDER_NONE ) ;
166+ Blockly . propc . console_move_to_position = function ( ) {
148167 Blockly . propc . serial_terminal_ = true ;
168+ var row = Blockly . propc . valueToCode ( this , 'ROW' , Blockly . propc . ORDER_NONE ) ;
169+ var column = Blockly . propc . valueToCode ( this , 'COLUMN' , Blockly . propc . ORDER_NONE ) ;
149170
150171 if ( Number ( row ) < 0 ) {
151172 row = 0 ;
152173 } else if ( Number ( row ) > 255 ) {
153174 row = 255 ;
154175 }
155176
156- return 'print("\\x0F%c", ' + row + ');' ;
177+ if ( Number ( column ) < 0 ) {
178+ column = 0 ;
179+ } else if ( Number ( column ) > 255 ) {
180+ column = 255 ;
181+ }
182+
183+ return 'term_cmd(CRSRXY, ' + column + ', ' + row + ');' ;
157184} ;
0 commit comments