Skip to content
Merged
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
42 changes: 33 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
Expand All @@ -27,12 +25,12 @@ jobs:
name: Format/Credo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.18.0"
otp-version: "27.0.1"
elixir-version: "1.19"
otp-version: "28"
- name: Restore dependencies cache
uses: actions/cache@v3
with:
Expand All @@ -45,16 +43,42 @@ jobs:
run: mix format --check-formatted
- name: Run Credo
run: mix credo
dialyzer:
name: Dialyzer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.19"
otp-version: "28"
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Restore dialyzer cache
uses: actions/cache@v3
with:
path: priv/plts
key: ${{ runner.os }}-mix-plts-${{ hashFiles('./priv/plts/') }}
restore-keys: ${{ runner.os }}-mix-plts-
- name: Install dependencies
run: mix deps.get
- name: Run dialyzer
run: mix dialyzer
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.18.0"
otp-version: "27.0.1"
elixir-version: "1.19"
otp-version: "28"
- name: Restore dependencies cache
uses: actions/cache@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.18.0-otp-27
erlang 27.0.1
elixir 1.19.4-otp-28
erlang 28.2
35 changes: 21 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,49 @@

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.11.0 - 2024-08-31
## [Unreleased]

**Added**
### Added

- Better documented typespecs. ([#31](https://github.com/codedge-llc/scribe/pull/31))
- Full unit test coverage. ([#31](https://github.com/codedge-llc/scribe/pull/31))

## [0.11.0] - 2024-08-31

### Added

- Center and right text alignment options ([#16](https://github.com/codedge-llc/scribe/pull/16)).

**Changed**
### Changed

- Bumped minimum Elixir version to 1.13.

**Removed**
### Removed

- Removed `Scribe.auto_inspect/1`.
- Removed `Scribe.auto_inspect?/0`.

## v0.10.0 - 2019-05-29
## [0.10.0] - 2019-05-29

- Added `:device` option to `Scribe.print/2` for printing to a specific device.
Defaults to `:stdio`

## v0.9.0 - 2019-05-04
## [0.9.0] - 2019-05-04

- `NoBorder` style added.

## v0.8.2 - 2019-01-17
## [0.8.2] - 2019-01-17

- Support for Elixir `v1.8`

## v0.8.1 - 2018-07-25
## [0.8.1] - 2018-07-25

- Support for Elixir `v1.7`

## v0.8.0 - 2019-03-15
## [0.8.0] - 2019-03-15

- `:compile_auto_inspect` and `:auto_inspect` config options, both default
to `false`.
Expand All @@ -61,23 +68,23 @@ true again.
If auto-inspect is not compiled (or disabled), `Scribe.print/2` and similar
functions will continue to work as normal.

## v0.7.0 - 2018-02-19
## [0.7.0] - 2018-02-19

- Pseudographics style added.

## v0.6.0 - 2018-02-16
## [0.6.0] - 2018-02-16

- Overrides Inspect protocol for `List` and `Map`. These types will now
automatically return in Scribe's table format. Disabled by default.
with `config :scribe, enable: false` in your Mix config.
- `Scribe.enable`, `Scribe.disable`, and `Scribe.enabled?` added.
- Minimum Elixir version bumped to `1.5`.

## v0.5.1 - 2018-01-06
## [0.5.1] - 2018-01-06

- Bump pane dependency to v0.2.0.

## v0.5.0 - 2017-03-27
## [0.5.0] - 2017-03-27

- `@behaviour Scribe.Style` implemented (See `/style` for example adapters)
- Colorized output.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2024 Codedge LLC (https://www.codedge.io/)
Copyright (c) 2016-2026 Codedge LLC (https://www.codedge.io/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ Git commit subjects use the [Karma style](http://karma-runner.github.io/5.0/dev/

## License

Copyright (c) 2016-2024 Codedge LLC (https://www.codedge.io/)
Copyright (c) 2016-2026 Codedge LLC (https://www.codedge.io/)

This library is MIT licensed. See the [LICENSE](https://github.com/codedge-llc/scribe/blob/main/LICENSE) for details.
34 changes: 21 additions & 13 deletions lib/scribe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ defmodule Scribe do
- `:width` - Defines table width. Defaults to `:infinite`
"""
@type format_opts :: [
alignment: atom,
colorize: boolean,
alignment: atom(),
colorize: boolean(),
data: [...],
style: module,
width: integer
style: module(),
width: integer()
]

@doc ~S"""
Expand All @@ -177,21 +177,21 @@ defmodule Scribe do
+----------+---------+
:ok
"""
@spec print(data, format_opts) :: :ok
@spec print(data(), format_opts()) :: :ok
def print(_results, opts \\ [])

def print([], _opts), do: :ok

def print(results, opts) do
dev = opts |> Keyword.get(:device, :stdio)
results = results |> format(opts)
dev |> IO.puts(results)
dev = Keyword.get(opts, :device, :stdio)
results = format(results, opts)
IO.puts(dev, results)
end

@doc ~S"""
Paginates data and starts a pseudo-interactive console.
"""
@spec console(data, format_opts) :: no_return
@spec console(data(), format_opts()) :: :ok
def console(results, opts \\ []) do
results
|> format(opts)
Expand All @@ -216,7 +216,7 @@ defmodule Scribe do
+----------+---------+
%{test: 1234, key: :value}
"""
@spec inspect(data, format_opts) :: data
@spec inspect(data(), format_opts()) :: data()
def inspect(results, opts \\ []) do
print(results, opts)
results
Expand All @@ -233,7 +233,7 @@ defmodule Scribe do
iex> format(%{test: 1234}, colorize: false)
"+---------+\n| :test |\n+---------+\n| 1234 |\n+---------+\n"
"""
@spec format(data) :: String.t() | :ok
@spec format(data(), format_opts()) :: String.t() | :ok
def format(_results, opts \\ [])
def format([], _opts), do: :ok

Expand All @@ -251,24 +251,31 @@ defmodule Scribe do
Table.format(table, Enum.count(table), Enum.count(keys), opts)
end

@spec map_string_values([map()]) :: [term()]
defp map_string_values(keys), do: Enum.map(keys, &string_value(&1))

@spec map_string_values(map() | struct(), [map()]) :: [term()]
defp map_string_values(row, keys), do: Enum.map(keys, &string_value(row, &1))

@spec string_value(map()) :: term()
defp string_value(%{name: name, key: _key}) do
name
end

@spec string_value(map() | struct(), map()) :: term()
defp string_value(map, %{name: _name, key: key}) when is_function(key) do
map |> key.()
key.(map)
end

defp string_value(map, %{name: _name, key: key}) do
map |> Map.get(key)
Map.get(map, key)
end

@spec fetch_keys([map() | struct()], list() | nil) :: [map()]
defp fetch_keys([first | _rest], nil), do: fetch_keys(first)
defp fetch_keys(_list, opts), do: process_headers(opts)

@spec process_headers(list()) :: [map()]
defp process_headers(opts) do
for opt <- opts do
case opt do
Expand All @@ -278,6 +285,7 @@ defmodule Scribe do
end
end

@spec fetch_keys(map() | struct()) :: [map()]
defp fetch_keys(map) do
map
|> Map.keys()
Expand Down
52 changes: 26 additions & 26 deletions lib/scribe/border.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ defmodule Scribe.Border do
+--------+
```
"""
defstruct top_left_corner: "",
top_edge: "",
top_right_corner: "",
right_edge: "",
bottom_right_corner: "",
bottom_edge: "",
defstruct bottom_edge: "",
bottom_left_corner: "",
left_edge: ""
bottom_right_corner: "",
left_edge: "",
right_edge: "",
top_edge: "",
top_left_corner: "",
top_right_corner: ""

@type t :: %__MODULE__{
top_left_corner: String.t(),
top_edge: String.t(),
top_right_corner: String.t(),
right_edge: String.t(),
bottom_right_corner: String.t(),
bottom_edge: String.t(),
bottom_left_corner: String.t(),
left_edge: String.t()
bottom_right_corner: String.t(),
left_edge: String.t(),
right_edge: String.t(),
top_edge: String.t(),
top_left_corner: String.t(),
top_right_corner: String.t()
}

@doc ~S"""
Expand All @@ -40,27 +40,27 @@ defmodule Scribe.Border do

iex> new("+", "|", "-")
%Scribe.Border{
top_left_corner: "+",
top_edge: "-",
top_right_corner: "+",
right_edge: "|",
bottom_right_corner: "+",
bottom_edge: "-",
bottom_left_corner: "+",
left_edge: "|"
bottom_right_corner: "+",
left_edge: "|",
right_edge: "|",
top_edge: "-",
top_left_corner: "+",
top_right_corner: "+"
}
"""
@spec new(String.t(), String.t(), String.t()) :: t
@spec new(String.t(), String.t(), String.t()) :: t()
def new(corner, v_edge, h_edge) do
%__MODULE__{
top_left_corner: corner,
top_edge: h_edge,
top_right_corner: corner,
right_edge: v_edge,
bottom_right_corner: corner,
bottom_edge: h_edge,
bottom_left_corner: corner,
left_edge: v_edge
bottom_right_corner: corner,
left_edge: v_edge,
right_edge: v_edge,
top_edge: h_edge,
top_left_corner: corner,
top_right_corner: corner
}
end
end
Loading
Loading