Skip to content

Commit

Permalink
move all rendering to module
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklanng committed Mar 22, 2024
1 parent 0a8bf72 commit a04d7a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
54 changes: 27 additions & 27 deletions src/telnet/render.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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 =
Expand All @@ -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")
}
3 changes: 0 additions & 3 deletions src/telnet/states/states.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a04d7a0

Please sign in to comment.