diff options
author | Simponic <loganhunt@simponic.xyz> | 2023-01-02 19:10:23 -0700 |
---|---|---|
committer | Simponic <loganhunt@simponic.xyz> | 2023-01-02 19:10:23 -0700 |
commit | 16281b0e8deb6b3bf86ac0b9381f3fdf89b22b58 (patch) | |
tree | 80295ecaaad54c82ea1541d0932f8e8043f88515 /lib/chessh/ssh/renderers/menu.ex | |
parent | 2bf058d5db79cc75f87d9accfeb9773d5bf29686 (diff) | |
download | chessh-16281b0e8deb6b3bf86ac0b9381f3fdf89b22b58.tar.gz chessh-16281b0e8deb6b3bf86ac0b9381f3fdf89b22b58.zip |
Now a simple logo draws in the center of the terminal, terminal size is limited, and resizing support
Diffstat (limited to 'lib/chessh/ssh/renderers/menu.ex')
-rw-r--r-- | lib/chessh/ssh/renderers/menu.ex | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/chessh/ssh/renderers/menu.ex b/lib/chessh/ssh/renderers/menu.ex new file mode 100644 index 0000000..c3c3646 --- /dev/null +++ b/lib/chessh/ssh/renderers/menu.ex @@ -0,0 +1,35 @@ +defmodule Chessh.SSH.Client.Menu do + alias Chessh.SSH.Client.State + alias Chessh.Utils + + alias IO.ANSI + + @logo " Simponic's + + dP MP\"\"\"\"\"\"`MM MP\"\"\"\"\"\"`MM M\"\"MMMMM\"\"MM + 88 M mmmmm..M M mmmmm..M M MMMMM MM +.d8888b. 88d888b. .d8888b. M. `YM M. `YM M `M +88' `\"\" 88' `88 88ooood8 MMMMMMM. M MMMMMMM. M M MMMMM MM +88. ... 88 88 88. ... M. .MMM' M M. .MMM' M M MMMMM MM +`88888P' dP dP `88888P' Mb. .dM Mb. .dM M MMMMM MM + MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM" + + def render( + %State{width: width, height: height, state_stack: [_current_state | _tail]} = _state, + _args + ) do + {logo_width, logo_height} = Utils.text_dim(@logo) + + split = String.split(@logo, "\n") + + Enum.flat_map( + Enum.zip(0..(length(split) - 1), split), + fn {i, x} -> + [ + ANSI.cursor(div(height - logo_height, 2) + i, div(width - logo_width, 2)), + "#{x}\n" + ] + end + ) + end +end |