Log dimension updates
This commit is contained in:
@@ -13,7 +13,7 @@ pub fn main() -> Nil {
|
||||
let input_keys_name: Name(Key) = process.new_name("input_keys")
|
||||
input.new(input_keys_name)
|
||||
|
||||
let assert Ok(ui) = ui.new()
|
||||
let assert Ok(ui) = ui.new(logger)
|
||||
let assert Ok(mpv) = mpv.new()
|
||||
let assert Ok(musicplayer_pid) =
|
||||
musicplayer.new(logger, ui, mpv, input_keys_name)
|
||||
|
||||
@@ -5,22 +5,30 @@ import gleam/list
|
||||
import gleam/otp/actor
|
||||
import gleam/string
|
||||
|
||||
import musicplayer/logging/control as logging_control
|
||||
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}
|
||||
|
||||
pub type State(redraw, content) {
|
||||
State(redraw: Subject(Layout), layout: Layout)
|
||||
State(
|
||||
logger: Subject(logging_control.Control),
|
||||
redraw: Subject(Layout),
|
||||
layout: Layout,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new() -> Result(Subject(Control), String) {
|
||||
pub fn new(
|
||||
logger: Subject(logging_control.Control),
|
||||
) -> Result(Subject(Control), String) {
|
||||
let redraw_name = process.new_name("redraw")
|
||||
let redraw: Subject(Layout) = process.named_subject(redraw_name)
|
||||
|
||||
let layout = layout.new()
|
||||
|
||||
case
|
||||
actor.new(State(redraw, layout))
|
||||
actor.new(State(logger, redraw, layout))
|
||||
|> actor.on_message(handle_message)
|
||||
|> actor.start
|
||||
{
|
||||
@@ -29,7 +37,7 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
Ok(actor.Started(data: ui, ..)) -> {
|
||||
process.spawn(fn() {
|
||||
let update_dimensions_interval_ms = 300
|
||||
update_dimensions_on_interval(ui, update_dimensions_interval_ms)
|
||||
update_dimensions_on_interval(logger, ui, update_dimensions_interval_ms)
|
||||
})
|
||||
|
||||
process.spawn(fn() {
|
||||
@@ -57,6 +65,11 @@ fn handle_message(
|
||||
case #(width, height) == current_dimensions {
|
||||
True -> actor.continue(state)
|
||||
False -> {
|
||||
[width, height]
|
||||
|> list.map(int.to_string)
|
||||
|> string.join(" ")
|
||||
|> string.append("ui - updating dimensions: ", _)
|
||||
|> logging.log(state.logger, _)
|
||||
|
||||
actor.continue(
|
||||
State(
|
||||
@@ -92,16 +105,20 @@ fn redraw_on_update_loop(redraw: Subject(Layout)) -> Nil {
|
||||
redraw_on_update_loop(redraw)
|
||||
}
|
||||
|
||||
fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
|
||||
fn update_dimensions_on_interval(
|
||||
logger: Subject(logging_control.Control),
|
||||
ui: Subject(Control),
|
||||
interval_ms: Int,
|
||||
) {
|
||||
case ui_internal.io_get_columns(), ui_internal.io_get_rows() {
|
||||
Ok(width), Ok(height) -> {
|
||||
process.send(ui, control.UpdateDimensions(width, height))
|
||||
}
|
||||
_, _ -> Nil
|
||||
_, _ -> logging.log(logger, "ui - failed to update dimensions")
|
||||
}
|
||||
|
||||
process.sleep(interval_ms)
|
||||
update_dimensions_on_interval(ui, interval_ms)
|
||||
update_dimensions_on_interval(logger, ui, interval_ms)
|
||||
}
|
||||
|
||||
fn render_layout(layout: Layout, from: Section) -> Nil {
|
||||
|
||||
Reference in New Issue
Block a user