Compare commits

...

10 Commits

Author SHA1 Message Date
fa63af7c30 irc: expand Send dialog input without allowing newlines
- Remove allow_newline; Enter triggers Send via is_enter_default.
- Keep use_available_height + condensed to reduce scroll bars.

Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 03:11:50 +03:00
149f930ef9 irc: make Send message dialog multiline and expandable
- Enable  for multiline input.
- Use  and  to expand input box and maximize space.

Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 03:10:12 +03:00
5cec4d8bb1 irc: remove duplicate NICK handler in handleLine
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 03:09:03 +03:00
36dd81ce1c irc: fix live updates and preserve default buttons on reopen
- Set  in  so append/refresh repaint.
- Build button rows explicitly (Send + TextViewer defaults) and disable
  automatic default insertion to ensure defaults remain after reinit.

Also clarifies behavior when reopening a keep_running view.

Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 03:03:28 +03:00
d79377a712 irc: restore TextViewer default buttons (scroll/find/Close); keep only custom Send button to avoid duplicate Close; fixes live updates
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:50:32 +03:00
2f061e20dc irc: avoid reinit on append; set TextViewer.text to current buffer in refresh; rely on switcher refresh path
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:48:54 +03:00
8a38e51e20 irc: force TextViewer reinit after live append to current channel to work around UI not repainting
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:45:22 +03:00
bdb131cbfa irc: refresh current channel with same codepath as switcher after append; fixes live updates on send/receive
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:39:33 +03:00
ef3db25cd0 irc: send before closing dialog and force a post-close refresh; add refreshView helper
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:30:59 +03:00
ed22622ecd irc: trigger ScrollTextWidget updateScrollBar after appending to force immediate repaint on send
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-20 02:27:59 +03:00

102
main.lua
View File

@@ -23,7 +23,7 @@ local lfs = require("libs/libkoreader-lfs")
local IrcChatView = TextViewer:extend{
title = _("IRC Chat"),
text = "",
add_default_buttons = false,
add_default_buttons = true,
monospace_font = true,
text_type = "code",
keep_running = true, -- keep connection alive when UI is closed
@@ -48,23 +48,67 @@ local IrcChatView = TextViewer:extend{
}
function IrcChatView:init(reinit)
-- Buttons: Send, Close
self.buttons_table = {
{
-- Mark UI as open so append/refresh paths repaint immediately
self._ui_open = true
-- Build buttons: first our Send row, then TextViewer's default row
-- Disable TextViewer's automatic default buttons to avoid duplication
self.add_default_buttons = false
local send_row = {
{
text = _("Send"),
callback = function()
self:promptSendMessage()
end,
},
}
local default_row = {
{
text = _("Find"),
id = "find",
callback = function()
if self._find_next then
self:findCallback()
else
self:findDialog()
end
end,
hold_callback = function()
if self._find_next then
self:findDialog()
else
if self.default_hold_callback then
self.default_hold_callback()
end
end
end,
},
{
text = "",
id = "top",
callback = function()
if self.scroll_text_w then self.scroll_text_w:scrollToTop() end
end,
hold_callback = self.default_hold_callback,
allow_hold_when_disabled = true,
},
{
text = "",
id = "bottom",
callback = function()
if self.scroll_text_w then self.scroll_text_w:scrollToBottom() end
end,
hold_callback = self.default_hold_callback,
allow_hold_when_disabled = true,
},
{
text = _("Close"),
callback = function()
self:onClose()
end,
hold_callback = self.default_hold_callback,
},
}
}
self.buttons_table = { send_row, default_row }
-- Buffers & title
if not reinit then
self._buffers = {}
@@ -267,12 +311,9 @@ function IrcChatView:appendLine(line, target)
-- Persist to history
self:writeHistory(target, prefix .. line)
if target == (self._current_target or "*") then
if self._ui_open and self.scroll_text_w and self.scroll_text_w.text_widget then
self.scroll_text_w.text_widget:setText(buf)
self.scroll_text_w:scrollToBottom()
if UIManager and self.frame and self.frame.dimen then
UIManager:setDirty(self, function() return "ui", self.frame.dimen end)
end
if self._ui_open then
-- Reuse the same refresh path as the channel switcher
self:refreshView(target)
end
else
-- increment unread counter for background target
@@ -416,15 +457,26 @@ function IrcChatView:promptSendMessage()
dialog = InputDialog:new{
title = _("Send message"),
input = "",
-- Keep single-line input semantics on Enter, but expand the box
use_available_height = true, -- expand input to available height
condensed = true, -- reduce extra padding to maximize text area
buttons = {
{
{
text = _("Send"),
is_default = true,
is_enter_default = true,
callback = function()
local txt = dialog:getInputText()
UIManager:close(dialog)
-- Update buffer/UI before closing dialog to ensure immediate repaint
self:sendMessage(txt)
UIManager:close(dialog)
-- And schedule a focused refresh after the dialog is gone
if UIManager and self._ui_open then
UIManager:nextTick(function()
self:refreshView(self._current_target or "*")
end)
end
end,
},
{
@@ -440,6 +492,24 @@ function IrcChatView:promptSendMessage()
dialog:onShowKeyboard(true)
end
function IrcChatView:refreshView(target)
target = target or self._current_target or "*"
if not self._ui_open then return end
self:preloadHistory(target)
if self.scroll_text_w and self.scroll_text_w.text_widget then
local s = self._buffers[target] or ""
self.text = s
self.scroll_text_w.text_widget:setText(s)
self.scroll_text_w:scrollToBottom()
if self.scroll_text_w.updateScrollBar then
self.scroll_text_w:updateScrollBar(true)
end
end
if UIManager and self.frame and self.frame.dimen then
UIManager:setDirty(self, function() return "ui", self.frame.dimen end)
end
end
function IrcChatView:receiveLoop()
if self._closing then return end
if not self._sock then return end
@@ -590,14 +660,6 @@ function IrcChatView:handleLine(line)
end
end
return
elseif command == "NICK" then -- someone changed nick; update ours if it's us
local newnick = rest:match("^:(.+)$") or rest
local oldnick = prefix:match("^([^!]+)!") or prefix
if oldnick == self._nick and newnick and #newnick > 0 then
self._nick = newnick
self:appendLine(T(_("You are now known as %1"), newnick))
end
return
elseif command == "376" or command == "422" then
-- End of MOTD / No MOTD: safe to join if not yet joined
if not self._registered then self._registered = true end