From a04d7a0ba0db3395baeaa2bc7ceafbe0dc7a0fda Mon Sep 17 00:00:00 2001 From: Nick Lanng Date: Fri, 22 Mar 2024 02:46:26 +0000 Subject: [PATCH] move all rendering to module --- src/telnet/render.gleam | 54 +++++++++++++++++----------------- src/telnet/states/states.gleam | 3 -- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/telnet/render.gleam b/src/telnet/render.gleam index 9159e26..6080a34 100644 --- a/src/telnet/render.gleam +++ b/src/telnet/render.gleam @@ -7,6 +7,31 @@ import gleam/bytes_builder import glisten.{type Connection} import telnet/states/menu +pub fn logo(conn: Connection(_user_message)) { + menu.logo + |> center(80) + |> magenta + |> bold + |> println(conn) +} + +pub fn menu(conn: Connection(_user_message)) { + menu.menu + |> center(80) + |> println(conn) +} + +pub fn room_descripion(conn: Connection(_user_message), region, name, desc) { + region + |> string.append(" - ") + |> string.append(name) + |> string.append("\n") + |> bold + |> green + |> string.append(desc) + |> println(conn) +} + pub fn print(str: String, conn: Connection(_user_message)) { glisten.send( conn, @@ -16,7 +41,7 @@ pub fn print(str: String, conn: Connection(_user_message)) { ) } -pub fn println(str: String, conn: Connection(_user_message)) { +fn println(str: String, conn: Connection(_user_message)) { glisten.send( conn, str @@ -26,7 +51,7 @@ pub fn println(str: String, conn: Connection(_user_message)) { ) } -pub fn center(str: String, width: Int) -> String { +fn center(str: String, width: Int) -> String { let lines = string.split(str, "\n") let padding = @@ -47,31 +72,6 @@ pub fn center(str: String, width: Int) -> String { } } -pub fn logo(conn: Connection(_user_message)) { - menu.logo - |> center(80) - |> magenta - |> bold - |> println(conn) -} - -pub fn menu(conn: Connection(_user_message)) { - menu.menu - |> center(80) - |> println(conn) -} - -pub fn room_descripion(conn: Connection(_user_message), region, name, desc) { - region - |> string.append(" - ") - |> string.append(name) - |> string.append("\n") - |> bold - |> green - |> string.append(desc) - |> println(conn) -} - fn insert_carriage_returns(str: String) -> String { string.replace(str, "\n", "\n\r") } diff --git a/src/telnet/states/states.gleam b/src/telnet/states/states.gleam index eee9eb0..a812be1 100644 --- a/src/telnet/states/states.gleam +++ b/src/telnet/states/states.gleam @@ -56,9 +56,6 @@ pub fn on_enter(state: State) -> State { Menu(_, _, _) -> { let assert Ok(_) = render.logo(state.conn) let assert Ok(_) = render.menu(state.conn) - let assert Ok(_) = - "\n" - |> render.println(state.conn) state }