This shows you the differences between two versions of the page.
outputting_20text_20with_20word-wrap [2018/03/31 14:19] 127.0.0.1 external edit |
outputting_20text_20with_20word-wrap [2018/04/16 15:55] (current) richardrussell Added syntax highlighting |
||
---|---|---|---|
Line 1: | Line 1: | ||
=====Outputting text with word-wrap===== | =====Outputting text with word-wrap===== | ||
- | //by Richard Russell, August 2009//\\ \\ BBC BASIC (by default) automatically 'wraps' text that is output to the screen or the printer. If a character will not fit on the current line (or within the current text viewport) a 'new line' is generated and the character is displayed or printed at the beginning of the next line. The text viewport scrolls, or a new page is ejected from the printer, if necessary.\\ \\ Although this ensures that all text output is visible, it does often result in a word being split between two lines. It would usually be more desirable to perform a **word wrap**, that is if a character will not fit the entire word containing that character is moved to the next line. This is the kind of behaviour that a word processor usually has.\\ \\ The routines listed below implement word-wrap for text output to the screen or the printer. There are four procedures: **PROCww** outputs a string to the screen, **PROCvww** outputs a single character to the screen, **PROCwwp** outputs a string to the printer and **PROCvwwp** outputs a single character to the printer:\\ \\ | + | //by Richard Russell, August 2009//\\ \\ BBC BASIC (by default) automatically 'wraps' text that is output to the screen or the printer. If a character will not fit on the current line (or within the current text viewport) a 'new line' is generated and the character is displayed or printed at the beginning of the next line. The text viewport scrolls, or a new page is ejected from the printer, if necessary.\\ \\ Although this ensures that all text output is visible, it does often result in a word being split between two lines. It would usually be more desirable to perform a **word wrap**, that is if a character will not fit the entire word containing that character is moved to the next line. This is the kind of behaviour that a word processor usually has.\\ \\ The routines listed below implement word-wrap for text output to the screen or the printer. There are four procedures: **PROCww** outputs a string to the screen, **PROCvww** outputs a single character to the screen, **PROCwwp** outputs a string to the printer and **PROCvwwp** outputs a single character to the printer: |
+ | |||
+ | <code bb4w> | ||
PROCww(A$) : REM Equivalent to PRINT A$; | PROCww(A$) : REM Equivalent to PRINT A$; | ||
PROCvww(C%) : REM Equivalent to VDU C% | PROCvww(C%) : REM Equivalent to VDU C% | ||
PROCwwp(A$) : REM Equivalent to OSCLI "OUTPUT 15" : PRINT A$; : OSCLI "OUTPUT 0" | PROCwwp(A$) : REM Equivalent to OSCLI "OUTPUT 15" : PRINT A$; : OSCLI "OUTPUT 0" | ||
PROCvwwp(C%) : REM Equivalent to VDU 2,1,C%,3 | PROCvwwp(C%) : REM Equivalent to VDU 2,1,C%,3 | ||
- | Note that **PROCww** and **PROCwwp** do not output a newline after the string; to do that you must concatenate **CHR$13+CHR$10** to the end of the string (or output them separately using **PROCvww** or **PROCvwwp**).\\ \\ Here are the routines necessary to implement word-wrap:\\ \\ | + | </code> |
+ | |||
+ | Note that **PROCww** and **PROCwwp** do not output a newline after the string; to do that you must concatenate **CHR$13+CHR$10** to the end of the string (or output them separately using **PROCvww** or **PROCvwwp**).\\ \\ Here are the routines necessary to implement word-wrap: | ||
+ | |||
+ | <code bb4w> | ||
DEF PROCww(A$) | DEF PROCww(A$) | ||
LOCAL I% | LOCAL I% | ||
Line 60: | Line 66: | ||
ENDIF | ENDIF | ||
ENDPROC | ENDPROC | ||
- | Note that the usual restrictions caused by the use of **PRIVATE** apply. You must not attempt to resume execution if an error occurs (even an ESCape error) within the **PROCvww** or **PROCvwwp** routines. Ensure that any **ON ERROR** handler in your program aborts execution in such a case. | + | </code> |
+ | |||
+ | Note that the usual restrictions caused by the use of **PRIVATE** apply. You must not attempt to resume execution if an error occurs (even an ESCape error) within the **PROCvww** or **PROCvwwp** routines, unless you execute a **RESTORE LOCAL** as part of your error handler. Ensure that any **ON ERROR** handler in your program aborts execution in such a case. |