Compare commits
2 Commits
layout
...
4752ce418b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4752ce418b | ||
|
|
df9160b932 |
@@ -7,13 +7,9 @@ pub fn clear_screen() -> Nil {
|
|||||||
io.print("\u{001B}[2J\u{001B}[H")
|
io.print("\u{001B}[2J\u{001B}[H")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chars_at(chars: String, x: Int, y: Int) -> String {
|
pub fn print_at(text: String, x: Int, y: Int) -> Nil {
|
||||||
let seq = "\u{001B}[" <> int.to_string(y) <> ";" <> int.to_string(x) <> "H"
|
let seq = "\u{001B}[" <> int.to_string(y) <> ";" <> int.to_string(x) <> "H"
|
||||||
seq <> chars
|
io.print(seq <> text)
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print(chars: String) -> Nil {
|
|
||||||
io.print(chars)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide_cursor() -> Nil {
|
pub fn hide_cursor() -> Nil {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import gleam/dict
|
import gleam/dict
|
||||||
import gleam/list
|
import gleam/list
|
||||||
import gleam/string_tree.{type StringTree}
|
|
||||||
|
|
||||||
import musicplayer/ui/internal
|
import musicplayer/ui/internal
|
||||||
|
|
||||||
@@ -62,29 +61,12 @@ pub fn update_dimensions(layout: Layout, width: Int, height: Int) -> Layout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(layout: Layout, from: Section) -> Nil {
|
pub fn render(layout: Layout, from: Section) -> Nil {
|
||||||
string_tree.new()
|
|
||||||
|> render_loop(layout, from, _)
|
|
||||||
|> string_tree.to_string
|
|
||||||
|> internal.print
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render_loop(
|
|
||||||
layout: Layout,
|
|
||||||
from: Section,
|
|
||||||
into: StringTree,
|
|
||||||
) -> StringTree {
|
|
||||||
case dict.get(layout.nodes, from) {
|
case dict.get(layout.nodes, from) {
|
||||||
Error(_) -> into
|
Error(_) -> Nil
|
||||||
Ok(node) -> {
|
Ok(node) -> {
|
||||||
let parent =
|
list.each(node.children, fn(child) { render(layout, child) })
|
||||||
string_tree.append(
|
|
||||||
into,
|
|
||||||
internal.chars_at(node.content, node.x, node.y),
|
|
||||||
)
|
|
||||||
|
|
||||||
list.fold(node.children, parent, fn(into_acc, child) {
|
internal.print_at(node.content, node.x, node.y)
|
||||||
render_loop(layout, child, into_acc)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user