From f3dba06048b6d24a55edbb0942e76c06493fbc7e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 14 Nov 2017 13:54:55 +0100 Subject: [PATCH] Fixed some minor bugs --- test_tig_3.tig | 2 ++ tigersay.tig | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test_tig_3.tig diff --git a/test_tig_3.tig b/test_tig_3.tig new file mode 100644 index 0000000..e8157fd --- /dev/null +++ b/test_tig_3.tig @@ -0,0 +1,2 @@ +/* print: |hello| */ +print(concat("", concat("hello", ""))) diff --git a/tigersay.tig b/tigersay.tig index baa9ac0..39b4b4e 100644 --- a/tigersay.tig +++ b/tigersay.tig @@ -79,6 +79,11 @@ let then concat(ll.val, ll_to_s(ll.next)) else "" + function ll_length (ll:stringll) : int = + if ll = nil + then 0 + else 1 + ll_length(ll.next) + var MAXWIDTH := 40 function is_whitespace (char:string) : int = @@ -117,7 +122,10 @@ let let var words := split_words(text) var splitstr := insert_whitespace_between_words(words, linewidth) in - ll_to_s(splitstr.next.next.next) + if ll_length(splitstr) > 2 then + ll_to_s(splitstr.next.next.next) + else + ll_to_s(splitstr) end function max (a:int, b:int) : int = @@ -160,7 +168,8 @@ let /* Draw stuff */ function drawtextbubble (text:string) = - let var textwidth := longest_line_length(text) + let + var textwidth := longest_line_length(text) var textheight := nr_char_in_str(text, "\n") + 1 var bubblewidth := textwidth + 4 var after_text := concat3("\013\027[",int_to_s(bubblewidth-1),"C|") @@ -172,10 +181,12 @@ let function drawtiger () = print(indentstring(TIGER, INDENT, "")) var text := getinput() + var wrappedtext := wrapstring(text, MAXWIDTH) in - drawtextbubble(wrapstring(text, MAXWIDTH)); + drawtextbubble(wrappedtext); drawtiger(); - print("\n") + print("\n"); + flush() end