window.open
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user