Go CLI for generating an ASCII world map from a pre-generated PNG land mask.
Module path: github.com/Kivayan/map-ascii
go install github.com/Kivayan/map-ascii/cmd/map-ascii@latestThen run:
map-ascii --size 60 --supersample 3package main
import (
"fmt"
"log"
mapascii "github.com/Kivayan/map-ascii"
)
func main() {
mask, err := mapascii.LoadEmbeddedDefaultLandMask()
if err != nil {
log.Fatal(err)
}
out, err := mapascii.RenderWorldASCII(mask, 80, 3, 2.0, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)
}You can also load a PNG mask from disk with mapascii.LoadLandMask("path/to/mask.png").
For custom margin and optional framing:
options := &mapascii.RenderOptions{
VerticalMarginRows: 2,
Frame: true,
}
out, err := mapascii.RenderWorldASCIIWithOptions(mask, 80, 3, 2.0, nil, options)Render a geographic subset with a viewport bounding box:
options := &mapascii.RenderOptions{
Viewport: &mapascii.Viewport{
MinLon: -20,
MinLat: -36,
MaxLon: 53,
MaxLat: 38,
},
}
out, err := mapascii.RenderWorldASCIIWithOptions(mask, 80, 3, 2.0, nil, options)Use a built-in continent preset (library API):
viewport, err := mapascii.ViewportForContinent(string(mapascii.ContinentAfrica))
if err != nil {
log.Fatal(err)
}
options := &mapascii.RenderOptions{Viewport: &viewport}
out, err := mapascii.RenderWorldASCIIWithOptions(mask, 80, 3, 2.0, nil, options)List accepted continent names at runtime:
fmt.Println(mapascii.ContinentNames())
// [africa antarctica asia europe north-america south-america oceania]Stream animated frames with a callback (import context in your program):
animOptions := &mapascii.AnimationOptions{
FPS: 2,
Style: mapascii.AnimationStylePulseColor,
}
err = mapascii.StreamWorldASCIIAnimation(
context.Background(),
mask,
80,
3,
2.0,
&mapascii.Marker{Lon: -73.9857, Lat: 40.7484},
&mapascii.RenderOptions{ColorMode: "always"},
animOptions,
func(frame mapascii.Frame) error {
fmt.Print(frame.Text)
return nil
},
)Render to stdout:
go run ./cmd/map-ascii --size 60 --supersample 3Render to a file:
go run ./cmd/map-ascii --size 120 --supersample 3 --output out/world_120.txtUse a specific mask:
go run ./cmd/map-ascii --mask data/landmask_3600x1800.png --size 120Render a continent preset:
go run ./cmd/map-ascii --size 90 --continent africaRender a custom bounding box:
go run ./cmd/map-ascii --size 90 --bbox=-20,-36,53,38Render with no top/bottom margin and a frame:
go run ./cmd/map-ascii --size 80 --margin-y 0 --frameRender with forced terminal colors:
go run ./cmd/map-ascii --size 80 --frame --color always --map-color green --frame-color bright-white --marker-lon -73.9857 --marker-lat 40.7484 --marker-color bright-redAnimate a marker in the terminal (Ctrl+C to stop):
go run ./cmd/map-ascii --size 80 --frame --color auto --marker-lon -73.9857 --marker-lat 40.7484 --animate-marker --animate-style pulse-color --animate-fps 2Add a crosshair marker centered on a coordinate:
go run ./cmd/map-ascii --size 120 --marker-lon -73.9857 --marker-lat 40.7484Marker options:
--marker-center(defaultO)--marker-horizontal(default-)--marker-vertical(default|)--marker-arm-x(default-1, full width)--marker-arm-y(default-1, full map height)--marker-colormarker color name (16 ANSI colors)--animate-markeranimate marker output (TTY stdout only)--animate-fpsanimation refresh rate in frames per second (default2)--animate-styleanimation style:pulse-color,blink(defaultpulse-color)--animate-durationanimation duration (for example10s,2m);0runs until interrupted
--marker-lon and --marker-lat must be provided together.
--animate-marker requires marker coordinates and cannot be used with --output.
Color output targets ANSI 16-color terminals.
--colorcontrols color mode:never,auto,always(defaultauto)--map-colorsets the map color--frame-colorsets the frame color--marker-colorsets the marker color
When --color auto is used, color output is enabled only on terminals that look color-capable. If NO_COLOR is set, color is disabled.
Supported color names:
blackredgreenyellowbluemagentacyanwhitebright-blackbright-redbright-greenbright-yellowbright-bluebright-magentabright-cyanbright-white
--sizemap width in characters (default60)--supersampleN x Nsupersampling per character cell (default3)--char-aspectcharacter height/width ratio used to derive map height (default2.0)--margin-yempty rows above and below the map (outside the frame) (default2)--framedraw an ASCII frame around the output (defaultfalse)--colorcolor output mode:never,auto,always(defaultauto)--map-colormap color name (16 ANSI colors)--frame-colorframe color name (16 ANSI colors)--marker-colormarker color name (16 ANSI colors)--animate-markeranimate marker output (TTY stdout only)--animate-fpsanimation refresh rate in frames per second (default2)--animate-styleanimation style:pulse-color,blink(defaultpulse-color)--animate-durationanimation duration (0means until interrupted)--maskpath to a PNG land mask (optional; defaults to localdata/landmask_3600x1800.pngwith embedded fallback)--continentpreset viewport:africa,antarctica,asia,europe,north-america,south-america,oceania--bboxviewport bounding box asminLon,minLat,maxLon,maxLat--outputoptional output text file
- Expected mask alignment:
- x-axis maps lon
-180..180 - y-axis maps lat
90..-90
- x-axis maps lon
--continentand--bboxare mutually exclusive.--continent australiais accepted as an alias ofoceania.- By default output has 2 empty rows of top/bottom margin; use
--margin-yto change it. - Use
--frameto wrap the output in+---+and| |style borders.