Merge pull request #306 from nhooyr/textmeasure-ab94
Move textmeasure into lib
This commit is contained in:
commit
026959bc57
20 changed files with 57 additions and 33 deletions
|
|
@ -55,12 +55,14 @@ tput() {
|
||||||
|
|
||||||
should_color() {
|
should_color() {
|
||||||
if [ -n "${COLOR-}" ]; then
|
if [ -n "${COLOR-}" ]; then
|
||||||
if [ "$COLOR" = 0 -o "$COLOR" = false ]; then
|
if [ "$COLOR" = 1 -o "$COLOR" = true ]; then
|
||||||
_COLOR=
|
|
||||||
return 1
|
|
||||||
elif [ "$COLOR" = 1 -o "$COLOR" = true ]; then
|
|
||||||
_COLOR=1
|
_COLOR=1
|
||||||
|
__COLOR=1
|
||||||
return 0
|
return 0
|
||||||
|
elif [ "$COLOR" = 0 -o "$COLOR" = false ]; then
|
||||||
|
_COLOR=
|
||||||
|
__COLOR=0
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
printf '$COLOR must be 0, 1, false or true but got %s\n' "$COLOR" >&2
|
printf '$COLOR must be 0, 1, false or true but got %s\n' "$COLOR" >&2
|
||||||
fi
|
fi
|
||||||
|
|
@ -68,9 +70,11 @@ should_color() {
|
||||||
|
|
||||||
if [ -t 1 -a "${TERM-}" != dumb ]; then
|
if [ -t 1 -a "${TERM-}" != dumb ]; then
|
||||||
_COLOR=1
|
_COLOR=1
|
||||||
|
__COLOR=1
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_COLOR=
|
_COLOR=
|
||||||
|
__COLOR=0
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -114,9 +118,9 @@ printfp() {(
|
||||||
fi
|
fi
|
||||||
should_color || true
|
should_color || true
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
printf '%s' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")"
|
printf '%s' "$(COLOR=$__COLOR setaf "$FGCOLOR" "$prefix")"
|
||||||
else
|
else
|
||||||
printf '%s: %s\n' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
printf '%s: %s\n' "$(COLOR=$__COLOR setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
||||||
fi
|
fi
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -125,7 +129,7 @@ catp() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
should_color || true
|
should_color || true
|
||||||
sed "s/^/$(COLOR=${_COLOR-} printfp "$prefix" '')/"
|
sed "s/^/$(COLOR=$__COLOR printfp "$prefix" '')/"
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
|
|
@ -152,17 +156,17 @@ printferr() {
|
||||||
|
|
||||||
logp() {
|
logp() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} echop "$@" | humanpath >&2
|
COLOR=$__COLOR echop "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
logfp() {
|
logfp() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} printfp "$@" | humanpath >&2
|
COLOR=$__COLOR printfp "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
logpcat() {
|
logpcat() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} catp "$@" | humanpath >&2
|
COLOR=$__COLOR catp "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
|
|
@ -287,3 +291,10 @@ runtty() {
|
||||||
return 1
|
return 1
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capcode() {
|
||||||
|
set +e
|
||||||
|
"$@"
|
||||||
|
code=$?
|
||||||
|
set -e
|
||||||
|
}
|
||||||
|
|
|
||||||
2
ci/sub
2
ci/sub
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0dacc9c6cee5b8d901f22f57e9dc7f9acf640cbc
|
Subproject commit 702b771228f41e5485b5f3f593ce79f6efcb555d
|
||||||
|
|
@ -17,8 +17,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2compiler"
|
"oss.terrastruct.com/d2/d2compiler"
|
||||||
"oss.terrastruct.com/d2/d2exporter"
|
"oss.terrastruct.com/d2/d2exporter"
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/lib/log"
|
"oss.terrastruct.com/d2/lib/log"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// usage: D2_CHAOS_MAXI=100 D2_CHAOS_N=100 ./ci/test.sh ./d2chaos
|
// usage: D2_CHAOS_MAXI=100 D2_CHAOS_N=100 ./ci/test.sh ./d2chaos
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2compiler"
|
"oss.terrastruct.com/d2/d2compiler"
|
||||||
"oss.terrastruct.com/d2/d2exporter"
|
"oss.terrastruct.com/d2/d2exporter"
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/log"
|
"oss.terrastruct.com/d2/lib/log"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2parser"
|
"oss.terrastruct.com/d2/d2parser"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2latex"
|
"oss.terrastruct.com/d2/d2renderers/d2latex"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/d2themes"
|
"oss.terrastruct.com/d2/d2themes"
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/go2"
|
"oss.terrastruct.com/d2/lib/go2"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Refactor with a light abstract layer on top of AST implementing scenarios,
|
// TODO: Refactor with a light abstract layer on top of AST implementing scenarios,
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2compiler"
|
"oss.terrastruct.com/d2/d2compiler"
|
||||||
"oss.terrastruct.com/d2/d2exporter"
|
"oss.terrastruct.com/d2/d2exporter"
|
||||||
"oss.terrastruct.com/d2/d2graph"
|
"oss.terrastruct.com/d2/d2graph"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CompileOptions struct {
|
type CompileOptions struct {
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ import (
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2latex"
|
"oss.terrastruct.com/d2/d2renderers/d2latex"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
"oss.terrastruct.com/d2/lib/color"
|
"oss.terrastruct.com/d2/lib/color"
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/go2"
|
"oss.terrastruct.com/d2/lib/go2"
|
||||||
"oss.terrastruct.com/d2/lib/label"
|
"oss.terrastruct.com/d2/lib/label"
|
||||||
"oss.terrastruct.com/d2/lib/shape"
|
"oss.terrastruct.com/d2/lib/shape"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
"oss.terrastruct.com/d2/d2lib"
|
"oss.terrastruct.com/d2/d2lib"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Remember to add if err != nil checks in production.
|
// Remember to add if err != nil checks in production.
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
"oss.terrastruct.com/d2/d2lib"
|
"oss.terrastruct.com/d2/d2lib"
|
||||||
"oss.terrastruct.com/d2/d2oracle"
|
"oss.terrastruct.com/d2/d2oracle"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Remember to add if err != nil checks in production.
|
// Remember to add if err != nil checks in production.
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2exporter"
|
"oss.terrastruct.com/d2/d2exporter"
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
"oss.terrastruct.com/d2/d2layouts/d2dagrelayout"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Remember to add if err != nil checks in production.
|
// Remember to add if err != nil checks in production.
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2layouts/d2elklayout"
|
"oss.terrastruct.com/d2/d2layouts/d2elklayout"
|
||||||
"oss.terrastruct.com/d2/d2lib"
|
"oss.terrastruct.com/d2/d2lib"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2target"
|
"oss.terrastruct.com/d2/d2target"
|
||||||
xdiff "oss.terrastruct.com/d2/lib/diff"
|
xdiff "oss.terrastruct.com/d2/lib/diff"
|
||||||
"oss.terrastruct.com/d2/lib/log"
|
"oss.terrastruct.com/d2/lib/log"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestE2E(t *testing.T) {
|
func TestE2E(t *testing.T) {
|
||||||
|
|
|
||||||
31
install.sh
31
install.sh
|
|
@ -61,12 +61,14 @@ tput() {
|
||||||
|
|
||||||
should_color() {
|
should_color() {
|
||||||
if [ -n "${COLOR-}" ]; then
|
if [ -n "${COLOR-}" ]; then
|
||||||
if [ "$COLOR" = 0 -o "$COLOR" = false ]; then
|
if [ "$COLOR" = 1 -o "$COLOR" = true ]; then
|
||||||
_COLOR=
|
|
||||||
return 1
|
|
||||||
elif [ "$COLOR" = 1 -o "$COLOR" = true ]; then
|
|
||||||
_COLOR=1
|
_COLOR=1
|
||||||
|
__COLOR=1
|
||||||
return 0
|
return 0
|
||||||
|
elif [ "$COLOR" = 0 -o "$COLOR" = false ]; then
|
||||||
|
_COLOR=
|
||||||
|
__COLOR=0
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
printf '$COLOR must be 0, 1, false or true but got %s\n' "$COLOR" >&2
|
printf '$COLOR must be 0, 1, false or true but got %s\n' "$COLOR" >&2
|
||||||
fi
|
fi
|
||||||
|
|
@ -74,9 +76,11 @@ should_color() {
|
||||||
|
|
||||||
if [ -t 1 -a "${TERM-}" != dumb ]; then
|
if [ -t 1 -a "${TERM-}" != dumb ]; then
|
||||||
_COLOR=1
|
_COLOR=1
|
||||||
|
__COLOR=1
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_COLOR=
|
_COLOR=
|
||||||
|
__COLOR=0
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -120,9 +124,9 @@ printfp() {(
|
||||||
fi
|
fi
|
||||||
should_color || true
|
should_color || true
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
printf '%s' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")"
|
printf '%s' "$(COLOR=$__COLOR setaf "$FGCOLOR" "$prefix")"
|
||||||
else
|
else
|
||||||
printf '%s: %s\n' "$(COLOR=${_COLOR-} setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
printf '%s: %s\n' "$(COLOR=$__COLOR setaf "$FGCOLOR" "$prefix")" "$(printf "$@")"
|
||||||
fi
|
fi
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -131,7 +135,7 @@ catp() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
should_color || true
|
should_color || true
|
||||||
sed "s/^/$(COLOR=${_COLOR-} printfp "$prefix" '')/"
|
sed "s/^/$(COLOR=$__COLOR printfp "$prefix" '')/"
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
|
|
@ -158,17 +162,17 @@ printferr() {
|
||||||
|
|
||||||
logp() {
|
logp() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} echop "$@" | humanpath >&2
|
COLOR=$__COLOR echop "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
logfp() {
|
logfp() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} printfp "$@" | humanpath >&2
|
COLOR=$__COLOR printfp "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
logpcat() {
|
logpcat() {
|
||||||
should_color >&2 || true
|
should_color >&2 || true
|
||||||
COLOR=${_COLOR-} catp "$@" | humanpath >&2
|
COLOR=$__COLOR catp "$@" | humanpath >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
|
|
@ -293,6 +297,13 @@ runtty() {
|
||||||
return 1
|
return 1
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capcode() {
|
||||||
|
set +e
|
||||||
|
"$@"
|
||||||
|
code=$?
|
||||||
|
set -e
|
||||||
|
}
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
if [ "${LIB_FLAG-}" ]; then
|
if [ "${LIB_FLAG-}" ]; then
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
"oss.terrastruct.com/d2/d2renderers/d2fonts"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
)
|
)
|
||||||
|
|
||||||
var txts = []string{
|
var txts = []string{
|
||||||
2
main.go
2
main.go
|
|
@ -18,11 +18,11 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2lib"
|
"oss.terrastruct.com/d2/d2lib"
|
||||||
"oss.terrastruct.com/d2/d2plugin"
|
"oss.terrastruct.com/d2/d2plugin"
|
||||||
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
"oss.terrastruct.com/d2/d2renderers/d2svg"
|
||||||
"oss.terrastruct.com/d2/d2renderers/textmeasure"
|
|
||||||
"oss.terrastruct.com/d2/d2themes"
|
"oss.terrastruct.com/d2/d2themes"
|
||||||
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
|
||||||
"oss.terrastruct.com/d2/lib/imgbundler"
|
"oss.terrastruct.com/d2/lib/imgbundler"
|
||||||
"oss.terrastruct.com/d2/lib/png"
|
"oss.terrastruct.com/d2/lib/png"
|
||||||
|
"oss.terrastruct.com/d2/lib/textmeasure"
|
||||||
"oss.terrastruct.com/d2/lib/version"
|
"oss.terrastruct.com/d2/lib/version"
|
||||||
"oss.terrastruct.com/d2/lib/xmain"
|
"oss.terrastruct.com/d2/lib/xmain"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4
make.sh
4
make.sh
|
|
@ -1,7 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
if [ ! -d "$(dirname "$0")/ci/sub/.git" ]; then
|
if [ ! -e "$(dirname "$0")/ci/sub/.git" ]; then
|
||||||
|
set -x
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
|
set +x
|
||||||
fi
|
fi
|
||||||
. "$(dirname "$0")/ci/sub/lib.sh"
|
. "$(dirname "$0")/ci/sub/lib.sh"
|
||||||
PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH"
|
PATH="$(cd -- "$(dirname "$0")" && pwd)/ci/sub/bin:$PATH"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue