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
2 changes: 2 additions & 0 deletions src/GMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export
Date, DateTime, Year, Month, Week, Day, Hour, Minute, Second, year, month, week, day, hour, minute, second, now, today,
bissextile,

prettytable,

@?, @G, @dir

include("common_docs.jl")
Expand Down
26 changes: 7 additions & 19 deletions src/PrettyTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# and no longer need a > 10 MB PT precomp cache DLL.
############################################################################################

export pretty_table
#export pretty_table

#const _REGEX_ANSI_SEQUENCES = r"\x1B(?:]8;;[^\x1B]*\x1B\\|[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])"

Expand Down Expand Up @@ -294,6 +294,8 @@ function pretty_table(@nospecialize(io::IO), @nospecialize(data::Any); header::U
return _print_table(io, pdata; header = pheader, kwargs...)
end

const prettytable = pretty_table # Alias

# --------------------------------------------------------------------------------
@kwdef struct TextFormat
up_right_corner::Char = '┐'
Expand Down Expand Up @@ -1040,13 +1042,7 @@ function _check_hline(ptable::ProcessedTable, hlines::Vector{Int}, body_hlines::
end

function _check_hline(ptable::ProcessedTable, hlines::Symbol, body_hlines::AbstractVector, i::Int)
if hlines == :all
return true
elseif hlines == :none
return _check_hline(ptable, Int[], body_hlines, i)
else
error("`hlines` must be `:all`, `:none`, or a vector of integers.")
end
return (hlines == :all) ? true : (hlines == :none) ? _check_hline(ptable, Int[], body_hlines, i) : error("`hlines` must be `:all`, `:none`, or a vector of integers.")
end

function _check_vline(ptable::ProcessedTable, vlines::AbstractVector, j::Int)
Expand All @@ -1064,13 +1060,7 @@ function _check_vline(ptable::ProcessedTable, vlines::AbstractVector, j::Int)
end

function _check_vline(ptable::ProcessedTable, vlines::Symbol, j::Int)
if vlines == :all
return true
elseif vlines == :none
return false
else
error("`vlines` must be `:all`, `:none`, or a vector of integers.")
end
return (vlines == :all) ? true : (vlines == :none) ? false : error("`vlines` must be `:all`, `:none`, or a vector of integers.")
end

function _count_hlines(ptable::ProcessedTable, hlines::Vector{Int}, body_hlines::Vector{Int})
Expand Down Expand Up @@ -2551,8 +2541,7 @@ function _print_custom_text_cell!(display::Display, cell_data::CustomTextCell, c
# Write it to the display.
_write_to_display!(display, rendered_str, suffix, new_lstr + textwidth(suffix))

# Print the padding character after the cell and return if the display has reached
# end-of-line.
# Print the padding character after the cell and return if the display has reached end-of-line.
return _p!(display, " ", false, 1)
end

Expand Down Expand Up @@ -2805,9 +2794,8 @@ function ProcessedTable(data::Any, header::Any;
elseif show_header
num_header_columns = length(first(header))

if num_data_columns != num_header_columns
(num_data_columns != num_header_columns) &&
error("The number of columns in the header ($num_header_columns) must be equal to that of the table ($num_data_columns).")
end

num_header_rows = show_subheader ? length(header) : 1
end
Expand Down
4 changes: 2 additions & 2 deletions src/proj_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,9 @@ function helper_geoglimits(prj::String, region::Vector{Float64})::Vector{Float64
Gdal.CPLPushErrorHandler(@cfunction(Gdal.CPLQuietErrorHandler, Cvoid, (UInt32, Cint, Cstring)))
opts = ["-s_srs", prj, "-t_srs", prj4WGS84, "-overwrite"]
ds = Gdal.get_gdaldataset([region[1] region[3]], opts, false)[1]
o1 = Gdal.gdalvectortranslate(ds, opts; dest="/vsimem/tmp", gdataset=true)
o1 = Gdal.gdalvectortranslate(ds, opts; dest="/vsimem/tmp", gdataset=true)::GMT.Gdal.IDataset
ds = Gdal.get_gdaldataset([region[2] region[4]], opts, false)[1]
o2 = Gdal.gdalvectortranslate(ds, opts; dest="/vsimem/tmp", gdataset=true)
o2 = Gdal.gdalvectortranslate(ds, opts; dest="/vsimem/tmp", gdataset=true)::GMT.Gdal.IDataset
if (o1.ptr == C_NULL || o2.ptr == C_NULL) # Diagonals failed, probably a Mollweide or alike projection
t = xy2lonlat([region[1] min(0,region[4]); region[2] min(0,region[4]);
0 region; 0 region], s_srs=prj, t_srs=prj4WGS84)
Expand Down
1 change: 1 addition & 0 deletions src/spatial_funs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ end
See `? getbyattrib`
"""
Base.:filter(D::Vector{<:GMTdataset}; kw...) = getbyattrib(D; kw...)

# ---------------------------------------------------------------------------------------------------
"""
findall(D::Vector{<:GMTdataset}; kw...)
Expand Down
5 changes: 3 additions & 2 deletions src/utils_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ does not need explicit coordinates to place the text.
- `segnan` or `nanseg`: Boolean. If true make a multi-segment made out of segments separated by NaNs.
- `datatype`: Keep the original data type of `mat`. Default converts to Float64.
- `geom`: The data geometry. By default, we set `wkbUnknown` but try to do some basic guess.
- `proj` or `proj4`: A proj4 string for dataset SRS.
- `wkt`: A WKT SRS.
- `proj` or `proj4`: A proj4 string for dataset SRS. Default is empty. To set it to lon,lat in WGS84 use ``proj=prj4WGS84``
- `wkt`: A WKT SRS string.
- `epsg`: An integer EPSG code. _e.g._ ``epsg=4326`` for lon,lat in WGS84. Default is 0.
- `colnames`: Optional string vector with names for each column of `mat`.
- `attrib`: Optional dictionary{String, String} with attributes of this dataset.
- `ref:` Pass in a reference GMTdataset from which we'll take the georeference info as well as `attrib` and `colnames`
Expand Down
44 changes: 22 additions & 22 deletions test/test_PT_alignments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data = Any[1 false 1.0 0x01 ;
│ 6 │ true │ 6.0 │ 6 │
└────────┴────────┴────────┴────────┘
"""
result = pretty_table(String, data; alignment = :l)
result = prettytable(String, data; alignment = :l)
@test result == expected

# == Center ============================================================================
Expand All @@ -42,7 +42,7 @@ data = Any[1 false 1.0 0x01 ;
│ 6 │ true │ 6.0 │ 6 │
└────────┴────────┴────────┴────────┘
"""
result = pretty_table(String, data; alignment = :c)
result = prettytable(String, data; alignment = :c)
@test result == expected

# == Per Column Configuration ==========================================================
Expand All @@ -59,7 +59,7 @@ data = Any[1 false 1.0 0x01 ;
│ 6 │ true │ 6.0 │ 6 │
└────────┴────────┴────────┴────────┘
"""
result = pretty_table(String, data; alignment = [:l, :r, :c, :r])
result = prettytable(String, data; alignment = [:l, :r, :c, :r])
@test result == expected

# == Cell Override =====================================================================
Expand All @@ -76,7 +76,7 @@ data = Any[1 false 1.0 0x01 ;
│ 6 │ true │ 6.0 │ 6 │
└────────┴────────┴────────┴────────┘
"""
result = pretty_table(
result = prettytable(
String,
data;
alignment = [:l, :r, :c, :r],
Expand Down Expand Up @@ -110,7 +110,7 @@ data = Any[1 false 1.0 0x01 ;
└───────────┴───────────┴───────────┴───────────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand Down Expand Up @@ -142,7 +142,7 @@ data = Any[1 false 1.0 0x01 ;
└───────────┴───────────┴───────────┴───────────┘
"""

result = pretty_table(
result = prettytable(
String, data;
header = header,
alignment = [:l, :r, :c, :r],
Expand Down Expand Up @@ -183,15 +183,15 @@ end
└────────────┴────────────┴──────────────┴──────────────┴────────────────┴────────────────┴────────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\."])
)

@test result == expected

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(i => [r"\."] for i in 1:7)
Expand All @@ -213,7 +213,7 @@ end
└───────────┴───────────┴─────────────┴─────────────┴───────────────┴───────────────┴───────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\.", r"^"])
Expand All @@ -237,7 +237,7 @@ end
└─────┴─────────┴─────────┴─────────┴─────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix,
alignment_anchor_regex = Dict(4 => [r"\.", r"^"]),
Expand All @@ -260,7 +260,7 @@ end
└─────┴───┴─────────┴─────────┴─────────┴─────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix,
alignment_anchor_regex = Dict(4 => [r"\.", r"^"]),
Expand All @@ -286,7 +286,7 @@ end
└─────────┴─────────┴─────────┴──────────────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(4 => [r"\.", r"^"]),
Expand All @@ -309,7 +309,7 @@ end
└─────────┴─────────┴─────────┴──────────────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment = :c,
Expand All @@ -333,7 +333,7 @@ end
└─────────┴─────────┴─────────┴──────────────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment = :l,
Expand All @@ -359,7 +359,7 @@ end
└─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┴─────────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(4 => [r"\.", r"^"]),
Expand All @@ -382,7 +382,7 @@ end
└─────────┴─────────┴─────────┴────────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(4 => [r"\.", r"^"]),
Expand All @@ -407,7 +407,7 @@ end
└──────────┴──────────┴───────────┴──────────┴────────────┴────────────┴────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(i => [r"\."] for i in 1:7),
Expand All @@ -430,7 +430,7 @@ end
└──────────────┴──────────────┴──────────────┴─────────────┴────────────┴───────────┴─────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(i => [r"\."] for i in 1:7),
Expand All @@ -453,7 +453,7 @@ end
└────────────┴──────────┴──────────────┴─────────────┴────────────────┴────────────────┴────────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\."]),
Expand All @@ -476,7 +476,7 @@ end
└──────────┴──────────┴───────────┴─────────────┴────────────────┴────────────┴────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\."]),
Expand All @@ -502,7 +502,7 @@ end
└─────┴──────────┴──────────┴───────────┴─────────────┴────────────────┴────────────┴────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\."]),
Expand All @@ -527,7 +527,7 @@ end
└───────┴──────────┴──────────┴───────────┴─────────────┴────────────────┴────────────┴────────────┘
"""

result = pretty_table(
result = prettytable(
String,
matrix;
alignment_anchor_regex = Dict(0 => [r"\."]),
Expand Down
16 changes: 8 additions & 8 deletions test/test_PT_column_width.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data = Any[1 false 1.0 0x01 ;
└──────┴───────┴──────┴──────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -53,7 +53,7 @@ data = Any[1 false 1.0 0x01 ;
└────┴────┴────┴────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -77,7 +77,7 @@ data = Any[1 false 1.0 0x01 ;
└────┴───────┴────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -100,7 +100,7 @@ data = Any[1 false 1.0 0x01 ;
└──────────┴──────────┴──────────┴──────────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -124,7 +124,7 @@ data = Any[1 false 1.0 0x01 ;
└───┴─────┴─────┴───┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -147,7 +147,7 @@ data = Any[1 false 1.0 0x01 ;
└───┴────┴─────┴──────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -171,7 +171,7 @@ data = Any[1 false 1.0 0x01 ;
└───┴─────┴────┴───┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand All @@ -194,7 +194,7 @@ data = Any[1 false 1.0 0x01 ;
└─────┴─────┴─────┴─────┘
"""

result = pretty_table(
result = prettytable(
String,
data;
header = header,
Expand Down
Loading
Loading