Current section
Files
Jump to
Current section
Files
src/fabulous.erl
-module(fabulous).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([add_col/2, add_row/2, make_table/1]).
-export_type([table/0]).
-type table() :: {table,
list(binary()),
list(list(binary())),
integer(),
binary(),
binary()}.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 12).
-spec add_col(table(), binary()) -> table().
add_col(Tab, Col) ->
Column_ln = string:length(Col),
case Column_ln of
Ln when Ln > erlang:element(4, Tab) ->
erlang:error(#{gleam_error => panic,
message => <<"Cannot have column names longer than the max width. Column names don't get wrapped at this time."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"add_col"/utf8>>,
line => 16});
_ ->
nil
end,
{table,
lists:append(erlang:element(2, Tab), [Col]),
erlang:element(3, Tab),
erlang:element(4, Tab),
erlang:element(5, Tab),
erlang:element(6, Tab)}.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 104).
-spec to_length_list(list(binary()), list(integer())) -> list(integer()).
to_length_list(Array, Length_array) ->
case Array of
[First | Rest] ->
to_length_list(
Rest,
lists:append(Length_array, [string:length(First) + 2])
);
[] ->
Length_array
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 195).
-spec align_rows(binary(), list(list(binary())), integer()) -> list(list(binary())).
align_rows(Dir, Rows, Cell_width) ->
gleam@list:map(
Rows,
fun(Row) ->
gleam@list:map(
Row,
fun(Cell) ->
Cell_ln = string:length(Cell),
case Cell_ln of
Ln when Ln < Cell_width ->
Spaces_ln = Cell_width - Cell_ln,
Spaces = begin
_pipe = gleam@list:repeat(
<<" "/utf8>>,
Spaces_ln
),
gleam@string:join(_pipe, <<""/utf8>>)
end,
case string:lowercase(Dir) of
<<"left"/utf8>> ->
<<Cell/binary, Spaces/binary>>;
<<"right"/utf8>> ->
<<Spaces/binary, Cell/binary>>;
<<"center"/utf8>> ->
erlang:error(#{gleam_error => panic,
message => <<"Center Alignment not implemented yet."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_rows"/utf8>>,
line => 210});
_ ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid alignment direction provided."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_rows"/utf8>>,
line => 211})
end;
Ln@1 when Ln@1 =:= Cell_width ->
Cell;
_ ->
erlang:error(#{gleam_error => panic,
message => <<"At this point, the cell length should never be larger the the max cell width. Ensure to run the align function after wrapping rows."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_rows"/utf8>>,
line => 216})
end
end
)
end
).
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 223).
-spec align_columns(binary(), list(binary()), integer()) -> list(binary()).
align_columns(Dir, Cols, Cell_width) ->
gleam@list:map(
Cols,
fun(Col) ->
Col_ln = string:length(Col),
case Col_ln of
Ln when Ln < Cell_width ->
Spaces_ln = Cell_width - Col_ln,
Spaces = begin
_pipe = gleam@list:repeat(<<" "/utf8>>, Spaces_ln),
gleam@string:join(_pipe, <<""/utf8>>)
end,
case string:lowercase(Dir) of
<<"left"/utf8>> ->
<<Col/binary, Spaces/binary>>;
<<"right"/utf8>> ->
<<Spaces/binary, Col/binary>>;
<<"center"/utf8>> ->
erlang:error(#{gleam_error => panic,
message => <<"Center Alignment not implemented yet."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_columns"/utf8>>,
line => 236});
_ ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid alignment direction provided."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_columns"/utf8>>,
line => 237})
end;
Ln@1 when Ln@1 =:= Cell_width ->
Col;
_ ->
erlang:error(#{gleam_error => panic,
message => <<"At this point, the coloumn length should never be larger the the max cell width. Ensure that the max length of a column accounts for the the longest column name."/utf8>>,
module => <<"fabulous"/utf8>>,
function => <<"align_columns"/utf8>>,
line => 241})
end
end
).
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 279).
-spec split_to_rows(list(list(binary()))) -> list(list(binary())).
split_to_rows(Splitted_rows) ->
gleam@list:map(
Splitted_rows,
fun(Cell) ->
Cell_ln = erlang:length(Cell),
Sp_ln = erlang:length(Splitted_rows),
case Cell_ln < Sp_ln of
true ->
Short_by = Sp_ln - Cell_ln,
lists:append(Cell, gleam@list:repeat(<<""/utf8>>, Short_by));
false ->
Cell
end
end
).
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 249).
-spec wrap_rows(list(list(list(binary()))), integer()) -> list(list(binary())).
wrap_rows(Splited_rows, Cols_ln) ->
_pipe = gleam@list:map(
Splited_rows,
fun(X) ->
Str = split_to_rows(X),
Rebo = gleam@list:transpose(Str),
gleam@list:map(
Rebo,
fun(R) ->
R_ln = erlang:length(R),
case R_ln < Cols_ln of
true ->
Spaces = gleam@list:repeat(
<<" "/utf8>>,
Cols_ln - R_ln
),
lists:append(Spaces, R);
_ ->
R
end
end
)
end
),
_pipe@1 = gleam@list:flatten(_pipe),
_pipe@2 = lists:reverse(_pipe@1),
gleam@list:filter(
_pipe@2,
fun(L) -> L /= gleam@list:repeat(<<""/utf8>>, erlang:length(L)) end
).
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 308).
-spec slice_string(binary(), list(binary()), integer()) -> list(binary()).
slice_string(S, Cell_list, Max_length) ->
Ln = string:length(S),
case Ln > Max_length of
true ->
slice_string(
gleam@string:slice(S, Max_length, Ln),
lists:append(Cell_list, [gleam@string:slice(S, 0, Max_length)]),
Max_length
);
false ->
lists:append(Cell_list, [gleam@string:slice(S, 0, Max_length)])
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 297).
-spec split_rows(list(list(binary())), integer()) -> list(list(list(binary()))).
split_rows(Rows, Max_length) ->
gleam@list:map(
Rows,
fun(Row) ->
gleam@list:map(
Row,
fun(Cell) -> slice_string(Cell, [], Max_length) end
)
end
).
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 24).
-spec add_row(table(), list(binary())) -> table().
add_row(Tab, Row) ->
Col_ln = erlang:length(erlang:element(2, Tab)),
case erlang:length(Row) of
Ln when Ln > Col_ln ->
erlang:error(#{gleam_error => panic,
message => (<<<<"Cannot have more cells than columns. Additonally, make sure to add columns first. Invlaid Row: ["/utf8,
(gleam@string:join(Row, <<", "/utf8>>))/binary>>/binary,
"]"/utf8>>),
module => <<"fabulous"/utf8>>,
function => <<"add_row"/utf8>>,
line => 29});
Ln@1 when Ln@1 < Col_ln ->
erlang:error(#{gleam_error => panic,
message => (<<<<"Cannot have less cells than columns. If you are want empty cells, include am empty string. Invlaid Row: ["/utf8,
(gleam@string:join(Row, <<", "/utf8>>))/binary>>/binary,
"]"/utf8>>),
module => <<"fabulous"/utf8>>,
function => <<"add_row"/utf8>>,
line => 30});
_ ->
nil
end,
New_table = {table,
erlang:element(2, Tab),
lists:append(erlang:element(3, Tab), [Row]),
erlang:element(4, Tab),
erlang:element(5, Tab),
erlang:element(6, Tab)},
Line_str = gleam@string:join(
gleam@list:repeat(<<"─"/utf8>>, erlang:element(4, Tab)),
<<""/utf8>>
),
{table,
erlang:element(2, Tab),
lists:append(
erlang:element(3, New_table),
[gleam@list:repeat(Line_str, Col_ln)]
),
erlang:element(4, Tab),
erlang:element(5, Tab),
erlang:element(6, Tab)}.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 124).
-spec make_top_line_section(integer(), binary()) -> binary().
make_top_line_section(Length, Output) ->
case Length of
0 ->
<<Output/binary, "┬"/utf8>>;
_ ->
make_top_line_section(Length - 1, <<Output/binary, "─"/utf8>>)
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 116).
-spec make_top_line(list(integer()), binary()) -> binary().
make_top_line(Array, Output) ->
case Array of
[First | Rest] ->
make_top_line(Rest, make_top_line_section(First, Output));
[] ->
Output
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 144).
-spec make_bottom_line_section(integer(), binary()) -> binary().
make_bottom_line_section(Length, Output) ->
case Length of
0 ->
<<Output/binary, "┴"/utf8>>;
_ ->
make_bottom_line_section(Length - 1, <<Output/binary, "─"/utf8>>)
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 137).
-spec make_bottom_line(list(integer()), binary()) -> binary().
make_bottom_line(Array, Output) ->
case Array of
[First | Rest] ->
make_bottom_line(Rest, make_bottom_line_section(First, Output));
[] ->
Output
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 164).
-spec make_column_line_section(integer(), binary()) -> binary().
make_column_line_section(Length, Output) ->
case Length of
0 ->
<<Output/binary, "┼"/utf8>>;
_ ->
make_column_line_section(Length - 1, <<Output/binary, "─"/utf8>>)
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 157).
-spec make_column_line(list(integer()), binary()) -> binary().
make_column_line(Array, Output) ->
case Array of
[First | Rest] ->
make_column_line(Rest, make_column_line_section(First, Output));
[] ->
Output
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 132).
-spec make_top_border(binary()) -> binary().
make_top_border(Line) ->
<<<<"╭"/utf8, (gleam@string:drop_end(Line, 1))/binary>>/binary, "╮"/utf8>>.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 151).
-spec make_bottom_border(binary()) -> binary().
make_bottom_border(Line) ->
<<<<"╰"/utf8, (gleam@string:drop_end(Line, 1))/binary>>/binary, "╯"/utf8>>.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 176).
-spec print_entry(list(binary()), binary()) -> nil.
print_entry(Array, Final) ->
case Array of
[] ->
gleam_stdlib:println(<<"│"/utf8, Final/binary>>);
[First | Rest] ->
print_entry(
Rest,
<<<<<<Final/binary, " "/utf8>>/binary, First/binary>>/binary,
" │"/utf8>>
)
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 184).
-spec print_rows(list(list(binary()))) -> nil.
print_rows(Rows) ->
case Rows of
[First | Rest] ->
print_rows(Rest),
print_entry(First, <<""/utf8>>);
[] ->
nil
end.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 171).
-spec make_column_border(binary()) -> binary().
make_column_border(Line) ->
<<<<"├"/utf8, (gleam@string:drop_end(Line, 1))/binary>>/binary, "┤"/utf8>>.
-file("C:\\Users\\River\\Desktop\\PROJECTS\\Gleam Projects\\fabulous\\src\\fabulous.gleam", 67).
-spec make_table(table()) -> nil.
make_table(Tab) ->
Aligned_cols = align_columns(
erlang:element(5, Tab),
erlang:element(2, Tab),
erlang:element(4, Tab)
),
Tb__char_length = to_length_list(Aligned_cols, []),
Col_ln = erlang:length(erlang:element(2, Tab)),
_pipe = make_top_line(Tb__char_length, <<""/utf8>>),
_pipe@1 = make_top_border(_pipe),
gleam_stdlib:println(_pipe@1),
print_entry(Aligned_cols, <<""/utf8>>),
_pipe@2 = make_column_line(Tb__char_length, <<""/utf8>>),
_pipe@3 = make_column_border(_pipe@2),
gleam_stdlib:println(_pipe@3),
_pipe@4 = wrap_rows(
split_rows(erlang:element(3, Tab), erlang:element(4, Tab)),
Col_ln
),
_pipe@5 = align_rows(
erlang:element(6, Tab),
_pipe@4,
erlang:element(4, Tab)
),
print_rows(_pipe@5),
_pipe@6 = make_bottom_line(Tb__char_length, <<""/utf8>>),
_pipe@7 = make_bottom_border(_pipe@6),
gleam_stdlib:println(_pipe@7).