about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.lua6
-rw-r--r--text.lua19
2 files changed, 13 insertions, 12 deletions
diff --git a/main.lua b/main.lua
index 702af42..a4eb1c8 100644
--- a/main.lua
+++ b/main.lua
@@ -44,7 +44,7 @@ Cursor_line = 1
 --  ^cursor_pos = 2
 --   ...
 --               ^cursor_pos past end of line is 15
-Cursor_pos = #Lines[Cursor_line].data+1  -- in Unicode codepoints
+Cursor_pos = 1  -- in Unicode codepoints
 
 Screen_width, Screen_height, Screen_flags = 0, 0, nil
 
@@ -133,8 +133,8 @@ function love.draw()
         y = y + Drawing.pixels(line.h) + 10 -- padding
       else
         line.y = y
-        y = Text.draw(line, 100, line_index, Cursor_line, Cursor_pos)
---?         y = Text.draw(line, Drawing_width, line_index, Cursor_line, Cursor_pos)
+--?         y = Text.draw(line, 100, line_index, Cursor_line, Cursor_pos)
+        y = Text.draw(line, Drawing_width, line_index, Cursor_line, Cursor_pos)
         y = y + math.floor(15*Zoom)  -- text height
       end
     end
diff --git a/text.lua b/text.lua
index bbe81c8..7a442e8 100644
--- a/text.lua
+++ b/text.lua
@@ -39,8 +39,8 @@ function Text.compute_fragments(line, line_width)
 end
 
 function Text.draw(line, line_width, line_index, cursor_line, cursor_pos)
-  love.graphics.setColor(0.75,0.75,0.75)
-  love.graphics.line(line_width, 0, line_width, Screen_height)
+--?   love.graphics.setColor(0.75,0.75,0.75)
+--?   love.graphics.line(line_width, 0, line_width, Screen_height)
   love.graphics.setColor(0,0,0)
   -- wrap long lines
   local x = 25
@@ -119,7 +119,7 @@ function Text.keychord_pressed(chord)
         new_cursor_line = new_cursor_line-1
         if Lines[new_cursor_line].mode == 'text' then
           Cursor_line = new_cursor_line
-          Cursor_pos = #Lines[Cursor_line].data+1
+          Cursor_pos = utf8.len(Lines[Cursor_line].data) + 1
           break
         end
       end
@@ -129,7 +129,7 @@ function Text.keychord_pressed(chord)
     end
   elseif chord == 'right' then
     assert(Lines[Cursor_line].mode == 'text')
-    if Cursor_pos <= #Lines[Cursor_line].data then
+    if Cursor_pos <= utf8.len(Lines[Cursor_line].data) then
       Cursor_pos = Cursor_pos+1
     else
       local new_cursor_line = Cursor_line
@@ -148,7 +148,7 @@ function Text.keychord_pressed(chord)
   elseif chord == 'home' then
     Cursor_pos = 1
   elseif chord == 'end' then
-    Cursor_pos = #Lines[Cursor_line].data+1
+    Cursor_pos = utf8.len(Lines[Cursor_line].data) + 1
   elseif chord == 'backspace' then
     if Cursor_pos > 1 then
       local byte_start = utf8.offset(Lines[Cursor_line].data, Cursor_pos-1)
@@ -176,7 +176,7 @@ function Text.keychord_pressed(chord)
     end
     save_to_disk(Lines, Filename)
   elseif chord == 'delete' then
-    if Cursor_pos <= #Lines[Cursor_line].data then
+    if Cursor_pos <= utf8.len(Lines[Cursor_line].data) then
       local byte_start = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
       local byte_end = utf8.offset(Lines[Cursor_line].data, Cursor_pos+1)
       if byte_start then
@@ -279,9 +279,10 @@ function Text.nearest_cursor_pos(line, x, hint)
   if x == 0 then
     return 1
   end
-  local max_x = Text.cursor_x(line, #line+1)
+  local len = utf8.len(line)
+  local max_x = Text.cursor_x(line, len+1)
   if x > max_x then
-    return #line+1
+    return len+1
   end
   if hint then
     local currx = Text.cursor_x(line, hint)
@@ -289,7 +290,7 @@ function Text.nearest_cursor_pos(line, x, hint)
       return hint
     end
   end
-  local left, right = 1, #line+1
+  local left, right = 1, len+1
   if hint then
     if currx > x then
       right = hint
#bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>

#include <stabber.h>
#include <expect.h>

#include "proftest.h"

void
send_enable_carbons(void **state)
{
    prof_connect();

    prof_input("/carbons on");

    assert_true(stbbr_received(
        "<iq id='*' type='set'><enable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));
}

void
connect_with_carbons_enabled(void **state)
{
    prof_input("/carbons on");

    prof_connect();

    assert_true(stbbr_received(
        "<iq id='*' type='set'><enable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));
}

void
send_disable_carbons(void **state)
{
    prof_input("/carbons on");

    prof_connect();

    prof_input("/carbons off");

    assert_true(stbbr_received(
        "<iq id='*' type='set'><disable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));
}

void
receive_carbon(void **state)
{
    prof_input("/carbons on");

    prof_connect();
    assert_true(stbbr_received(
        "<iq id='*' type='set'><enable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));

    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>On my mobile</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"On my mobile\""));
    prof_input("/msg Buddy1");
    assert_true(prof_output_exact("unencrypted"));

    stbbr_send(
        "<message type='chat' to='stabber@localhost/profanity' from='stabber@localhost'>"
            "<received xmlns='urn:xmpp:carbons:2'>"
                "<forwarded xmlns='urn:xmpp:forward:0'>"
                    "<message id='prof_msg_7' xmlns='jabber:client' type='chat' lang='en' to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
                        "<body>test carbon from recipient</body>"
                    "</message>"
                "</forwarded>"
            "</received>"
        "</message>"
    );

    assert_true(prof_output_regex("Buddy1/mobile: .+test carbon from recipient"));
}

void
receive_self_carbon(void **state)
{
    prof_input("/carbons on");

    prof_connect();
    assert_true(stbbr_received(
        "<iq id='*' type='set'><enable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));

    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>On my mobile</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"On my mobile\""));
    prof_input("/msg Buddy1");
    assert_true(prof_output_exact("unencrypted"));

    stbbr_send(
        "<message type='chat' to='stabber@localhost/profanity' from='stabber@localhost'>"
            "<sent xmlns='urn:xmpp:carbons:2'>"
                "<forwarded xmlns='urn:xmpp:forward:0'>"
                    "<message id='59' xmlns='jabber:client' type='chat' to='buddy1@localhost/mobile' lang='en' from='stabber@localhost/profanity'>"
                        "<body>self sent carbon</body>"
                    "</message>"
                "</forwarded>"
            "</sent>"
        "</message>"
    );

    assert_true(prof_output_regex("me: .+self sent carbon"));
}

void
receive_private_carbon(void **state)
{
    prof_input("/carbons on");

    prof_connect();
    assert_true(stbbr_received(
        "<iq id='*' type='set'><enable xmlns='urn:xmpp:carbons:2'/></iq>"
    ));

    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>On my mobile</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"On my mobile\""));
    prof_input("/msg Buddy1");
    assert_true(prof_output_exact("unencrypted"));

    stbbr_send(
        "<message type='chat' to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
            "<body>Private carbon</body>"
            "<private xmlns='urn:xmpp:carbons:2'/>"
        "</message>"
    );

    assert_true(prof_output_regex("Buddy1/mobile: .+Private carbon"));
}