Created
April 2, 2026 13:11
-
-
Save mcnemesis/6a53c63dc1159e14ad287a44a92341e3 to your computer and use it in GitHub Desktop.
TEXT BEAUTIFIER is a basic TEA app for drawing nice customizable boxes around your text. It can be used to prepare messages, poetry, verses and greetings!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/tttt -fc | |
| v:vABOUT:{ | |
| ++--------------------++ | |
| + TEXT BEAUTIFIER v1 + | |
| ++--------------------++ | |
| + draws nice boxes | |
| + around your text! | |
| +----------------------+} | |
| ############################## | |
| # Architect: Fut. Prof. JWL | |
| # https://bit.ly/profjwl | |
| ############################## | |
| +---[CONSTANTS] | |
| v:vPROMPT_TEXT:{Please Enter|Type|Paste the text to be processed:} | |
| v:vNL:{ | |
| } | |
| +---[VARIABLES] | |
| v:vIN:{} # to hold main raw text | |
| #v:vTEXT:{} | |
| v:vTEXTBOX:{} | |
| v:vCORNER:{+} | |
| v:vHBAR:{-} | |
| v:vVBAR:{|} | |
| v:vNMAXLINE_LEN:26 | |
| v:vWRAPPED_TEXT:{} | |
| v:vIGNORE_EXTERNAL_TEXT:0 # effective if not 0 | |
| +---[PHASE 1: get text] | |
| l:lINTRO | |
| y:vABOUT | i: | |
| l:lPROMPT | |
| y:vIGNORE_EXTERNAL_TEXT | f!:0:lIGNORE_EXTERNAL_TEXT | |
| y*: | t!.: | v:vIN # external input text | |
| l:lIGNORE_EXTERNAL_TEXT | |
| # check if we already have text... | |
| y:vIN | f!:^$:lPROCESS_TEXT | |
| y:vPROMPT_TEXT | i: | t!.: | v:vIN | |
| f!:^$:lPROCESS_TEXT # re-check... | |
| j:lPROMPT | |
| +---[PHASE 2: re-format text] | |
| l:lPROCESS_TEXT | |
| # ensure we are starting frm scratch | |
| v:vWRAPPED_TEXT:{} | |
| y:vIN | |
| g.:=% # first, mask all new lines.. | |
| v:vIN | |
| # check if text exceeds max line size.. | |
| y!:vIN | v:vNTEXT_LEN | |
| g*:{>}:vNTEXT_LEN:vNMAXLINE_LEN | r.: | |
| f:true:lWRAP_TEXT:lNO_TEXT_WRAP_NEEDED | |
| # wrap long texts... | |
| l:lWRAP_TEXT | |
| v:vINDEX_LINE:0 | |
| y!:vIN | v:vIN_REMAINDER_LEN | |
| l:lSTART_WRAP | |
| # did we reach end of text yet? | |
| y:vIN_REMAINDER_LEN | x!:{<= 0} | r.: | |
| f:true:lFINISHED_WRAP | |
| # did we reach end of line yet? | |
| # (nl>0) && (nl%maxl==0)? | |
| v:vBO:(|v:vBE:) | |
| v:vG:{>0)&&(}|v:vMOD:{%}|v:vTEST_SUF:{==0} | |
| g*:{}:vBO:vINDEX_LINE:vG:vINDEX_LINE:vMOD:vNMAXLINE_LEN:vTEST_SUF:vBE | r.: | |
| f:true:lSTART_NEXT_LINE:lCONTINUE_LINE | |
| l:lSTART_NEXT_LINE | |
| g*:{}:vWRAPPED_TEXT:vNL | v:vWRAPPED_TEXT | |
| # advance indices... | |
| y:vINDEX_LINE | x!:{+1} | r.: | v:vINDEX_LINE | |
| l:lCONTINUE_LINE | |
| y:vIN | d!:^. | v:vCHAR # pop char | |
| y:vIN | r:.:{} | v:vIN # stash remainder.. | |
| g*:{}:vWRAPPED_TEXT:vCHAR | |
| #x:[|x!:]|q!: | |
| | v:vWRAPPED_TEXT | |
| # advance indices... | |
| y:vINDEX_LINE | x!:{+1} | r.: | v:vINDEX_LINE | |
| y!:vIN | v:vIN_REMAINDER_LEN | |
| # process next char... | |
| j:lSTART_WRAP | |
| i!: interlude | q!: | |
| l:lFINISHED_WRAP | |
| y:vWRAPPED_TEXT | |
| # reverse new-line masking... | |
| r!:{=%|=[\n]%}:{ | |
| } | |
| v:vWRAPPED_TEXT | |
| j:lPRESENT_TEXT | |
| +---[PHASE 3: present text] | |
| l:lNO_TEXT_WRAP_NEEDED | |
| # using available text as is! | |
| # ensure we actually have text... | |
| y:vIN | f:^$:lPROMPT | |
| y:vIN | v:vWRAPPED_TEXT | |
| l:lPRESENT_TEXT | |
| # show what we have and decide next step... | |
| v:vPRESENT_PROMPT:{DECIDE NEXT STEP: | |
| 1. Return Formatted Text as is | |
| 2. Proceed to Draw Text Box (default) | |
| +----------------------+ | |
| Formatted Text Follows... | |
| +----------------------+ | |
| } | |
| y:vPRESENT_PROMPT | x*!:vWRAPPED_TEXT | i: | t!.: | v:vOPT | |
| f!:^[12]$:lDRAW_TEXTBOX | |
| f!:^1$:lDRAW_TEXTBOX | |
| y:vWRAPPED_TEXT | q!: | |
| +---[PHASE 4: draw basic text-box] | |
| l:lDRAW_TEXTBOX | |
| #draw top and bottom border first... | |
| v:vBORDER_LINE:{} | |
| v:vNINDEX:0 | |
| l:lSTART_DRAW_BORDER | |
| y:vBORDER_LINE | x*!:vHBAR | v:vBORDER_LINE | |
| y:vNINDEX | x!:+1 | r. | v:vNINDEX | |
| y:vNINDEX | x!:> | x*!:vNMAXLINE_LEN | r.: | |
| f:true:lDONE_DRAW_BORDER | |
| j:lSTART_DRAW_BORDER | |
| l:lDONE_DRAW_BORDER | |
| y:vBORDER_LINE | v:vDECO_BORDER_LINE | |
| l:lPRESENT_BORDERED_TEXT | |
| # add it to the text... | |
| g*!:vNL:vDECO_BORDER_LINE:vWRAPPED_TEXT:vDECO_BORDER_LINE | |
| v:vTEXTBOX # store current text box | |
| # show what we have and decide next step... | |
| v:vPRESENT_PROMPT:{DECIDE NEXT STEP: | |
| 1. Return Text-Box as is | |
| 2. Customize Border Line (CORNERS) | |
| 3. Draw Complete Text Box (default) | |
| } | |
| y:vPRESENT_PROMPT | x*!:vTEXTBOX | i: | t!.: | v:vOPT | |
| f!:^[12]$:lDRAW_FULL_TEXTBOX | |
| f!:^1$:lCUSTOMIZE_BORDER | |
| y:vTEXTBOX | q!: | |
| +---[PHASE 5: draw custom text-box] | |
| l:lCUSTOMIZE_BORDER | |
| g*:{}:vCORNER:vBORDER_LINE:vCORNER | v:vDECO_BORDER_LINE | |
| i!:{CUSTOMIZE CORNERS: | |
| Current is (}| x*!:vCORNER | x!:{) to produce: | |
| } | x*!:vDECO_BORDER_LINE | |
| x!:{ | |
| OPTIONS: | |
| .LEAVE BLANK (preserves current corners) | |
| .ENTER VALUE (adopts your provided corner) | |
| } | |
| | v:vPRESENT_PROMPT | |
| y:vPRESENT_PROMPT | i: | v:vOPT | |
| f:^$:lPRESERVE_CORNER | |
| y:vOPT | |
| #| d!:^. #ensure we only keep 1 char for corner? | |
| | v:vCORNER | |
| g*:{}:vCORNER:vBORDER_LINE:vCORNER | v:vDECO_BORDER_LINE | |
| # first go see what it looks like | |
| j:lPRESENT_BORDERED_TEXT | |
| l:lPRESERVE_CORNER | |
| # then return to next option... | |
| l:lDRAW_FULL_TEXTBOX | |
| # first, get formatted, unbounded text | |
| y:vWRAPPED_TEXT | |
| # pad it as necessary?... | |
| #t.: | t.!: | v:vWRAPPED_TEXT | |
| # mask all new lines.. | |
| g.:=_=_=%_%_% # first, mask all new lines.. | |
| v:vTEMP_WTEXT | |
| # inject line delimiters... | |
| v:vREGEX_HEND:{=_=_=} | |
| v:vREGEX_HSTART:{%_%_%} | |
| v:vREGEX_START:{^} | |
| v:vREGEX_END:{$} | |
| v:vEMPTY:{} | |
| r*:vTEMP_WTEXT:vREGEX_START:vVBAR | v:vTEMP_WTEXT | |
| r*:vTEMP_WTEXT:vREGEX_END:vEMPTY | v:vTEMP_WTEXT | |
| # split em up... | |
| h*!:vTEMP_WTEXT:vREGEX_HEND | v:vTEMP_WTEXT | |
| # swap em... | |
| r*!:vTEMP_WTEXT:vREGEX_HSTART:vVBAR | v:vTEMP_WTEXT | |
| # we could also draw right vertical border | |
| # but for now, shall merely relax it... | |
| r*!:vTEMP_WTEXT:vREGEX_HEND:vEMPTY | v:vTEMP_WTEXT | |
| # add decor borders to the text... | |
| g*!:vNL:vDECO_BORDER_LINE:vTEMP_WTEXT:vDECO_BORDER_LINE | |
| v:vTEXTBOX # store current text box | |
| +---[PHASE 6: user configurations] | |
| l:lCUSTOMIZE_BEAUTIFIED_BORDER | |
| # show what we have and decide next step... | |
| v:vPRESENT_PROMPT:{DECIDE NEXT STEP: | |
| 1. Return Text-Box as is | |
| 2. Make Further Customizations (default) | |
| } | |
| y:vPRESENT_PROMPT | x*!:vTEXTBOX | i: | t!.: | v:vOPT | |
| f!:^[1]$:lPROMPT_CUSTOMIZATION_HBAR | |
| y:vTEXTBOX | q!: | |
| l:lPROMPT_CUSTOMIZATION_HBAR | |
| # first, construct current horizontal border... | |
| g*:{}:vCORNER:vBORDER_LINE:vCORNER | v:vDECO_BORDER_LINE | |
| i!:{CUSTOMIZE H-BAR: | |
| Current is (}| x*!:vHBAR | x!:{) to produce: | |
| } | x*!:vDECO_BORDER_LINE | |
| x!:{ | |
| OPTIONS: | |
| .LEAVE BLANK (preserves current h-bar) | |
| .ENTER VALUE (adopts your provided h-bar) | |
| } | |
| | v:vPRESENT_PROMPT | |
| y:vPRESENT_PROMPT | i: | v:vOPT | |
| f:^$:lPRESERVE_HBAR | |
| y:vOPT | |
| #| d!:^. #ensure we only keep 1 char for h-bar? | |
| | v:vHBAR_new | |
| # first integrate new customizations | |
| r*!:vBORDER_LINE:vHBAR:vHBAR_new | v:vBORDER_LINE | |
| # override old h-bar too | |
| y:vHBAR_new | v:vHBAR | |
| g*:{}:vCORNER:vBORDER_LINE:vCORNER | v:vDECO_BORDER_LINE | |
| l:lPRESERVE_HBAR | |
| # then go to next customization... | |
| l:lPROMPT_CUSTOMIZATION_VBAR | |
| # first, construct current vertical border... | |
| v:vTEMP_TEXT:{This is sample text...} | |
| g*:{}:vVBAR:vTEMP_TEXT | v:vDECO_SAMPLE_LINE | |
| i!:{CUSTOMIZE V-BAR: | |
| Current is (}| x*!:vVBAR | x!:{) to produce: | |
| } | x*!:vDECO_SAMPLE_LINE | |
| x!:{ | |
| OPTIONS: | |
| .LEAVE BLANK (preserves current v-bar) | |
| .ENTER VALUE (adopts your provided v-bar) | |
| } | |
| | v:vPRESENT_PROMPT | |
| y:vPRESENT_PROMPT | i: | v:vOPT | |
| f:^$:lPRESERVE_VBAR | |
| y:vOPT | |
| #| d!:^. #ensure we only keep 1 char for v-bar? | |
| | v:vVBAR_new | |
| # first integrate new customizations | |
| # override old v-bar too | |
| y:vVBAR_new | v:vVBAR | |
| l:lPRESERVE_VBAR | |
| # then go final presentations... | |
| +---[FINAL CUSTOMIZATIONS:] | |
| # show what we have and decide next step... | |
| v:vPRESENT_PROMPT:{DECIDE NEXT STEP: | |
| 1. Modify MAX Line Length | |
| 2. CHANGE the TEXT | |
| 3. Go Re-DRAW Text-Box (default) | |
| } | |
| y:vPRESENT_PROMPT | i: | t!.: | v:vOPT | |
| f!:^[12]$:lNO_FURTHER_CUSTOMIZATIONS | |
| y:vOPT | f!:^1$:lMODIFY_TEXT | |
| # customize max line length... | |
| l:lCUSTOMIZE_LINE_LENGTH | |
| i!:{CUSTOMIZE MAX LINE LEN: | |
| Current is (}| x*!:vNMAXLINE_LEN | x!:{) to produce: | |
| } | x*!:vBORDER_LINE | |
| x!:{ | |
| OPTIONS: | |
| .LEAVE BLANK (preserves current) | |
| .ENTER VALID NUMBER (adopts your provided) | |
| } | |
| | v:vPRESENT_PROMPT | |
| y:vPRESENT_PROMPT | i: | v:vOPT | |
| f:^$:lNO_FURTHER_CUSTOMIZATIONS | |
| y:vOPT | t!.: | v:vOPT | |
| f!:^[1-9][0-9]*$:lCUSTOMIZE_LINE_LENGTH | |
| y:vOPT | v:vNMAXLINE_LEN | |
| # return to processing text.. | |
| j:lPROCESS_TEXT | |
| # modifying text... | |
| l:lMODIFY_TEXT | |
| y:vOPT | f!:^2$:lNO_FURTHER_CUSTOMIZATIONS | |
| v:vIGNORE_EXTERNAL_TEXT:1 # so we force prompt | |
| v:vIN:{} # reset current text record | |
| # return to text prompt... | |
| j:lPROMPT | |
| l:lNO_FURTHER_CUSTOMIZATIONS | |
| # go see what it looks like | |
| j:lPRESENT_BORDERED_TEXT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment