Input Text Area to Array then Reshape Table
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RozaniGhani-RG

//@version=5
indicator('Input Text Area to Array then Reshape Table', shorttitle = 'ITAtAtRT', overlay = true)

// 0 Input
// 1 String
// 2 Switch
// 3 Variable
// 4 Construct

// ————————————————————————————————————————————————————————————————————————————— 0 Input {
i_s_Y       = input.string('middle',        'Position ',       inline  = 'Position', group = 'Table', options = ['top',  'middle', 'bottom'])
i_s_X       = input.string('center',        '',                inline  = 'Position', group = 'Table', options = ['left', 'center', 'right'])
i_s_font    = input.string('normal',        'Font Size',       inline  = 'Font',     group = 'Table', options = ['tiny', 'small',  'normal', 'large', 'huge'])
i_b_reshape = input.bool(             true, 'Reshape Table',   inline  = 'Font',     group = 'Table', tooltip = 'true - vertical cells\n false - horizontal cells')
i_b_sort    = input.bool(            false, 'Sort',            inline  = 'Sort',     group = 'Table', tooltip = 'true - sort ascending\n false - sort descending')
i_c_border  = input.color(     color.black, 'Border',          inline  = 'Color',    group = 'Color')
i_c_bg      = input.color(    color.yellow, 'Cell',            inline  = 'Color',    group = 'Color')
i_c_text    = input.color(     color.black, 'Text',            inline  = 'Color',    group = 'Color')
i_ta_text   = input.text_area(   'A\nB\nC', 'Input your text', tooltip = 'Input your text then enter each line except for last line')
// }
// ————————————————————————————————————————————————————————————————————————————— 1 String {
_array      = str.split(         i_ta_text, '\n')
// }
// ————————————————————————————————————————————————————————————————————————————— 2 Switch {
[_columns, _rows] = switch i_b_reshape
    true  => [                 1, array.size(_array)]
    false => [array.size(_array),                  1]
switch i_b_sort
    true  => array.sort(_array, order.ascending)
    false => array.sort(_array, order.descending)
// }
// ————————————————————————————————————————————————————————————————————————————— 3 Variable {
var TableText = table.new(i_s_Y + '_' + i_s_X, _columns, _rows, i_c_bg, border_color = i_c_border, border_width = 1)
// }
// ————————————————————————————————————————————————————————————————————————————— 4 Construct {
if barstate.islast
    for _index = 0 to array.size(_array) - 1
        [_column, _row] = switch i_b_reshape
            true  => [0,     _index]
            false => [_index,     0]
        if array.size(_array) > _index
            table.cell(TableText, _column, _row, array.get(_array, _index), text_color = i_c_text, text_size = i_s_font)
// }
