Paste #40454: Edit of P#40450 - Untitled Paste

Date: 2017/03/03 22:32:03 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


#--------------------------------------
#
#  Color Enabled Line Wrap Utility
#
# Turn a long string into a list of smaller strings and respects color codes
#
# Usage: <procedure[script:LineWrap_colored|string:string|length:10].return>
# Example: <procedure[script:LineWrap_colored|string:Hi <&[a]>i <&[b]>am a long <&[c]>string m8|length:10].return>
LineWrap_colored:
  type: procedure
  debug: minimal

  script:
    - define string '<context.string>'
    - define targetLen <context.length>
    - define line ''
    - define return <list[]>
    - define index 0
    - while <def[string].length.is_greater_than[0]>:
      - define index <def[index].add[1]>
      - define split '<def[string].index_of_cased[ ]>'
      - if <def[split]> == 0:
        - if <def[targetLen]> > <def[string].length>:
          - define split <def[string].length>
        - else:
          - define split <def[targetLen]>
      - define word '<def[string].substring[1|<def[split]>]>'
      - if <texts.for_old_colors[<def[line]><def[word]>].plain.length> <= <def[targetLen]>:
        - addto line parsed '<def[word]>'
        - define string '<def[string].after[<def[word]>]>'
      - else:
        - addto return list '<def[line]>'
        - define line ''
      - if <def[index]> == 50:
        - while stop
    - addto return list '<def[line]>'
    - echo <def[index]>
    - determine return <def[return]>
#
#  END Color Enabled Line Wrap Utility
#--------------------------------------
#
#  Line Wrap Utility
#
# Turn a long string into a list of smaller strings
#
# Usage: <procedure[script:LineWrap|string:string|length:10].return>
# Example: <procedure[script:LineWrap|string:Hi i am a long string m8|length:10].return>
LineWrap:
  type: procedure
  speed: 0
  debug: minimal

  script:
    - define string '<context.string>'
    - define stringLen <context.string.length>
    - define targetLen <context.length>
    - define increment 0
    - if <def[stringLen]> > <def[targetLen]>:
      - define lines '<list[]>'
      - while <def[stringLen].is_greater_than[0]>:
        - define low '<def[increment].add[1]>'
        - define hi '<def[increment].add[<def[targetLen]>]>'
        - define pass '<def[string].substring[<def[low]>|<def[hi]>]>'
        - if <def[pass].length> == <def[stringLen]>:
          - addto lines list '<def[pass]>'
          - while stop
        - else:
          - define brake '<def[pass].last_index_of_cased[ ]>'
          - define increment '<def[increment].add[<def[brake]>]>'
          - if <def[brake]> > 0:
            - define passtrim '<def[brake]>'
          - else:
            - define passtrim '<def[pass].length>'
          - define passtrim '<def[pass].substring[1|<def[passtrim]>]>'
          - addto lines list '<def[passtrim]>'
          - define stringLen '<def[stringLen].subtract[<def[brake]>]>'
      - determine return '<def[lines]>'
    - else:
      - determine return '<def[string]>'
#
#  END Line Wrap Utility
#--------------------------------------