Skip to content

Commit

Permalink
Ensure CLI results for rolling dice are printed as integers
Browse files Browse the repository at this point in the history
`IO.inspect` by default treats lists of integers as `charlists`. This
means certain integer combinations result in the list being printed as
`charlist`. This was rather confusing, as getting `~c"\a\n"` when
rolling `2d10` doesn't make much sense (`~c"\a\n"` == `[7, 10]`). To
force `IO.inspect` to read the list as a list of integers, we had to
pass `charlists: :as_lists` in the opts of the function.
  • Loading branch information
QMalcolm committed Nov 25, 2024
1 parent d9652a1 commit dc5714b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ defmodule ExTTRPGDev.CLI do
def handle_roll(%Optimus.ParseResult{args: %{dice: dice}}) do
dice
|> Dice.multi_roll!()
|> Enum.each(fn {dice_spec, results} -> IO.inspect(results, label: dice_spec) end)
|> Enum.each(fn {dice_spec, results} ->
IO.inspect(results, label: dice_spec, charlists: :as_lists)
end)
end

def handle_system_subcommands([command | subcommands], %Optimus.ParseResult{
Expand Down

0 comments on commit dc5714b

Please sign in to comment.