Skip to content

Commit 921a343

Browse files
ST0008: orthogonalising output styling and formatting
1 parent 9225edb commit 921a343

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

lib/arca_cli/output.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ defmodule Arca.Cli.Output do
181181
_ -> determine_style(%Ctx{})
182182
end
183183
end
184-
end
184+
end

lib/arca_cli/output/fancy_renderer.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ defmodule Arca.Cli.Output.FancyRenderer do
7676
output
7777
|> Enum.map(&render_item/1)
7878
|> Enum.join("\n")
79+
7980
nil ->
8081
""
82+
8183
_ ->
8284
# Fallback for non-list output
8385
safe_to_string(ctx.output)
@@ -111,7 +113,9 @@ defmodule Arca.Cli.Output.FancyRenderer do
111113
defp render_item({:table, rows, opts}) do
112114
# Handle empty tables gracefully
113115
case rows do
114-
[] -> ""
116+
[] ->
117+
""
118+
115119
[_ | _] ->
116120
table_opts =
117121
Keyword.merge(

lib/arca_cli/output/plain_renderer.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ defmodule Arca.Cli.Output.PlainRenderer do
6969
|> Enum.map(&render_item/1)
7070
|> Enum.reject(&is_nil/1)
7171
|> Enum.intersperse("\n")
72+
7273
nil ->
7374
[]
75+
7476
other ->
7577
# Fallback for non-list output
7678
[safe_to_string(other)]

test/arca_cli/output_test.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defmodule Arca.Cli.OutputTest do
3838
{:warning, "Check logs"}
3939
]
4040
}
41+
4142
result = Output.render(ctx)
4243
assert result =~ "Starting"
4344
assert result =~ "Done"
@@ -75,7 +76,8 @@ defmodule Arca.Cli.OutputTest do
7576

7677
test "respects NO_COLOR environment variable" do
7778
System.put_env("NO_COLOR", "1")
78-
System.put_env("TERM", "xterm-256color") # Would normally trigger fancy
79+
# Would normally trigger fancy
80+
System.put_env("TERM", "xterm-256color")
7981

8082
assert Output.current_style() == :plain
8183
end
@@ -178,6 +180,7 @@ defmodule Arca.Cli.OutputTest do
178180
output: [{:success, "Test"}],
179181
meta: %{style: :fancy}
180182
}
183+
181184
result = Output.render(ctx)
182185

183186
# Fancy renderer should include colors if properly mocked
@@ -190,6 +193,7 @@ defmodule Arca.Cli.OutputTest do
190193
output: [{:success, "Test"}],
191194
meta: %{style: :plain}
192195
}
196+
193197
result = Output.render(ctx)
194198

195199
# Plain renderer returns iodata, should be converted to binary
@@ -202,6 +206,7 @@ defmodule Arca.Cli.OutputTest do
202206
ctx = %Ctx{
203207
output: [{:table, [%{name: "Alice", age: 30}], []}]
204208
}
209+
205210
result = Output.render(ctx)
206211

207212
assert result =~ "Alice"
@@ -212,6 +217,7 @@ defmodule Arca.Cli.OutputTest do
212217
ctx = %Ctx{
213218
output: [{:list, ["Item 1", "Item 2"], title: "Items"}]
214219
}
220+
215221
result = Output.render(ctx)
216222

217223
assert result =~ "Item 1"
@@ -308,4 +314,4 @@ defmodule Arca.Cli.OutputTest do
308314
# Helper to restore environment variables
309315
defp restore_env(key, nil), do: System.delete_env(key)
310316
defp restore_env(key, value), do: System.put_env(key, value)
311-
end
317+
end

0 commit comments

Comments
 (0)