Skip to content

Commit

Permalink
Handle :window_size message (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuqian Hon (SQ) authored and jjcarstens committed Nov 20, 2020
1 parent 8aa7112 commit 05be91c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/nerves_hub_link/console_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ defmodule NervesHubLink.ConsoleChannel do
{:noreply, state, iex_timeout()}
end

def handle_info(%Message{event: "window_size", payload: %{"height" => height, "width" => width}}, state) do
ExTTY.window_change(state.iex_pid, width, height)
{:noreply, state}
end

def handle_info(%Message{event: event, payload: payload}, state)
when event in ["phx_error", "phx_close"] do
reason = Map.get(payload, :reason, "unknown")
Expand Down
8 changes: 8 additions & 0 deletions test/nerves_hub_link/console_channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ defmodule NervesHubLink.ConsoleChannelTest do
assert new_state.iex_pid != state.iex_pid
end

test "window_size - sets width & height of ExTTY", %{state: state} do
{:ok, iex_pid} = ExTTY.start_link(handler: self(), type: :elixir)
state = %{state | iex_pid: iex_pid}
msg = %Message{event: "window_size", payload: %{"height" => 200, "width" => 300}}

assert {:noreply, state} == ConsoleChannel.handle_info(msg, state)
end

test "dn - sends text to ExTTY", %{state: state} do
{:ok, iex_pid} = ExTTY.start_link(handler: self(), type: :elixir)
state = %{state | iex_pid: iex_pid}
Expand Down

0 comments on commit 05be91c

Please sign in to comment.