2 Commits

Author SHA1 Message Date
Alexander Heldt
4752ce418b Move render_layout to layout module 2025-11-30 11:53:27 +01:00
Alexander Heldt
df9160b932 Don't prefix internal modules 2025-11-30 11:53:25 +01:00
3 changed files with 24 additions and 21 deletions

View File

@@ -1,4 +1,7 @@
import gleam/dict
import gleam/list
import musicplayer/ui/internal
pub type Layout {
Layout(width: Int, height: Int, nodes: dict.Dict(Section, Node))
@@ -56,3 +59,14 @@ pub fn update_section(
pub fn update_dimensions(layout: Layout, width: Int, height: Int) -> Layout {
Layout(..layout, width:, height:)
}
pub fn render(layout: Layout, from: Section) -> Nil {
case dict.get(layout.nodes, from) {
Error(_) -> Nil
Ok(node) -> {
list.each(node.children, fn(child) { render(layout, child) })
internal.print_at(node.content, node.x, node.y)
}
}
}

View File

@@ -1,4 +1,3 @@
import gleam/dict
import gleam/erlang/process.{type Subject}
import gleam/int
import gleam/list
@@ -7,8 +6,8 @@ import gleam/string
import musicplayer/logging/logging
import musicplayer/ui/control.{type Control}
import musicplayer/ui/internal as ui_internal
import musicplayer/ui/layout.{type Layout, type Section}
import musicplayer/ui/internal
import musicplayer/ui/layout.{type Layout}
pub type State(redraw, content) {
State(redraw: Subject(Layout), layout: Layout)
@@ -36,8 +35,8 @@ pub fn new() -> Result(Subject(Control), String) {
process.spawn(fn() {
let assert Ok(_) = process.register(process.self(), redraw_name)
ui_internal.clear_screen()
ui_internal.hide_cursor()
internal.clear_screen()
internal.hide_cursor()
redraw_on_update_loop(redraw)
})
@@ -82,7 +81,7 @@ fn handle_message(
}
control.Exit(reply_to) -> {
ui_internal.show_cursor()
internal.show_cursor()
process.send(reply_to, Nil)
actor.stop()
}
@@ -92,14 +91,14 @@ fn handle_message(
fn redraw_on_update_loop(redraw: Subject(Layout)) -> Nil {
let layout = process.receive_forever(redraw)
ui_internal.clear_screen()
render_layout(layout, layout.Root)
internal.clear_screen()
layout.render(layout, layout.Root)
redraw_on_update_loop(redraw)
}
fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
case ui_internal.io_get_columns(), ui_internal.io_get_rows() {
case internal.io_get_columns(), internal.io_get_rows() {
Ok(width), Ok(height) -> {
process.send(ui, control.UpdateDimensions(width, height))
}
@@ -109,13 +108,3 @@ fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
process.sleep(interval_ms)
update_dimensions_on_interval(ui, interval_ms)
}
fn render_layout(layout: Layout, from: Section) -> Nil {
case dict.get(layout.nodes, from) {
Error(_) -> Nil
Ok(node) -> {
list.each(node.children, fn(child) { render_layout(layout, child) })
ui_internal.print_at(node.content, node.x, node.y)
}
}
}

View File

@@ -1,6 +1,6 @@
import gleeunit
import musicplayer/mpv/internal as control_internal
import musicplayer/mpv/internal
pub fn main() -> Nil {
gleeunit.main()
@@ -10,6 +10,6 @@ pub fn parse_playback_time_test() {
let json_string =
"{\"data\":\"123.456789\",\"request_id\":0,\"error\":\"success\"}\n"
let assert Ok(data) = control_internal.parse_playback_time(json_string)
let assert Ok(data) = internal.parse_playback_time(json_string)
assert data == 123.456789
}