Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .committee.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ defmodule YourApp.Commit do
To test: `mix committee.runner [pre_commit | post_commit]`
"""
def pre_commit do
{_format_output, 0} = System.cmd("mix", ["format"] ++ staged_files([".ex", ".exs"]))
{_add_output, 0} = System.cmd("git", ["add"] ++ staged_files())
existing_staged_files = staged_files([".ex", ".exs"]) |> Enum.filter(&File.exists?(&1))

{_format_output, 0} = System.cmd("mix", ["format"] ++ existing_staged_files)
{_add_output, 0} = System.cmd("git", ["add"] ++ existing_staged_files)
{:ok, "SUCCESS!"}
end
end
23 changes: 23 additions & 0 deletions apps/xest/tui.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Counter do
@behaviour Ratatouille.App

import Ratatouille.View

def init(_context), do: 0

def update(model, msg) do
case msg do
{:event, %{ch: ?+}} -> model + 1
{:event, %{ch: ?-}} -> model - 1
_ -> model
end
end

def render(model) do
view do
label(content: "Counter is #{model} (+/-)")
end
end
end

Ratatouille.run(Counter)
4 changes: 4 additions & 0 deletions apps/xest_tui/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
27 changes: 27 additions & 0 deletions apps/xest_tui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
xest_tui-*.tar


# Temporary files for e.g. tests
/tmp
21 changes: 21 additions & 0 deletions apps/xest_tui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Xest.TUI

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `xest_tui` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:xest_tui, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/xest_tui](https://hexdocs.pm/xest_tui).

18 changes: 18 additions & 0 deletions apps/xest_tui/lib/xest/tui.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Xest.TUI do
@moduledoc """
Documentation for `Xest.TUI`.
"""

@doc """
Hello world.

## Examples

iex> Xest.TUI.hello()
:world

"""
def hello do
:world
end
end
20 changes: 20 additions & 0 deletions apps/xest_tui/lib/xest/tui/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Xest.TUI.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false

use Application

@impl true
def start(_type, _args) do
children = [
# TUI process
{Ratatouille.Runtime.Supervisor, runtime: [app: Xest.TUI.TUI]}
]

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Xest.TUI.Supervisor]
Supervisor.start_link(children, opts)
end
end
79 changes: 79 additions & 0 deletions apps/xest_tui/lib/xest/tui/tui.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
defmodule Xest.TUI.TUI do
@behaviour Ratatouille.App

alias Ratatouille.{EventManager, Window}
alias Ratatouille.Runtime.{Subscription, State}

require DateTime
import Ratatouille.View

alias Xest.BinanceExchange
alias Xest.Models

@impl true
def init(_context) do
{DateTime.utc_now(), 0, Xest.BinanceExchange.model(Xest.BinanceExchange)}
end

@impl true
def subscribe(_model) do
Subscription.interval(1_000, :tick)
end

@impl true
def update({now, counter, exchange}, msg) do
case msg do
{:event, %{ch: ?q}} ->
:ok = Window.close()

{:event, %{ch: ?+}} ->
{now, counter + 1, exchange}

{:event, %{ch: ?-}} ->
{now, counter - 1, exchange}

:tick ->
{DateTime.utc_now(), counter, exchange}

_ ->
IO.inspect(msg)
{now, counter, exchange}
end
end

# TODO : TUI design...

# Various windows:
# - HTTP requests (a nice log view)
# - websockets (a nice log view)
# - Events (from both rest polling and websockets, a debugging interface for commanded)
# - Exchange (model) State (from Events, but other untracked sources) - default view

@impl true
def render({now, counter, exchange}) do
view do
panel title: "Clock Example ('q' to quit)" do
label(content: "The time is: #{DateTime.to_string(now)}")
end

panel title: "Counter" do
label(content: "Counter is #{counter} (+/-)")
end

render_exchange(exchange)
end
end

defp render_exchange(%Models.Exchange{} = exchange) do
panel title: "Exchange" do
label(content: "code: #{exchange.status.code} ")
label(content: "status: #{exchange.status.message} ")
end
end

defp render_events() do
end

defp render_adapters() do
end
end
36 changes: 36 additions & 0 deletions apps/xest_tui/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Xest.TUI.MixProject do
use Mix.Project

def project do
[
app: :xest_tui,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.11",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {Xest.TUI.Application, []}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# TUI tooling
{:ratatouille, "~> 0.5.0"},
{:xest, in_umbrella: true}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
1 change: 1 addition & 0 deletions apps/xest_tui/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
8 changes: 8 additions & 0 deletions apps/xest_tui/test/xest/tui_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Xest.TUITest do
use ExUnit.Case
doctest Xest.TUI

test "greets the world" do
assert Xest.TUI.hello() == :world
end
end
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use Mix.Config
config :xest_web,
generators: [context_app: :xest]

config :xest_tui,
generators: [context_app: :xest]

# Configures the endpoint
config :xest_web, XestWeb.Endpoint,
url: [host: "localhost"],
Expand Down
4 changes: 0 additions & 4 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,3 @@ config :phoenix, :stacktrace_depth, 20

# clear screen when test_watch running again
config :mix_test_watch, clear: true

# to make sure we format before committing
# TODO : add credo and coveralls
config :pre_commit, commands: ["format"]