From 87ff91c04cf4744fb287fe3dec869eef1045cc06 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:20:57 -0700 Subject: [PATCH] clean up tui --- .gitmodules | 2 ++ examples/tui/tui.nim | 27 ++++++++++----------------- nim_chat_poc.nimble | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.gitmodules b/.gitmodules index 684984a..1b05c61 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,5 @@ [submodule "vendor/illwill"] path = vendor/illwill url = https://github.com/johnnovak/illwill.git + ignore = untracked + branch = master diff --git a/examples/tui/tui.nim b/examples/tui/tui.nim index 624440e..cf40445 100644 --- a/examples/tui/tui.nim +++ b/examples/tui/tui.nim @@ -15,10 +15,9 @@ import chat_sdk/[ conversations, delivery/waku_client, links - # proto_types ] -import ../../src/content_types/all +import content_types/all import layout import persistence @@ -109,9 +108,6 @@ proc setupChatSdk(app: ChatApp) = "" app.conversations[convo.id()].messages.add(Message(sender: "???", content: contentStr, timestamp: now())) - - # await sleepAsync(10000) - # await convo.sendMessage(client.ds, initTextFrame("Pong").toContentFrame()) ) app.client.onNewConversation(proc(convo: Conversation) {.async.} = @@ -119,7 +115,6 @@ proc setupChatSdk(app: ChatApp) = info "New Conversation: ", convoId = convo.id() app.conversations[convo.id()] = ConvoInfo(name: convo.id(), messages: @[], lastMsgTime: now(), isTooLong: false) - # await convo.sendMessage(client.ds, initTextFrame("Hello").toContentFrame()) ) app.client.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} = @@ -341,7 +336,7 @@ proc drawMsgInput( app: ChatApp, layout: Pane) = tb.write(paneStart + 1, inputY, " > " & app.inputBuffer, fgWhite) # Draw cursor - let cursorX = paneStart + 3 + app.inputBuffer.len + let cursorX = paneStart + 3 + app.inputBuffer.len + 1 if cursorX < paneStart + layout.width - 1: tb.write(cursorX, inputY, "_", fgYellow) @@ -366,7 +361,6 @@ proc drawModal(app: ChatApp, layout: Pane, color: ForegroundColor, bg: BackgroundColor = bgBlack) = var tb = app.tb - # echo "Drawing modal at ", layout tb.setForegroundColor(color) tb.setBackgroundColor(bg) for x in layout.xStart.. " & app.inputBuffer) + tb.write(layout.xStart+5, layout.yStart+inputLine, "> " & app.inputInviteBuffer) - # Draw cursor - let cursorX = layout.xStart+5 + app.inputBuffer.len + # Draw cursor + let cursorX = layout.xStart+5+1 + app.inputInviteBuffer.len if cursorX < terminalWidth() - 1: - tb.write(cursorX, layout.yStart+inputLine+2, "_", fgYellow) + tb.write(cursorX, layout.yStart+inputLine, "_", fgYellow) tb.setForegroundColor(fgBlack) tb.setBackgroundColor(bgGreen) @@ -449,11 +443,10 @@ proc handleInput(app: ChatApp, key: Key) = if app.inputBuffer.len > 0: app.inputBuffer.setLen(app.inputBuffer.len - 1) of Key.Tab: - if app.conversations.len > 0: - app.inviteModal = not app.inviteModal + app.inviteModal = not app.inviteModal - if app.inviteModal: - app.currentInviteLink = app.client.createIntroBundle().toLink() + if app.inviteModal: + app.currentInviteLink = app.client.createIntroBundle().toLink() of Key.Escape, Key.CtrlC: quit(0) else: @@ -474,7 +467,7 @@ proc appLoop(app: ChatApp, panes: seq[Pane]) : Future[void] {.async.} = illwillInit(fullscreen = false) # Clear buffer while true: - await sleepAsync(50) + await sleepAsync(5) app.tb.clear() drawStatusBar(app, panes[0], fgBlack, getIdColor(app.client.getId())) diff --git a/nim_chat_poc.nimble b/nim_chat_poc.nimble index 98df81c..03c49da 100644 --- a/nim_chat_poc.nimble +++ b/nim_chat_poc.nimble @@ -44,4 +44,4 @@ task nim_chat_poc, "Build Waku based simple example": task tui, "Build Waku based simple example": let name = "tui" - buildBinary name, "examples/", " -d:chronicles_log_level='INFO' -d:chronicles_sinks=textlines[file]" + buildBinary name, "examples/", " -d:chronicles_enabled=off -d:chronicles_log_level='INFO' -d:chronicles_sinks=textlines[file]"