aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-11-19 04:01:12 +0100
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-11-19 04:01:12 +0100
commit0d90e8abd785ed897eb2ddccc1e97e8b32fef616 (patch)
tree8094ecb1cf1fc929194b87a24d10e66eb38b8d32
parent2a26ea96a9bde812ebe0ea194933b88167ca6f23 (diff)
Add Tab keybind
- Do not let chatty send empty messages - Add option to `markdown_to_raw()` to only get length of raw text
-rw-r--r--chatty.c18
-rw-r--r--ui.c13
2 files changed, 27 insertions, 4 deletions
diff --git a/chatty.c b/chatty.c
index 233e8b3..6631ebf 100644
--- a/chatty.c
+++ b/chatty.c
@@ -19,6 +19,8 @@
#define LOGFILE "chatty.log"
// enable logging
#define LOGGING
+// Number of spaces inserted when pressing Tab/Ctrl+I
+#define TAB_WIDTH 4
#define DEBUG
@@ -761,12 +763,25 @@ main(int argc, char** argv)
}
} break;
+ case TB_KEY_CTRL_I:
+ {
+ for (u32 i = 0;
+ i < TAB_WIDTH && InputLen < INPUT_LIMIT - 1;
+ i++)
+ {
+ Input[InputLen] = L' ';
+ InputLen++;
+ }
+ } break;
case TB_KEY_CTRL_D:
case TB_KEY_CTRL_C:
quit = 1;
break;
case TB_KEY_CTRL_M: // send message
- if (InputLen == 0)
+ {
+ raw_result RawText = markdown_to_raw(0, Input, InputLen);
+
+ if (RawText.Len == 0)
// do not send empty message
break;
if (fds[FDS_UNI].fd == -1)
@@ -796,6 +811,7 @@ main(int argc, char** argv)
MessagesNum++;
// also clear input
+ } // fallthrough
case TB_KEY_CTRL_U: // clear input
bzero(Input, InputLen * sizeof(*Input));
InputLen = 0;
diff --git a/ui.c b/ui.c
index ed2aa24..c2e0ac9 100644
--- a/ui.c
+++ b/ui.c
@@ -207,20 +207,27 @@ tb_print_wrapped_with_markdown(u32 XOffset, u32 YOffset, u32 fg, u32 bg,
// Return string without markdown markup characters using `is_markdown()`
// ScratchArena is used to allocate space for the raw text
+// If ScratchArena is null then it will only return then length of the raw string
// Len should be characters + null terminator
// Copies the null terminator as well
raw_result
markdown_to_raw(Arena* ScratchArena, u32* Text, u32 Len)
{
raw_result Result = {0};
- Result.Text = ScratchArena->addr;
+ if (ScratchArena)
+ {
+ Result.Text = ScratchArena->addr;
+ }
for (u32 i = 0; i < Len; i++)
{
if (!is_markdown(Text[i]))
{
- u32* ch = ArenaPush(ScratchArena, sizeof(*ch));
- *ch = Text[i];
+ if (ScratchArena)
+ {
+ u32* ch = ArenaPush(ScratchArena, sizeof(*ch));
+ *ch = Text[i];
+ }
Result.Len++;
}
}