window.open

This commit is contained in:
2026-05-13 21:12:39 +02:00
parent 757d999b9a
commit f79a98229a
10 changed files with 277 additions and 269 deletions

View File

@@ -2,21 +2,22 @@
module UI
module Windows
module_function
class Chat
def self.open(app, services:)
username = app.context[:username] || 'Anonymous'
BBS::Windows::Stream.open(app,
title: ' Live Chat ',
initial_lines: services[:chat].history.map { |l| format_chat_line(l) },
placeholder: 'Type a message and press Enter…',
on_submit: ->(text, _a) { services[:chat].broadcast(username, text.strip) },
on_poll: ->(a) { services[:chat].drain(a.session_id).map { |l| format_chat_line(l) } }
)
end
def chat(app, services:)
username = app.context[:username] || 'Anonymous'
BBS::Windows::Stream.open(app,
title: ' Live Chat ',
initial_lines: services[:chat].history.map { |l| format_chat_line(l) },
placeholder: 'Type a message and press Enter…',
on_submit: ->(text, _a) { services[:chat].broadcast(username, text.strip) },
on_poll: ->(a) { services[:chat].drain(a.session_id).map { |l| format_chat_line(l) } }
)
end
def format_chat_line(line)
" \e[2;37m#{line.timestamp}\e[0m \e[1;33m#{line.username}\e[0m: #{line.text}"
def self.format_chat_line(line)
" \e[2;37m#{line.timestamp}\e[0m \e[1;33m#{line.username}\e[0m: #{line.text}"
end
private_class_method :format_chat_line
end
end
end