diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-26 23:43:58 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-26 23:57:39 -0700 |
commit | 307a75530fc63939a2356bf99a04a8107d2ae800 (patch) | |
tree | 6ad4f8e5c79884c2f26cf46aaf363b5ecd2aa689 /apps/tile | |
parent | c15b6e3fc6c7f2666e8de4bc138835139fc96fce (diff) | |
download | mu-307a75530fc63939a2356bf99a04a8107d2ae800.tar.gz |
7123 - tile: truncate string if necessary
Diffstat (limited to 'apps/tile')
-rw-r--r-- | apps/tile/environment.mu | 24 | ||||
-rw-r--r-- | apps/tile/main.mu | 4 | ||||
-rw-r--r-- | apps/tile/value-stack.mu | 5 |
3 files changed, 30 insertions, 3 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 94fe8476..d006d245 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1415,13 +1415,31 @@ $render-value:body: { break-if-!= var val-ah/eax: (addr handle array byte) <- get val, text-data var val-string/eax: (addr array byte) <- lookup *val-ah + compare val-string, 0 + break-if-= + var orig-len/ecx: int <- length val-string + var truncated: (handle array byte) + var truncated-ah/esi: (addr handle array byte) <- address truncated + substring val-string, 0, 0xc, truncated-ah + var truncated-string/eax: (addr array byte) <- lookup *truncated-ah +#? { +#? var foo/eax: int <- copy truncated-string +#? print-int32-hex 0, foo +#? print-string 0, "\n" +#? } + var len/edx: int <- length truncated-string start-color screen, 0xf2, 7 - print-code-point screen, 0x275d + print-code-point screen, 0x275d # open-quote reset-formatting screen start-color screen, 0, 7 - print-string screen, val-string + print-string screen, truncated-string start-color screen, 0xf2, 7 - print-code-point screen, 0x275e + compare len, orig-len + { + break-if-= + print-code-point screen, 0x2026 # ellipses + } + print-code-point screen, 0x275e # close-quote reset-formatting screen break $render-value:body } diff --git a/apps/tile/main.mu b/apps/tile/main.mu index 08e6532b..b02dc386 100644 --- a/apps/tile/main.mu +++ b/apps/tile/main.mu @@ -77,6 +77,10 @@ fn test { initialize-environment-with-fake-screen env, 5, 0xa var g/eax: grapheme <- copy 0x22 # '"' process env, g + g <- copy 0x61 # 'a' + process env, g + g <- copy 0x22 # '"' + process env, g render env } diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu index a6ba4f0f..99e013bb 100644 --- a/apps/tile/value-stack.mu +++ b/apps/tile/value-stack.mu @@ -172,6 +172,11 @@ fn value-width _v: (addr value) -> result/eax: int { break-if-= var _out/eax: int <- length s out <- copy _out + compare out, 0xd # max string size + { + break-if-<= + out <- copy 0xd + } break $value-width:body } { |