new message modal

This commit is contained in:
2026-05-12 20:36:44 +02:00
parent e9c0d947a6
commit 0661bb6a54

78
bbs.rb
View File

@@ -48,28 +48,65 @@ MAIN_TUI = BBS::TUI.define do
chrome { render_chrome } chrome { render_chrome }
page :idle do page :idle do
enter { @page_title = 'TELETYPE BBS' } enter { @page_title = 'TELETYPE BBS'; @modal = nil }
render do render do
text 'Navigate the menu with ↑↓, select with Enter.', text 'Navigate the menu with ↑↓, select with Enter.',
x: CONT_X, y: CONT_Y + cont_h / 2, style: THEME[:normal] x: CONT_X, y: CONT_Y + cont_h / 2, style: THEME[:normal]
if @modal == :sysinfo
float title: ' SYSTEM INFO ', width: 56, height: 10,
style: THEME[:border], bg: :black do |fx, fy, fw, _|
[
"Online users #{ONLINE.count}",
"Messages #{MESSAGES.count}",
"Wiki https://wiki.teletypegames.org",
"Games API https://teletypegames.org",
"Platform #{RUBY_PLATFORM}",
"Ruby #{RUBY_VERSION}",
].each_with_index do |row, i|
text row[0, fw], x: fx, y: fy + i, style: THEME[:normal]
end
text 'ESC close', x: fx, y: fy + 7, style: THEME[:label]
end
elsif @modal == :new_msg
float title: ' POST MESSAGE ', width: 62, height: 9,
style: THEME[:border], bg: :black do |fx, fy, fw, _|
text 'Type your message and press Enter. Esc cancels.',
x: fx, y: fy, style: THEME[:normal]
text "#{tc(:bright, @username)}: #{tc(:input, @input)}_",
x: fx, y: fy + 2
text @status, x: fx, y: fy + 4, style: THEME[:error] unless @status.empty?
text "#{@input.length}/200 ESC cancel",
x: fx, y: fy + 6, style: THEME[:label]
end
end
end end
nav :menu, size: MENU_ITEMS.size nav :menu, size: MENU_ITEMS.size
key(:enter) do key(:enter) do
if @modal == :new_msg
case MESSAGES.post(@username, @input)
when :empty then @status = 'Message cannot be empty.'
when :ok then @modal = nil
end
elsif @modal.nil?
case MENU_ITEMS[@menu_sel] case MENU_ITEMS[@menu_sel]
when 'Messages' then go :messages when 'Messages' then go :messages
when 'Post Message' then go :new_msg when 'Post Message' then @modal = :new_msg; @input = +''; @status = +''
when 'Blog Posts' then go :blog when 'Blog Posts' then go :blog
when 'HowTo Guides' then go :howto when 'HowTo Guides' then go :howto
when 'Game Catalog' then go :games when 'Game Catalog' then go :games
when 'Online Users' then go :online when 'Online Users' then go :online
when 'System Info' then go :sysinfo when 'System Info' then @modal = :sysinfo
when 'Exit' then :halt when 'Exit' then :halt
end end
end end
key('q') { :halt } end
key(:escape) { :halt } key(:backspace) { @input.chop! if @modal == :new_msg && !@input.empty? }
key('q') { @modal ? @modal = nil : :halt }
key(:escape) { @modal ? @modal = nil : :halt }
printable { |ch| @input << ch if @modal == :new_msg && @input.length < 200 }
end end
page :messages do page :messages do
@@ -81,20 +118,6 @@ MAIN_TUI = BBS::TUI.define do
key(:escape) { go :idle } key(:escape) { go :idle }
end end
page :new_msg do
enter { @page_title = 'POST MESSAGE'; @input = +''; @status = +'' }
render { render_new_message_form }
key(:enter) do
case MESSAGES.post(@username, @input)
when :empty then @status = 'Message cannot be empty.'
when :ok then go :idle
end
end
key(:backspace) { @input.chop! unless @input.empty? }
key(:escape) { go :idle }
printable { |ch| @input << ch if @input.length < 200 }
end
page :blog do page :blog do
enter { @page_title = 'BLOG'; load_wiki_list(WIKI, 'blog') } enter { @page_title = 'BLOG'; load_wiki_list(WIKI, 'blog') }
render { render_wiki_list } render { render_wiki_list }
@@ -139,23 +162,6 @@ MAIN_TUI = BBS::TUI.define do
key(:escape) { go :idle } key(:escape) { go :idle }
end end
page :sysinfo do
enter do
@page_title = 'SYSTEM INFO'
@items = [
"Online users #{ONLINE.count}",
"Messages #{MESSAGES.count}",
"Wiki https://wiki.teletypegames.org",
"Games API https://teletypegames.org",
"Platform #{RUBY_PLATFORM}",
"Ruby #{RUBY_VERSION}"
]
end
render { render_sysinfo_rows }
key('q') { go :idle }
key(:escape) { go :idle }
end
start :idle start :idle
end end