tui version
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.env
|
.env
|
||||||
bbs-server
|
bbs-server
|
||||||
tmp
|
tmp
|
||||||
data/messages.dat
|
data/messages.dat
|
||||||
|
.claude
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: https://git.teletype.hu/tools/rubbs.git
|
remote: https://git.teletype.hu/tools/rubbs.git
|
||||||
revision: c01159dc2306ed9adda3b865346ae1f987649a67
|
revision: 8a3e38aa25b29575b7038cdab753cad0a126c698
|
||||||
specs:
|
specs:
|
||||||
bbs (0.1.0)
|
bbs (0.1.0)
|
||||||
artii (~> 2.1)
|
artii (~> 2.1)
|
||||||
|
|||||||
458
bbs.rb
458
bbs.rb
@@ -14,46 +14,15 @@ MESSAGES = MessageBoardRepository.new(ENV.fetch('MESSAGES_PATH', 'data/messages.
|
|||||||
WIKI = WikiRepository.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
WIKI = WikiRepository.new(token: ENV['WEBAPP_WIKIJS_TOKEN'])
|
||||||
CATALOG = CatalogRepository.new
|
CATALOG = CatalogRepository.new
|
||||||
|
|
||||||
class OutputBuilder
|
MENU_ITEMS = [
|
||||||
def initialize = (@buf = +''; @badges = [])
|
'Messages', 'Post Message', 'Blog Posts',
|
||||||
def to_s = (flush_badges; @buf)
|
'HowTo Guides', 'Game Catalog', 'Online Users',
|
||||||
|
'System Info', 'Exit'
|
||||||
|
].freeze
|
||||||
|
|
||||||
def sep(color = :gray)
|
SEP_X = 21
|
||||||
flush_badges
|
CONT_X = 23
|
||||||
@buf << "\r\n #{c(color, '─' * 66)}\r\n"
|
CONT_Y = 3
|
||||||
end
|
|
||||||
|
|
||||||
def line(text, color = nil)
|
|
||||||
flush_badges
|
|
||||||
@buf << " #{color ? c(color, text) : text}\r\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def cols(**pairs)
|
|
||||||
flush_badges
|
|
||||||
@buf << " #{pairs.map { |color, text| c(color, text.to_s) }.join(' ')}\r\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def para(text)
|
|
||||||
flush_badges
|
|
||||||
@buf << wrap_text(text) unless text.to_s.strip.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
def badge(color, text)
|
|
||||||
@badges << c(color, text)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def flush_badges
|
|
||||||
return if @badges.empty?
|
|
||||||
@buf << " #{@badges.join(' ')}\r\n"
|
|
||||||
@badges = []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def render(&block)
|
|
||||||
OutputBuilder.new.tap { |b| b.instance_eval(&block) }.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def fmt_date(iso)
|
def fmt_date(iso)
|
||||||
Time.parse(iso.to_s).strftime('%Y-%m-%d')
|
Time.parse(iso.to_s).strftime('%Y-%m-%d')
|
||||||
@@ -61,21 +30,27 @@ rescue
|
|||||||
iso.to_s
|
iso.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_text(text, width: 60, indent: 4)
|
def wrap_wiki(text, width)
|
||||||
clean = text.to_s
|
clean = text.to_s
|
||||||
.gsub(/\[([^\]]+)\]\([^)]+\)/, '\1')
|
.gsub(/\[([^\]]+)\]\([^)]+\)/, '\1')
|
||||||
.gsub(/[#*_`~>|\\]/, '')
|
.gsub(/[#*_`~>|\\]/, '')
|
||||||
.gsub(/\r?\n+/, ' ')
|
.gsub(/\r?\n+/, ' ')
|
||||||
.strip
|
.strip
|
||||||
lines, line = [], +''
|
words = clean.split
|
||||||
clean.split.each do |word|
|
lines = []
|
||||||
if line.empty? then line << word
|
line = +''
|
||||||
elsif line.length + 1 + word.length <= width then line << ' ' << word
|
words.each do |word|
|
||||||
else lines << line.dup; line = +word
|
if line.empty?
|
||||||
|
line << word
|
||||||
|
elsif line.length + 1 + word.length <= width
|
||||||
|
line << ' ' << word
|
||||||
|
else
|
||||||
|
lines << line.dup
|
||||||
|
line = +word
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
lines << line unless line.empty?
|
lines << line unless line.empty?
|
||||||
lines.map { |l| "#{' ' * indent}#{l}\r\n" }.join
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
BBS.configure do |c|
|
BBS.configure do |c|
|
||||||
@@ -89,125 +64,308 @@ BBS.configure do |c|
|
|||||||
|
|
||||||
call { |ctx| ONLINE.add(ctx[:session_id], ctx[:username]) }
|
call { |ctx| ONLINE.add(ctx[:session_id], ctx[:username]) }
|
||||||
|
|
||||||
menu 'Choice', loop: true do
|
call do |ctx, runner|
|
||||||
option 'Message Board' do
|
session = runner.instance_variable_get(:@session)
|
||||||
section 'Message Board', color: :cyan
|
username = ctx[:username]
|
||||||
rows(empty: 'No messages yet.') do |ctx|
|
session_id = ctx[:session_id]
|
||||||
MESSAGES.last(30).map.with_index(1) do |msg, i|
|
|
||||||
"#{c(:gray, "[#{i}]")} #{c(:yellow, msg.timestamp)} #{c(:white, msg.username)}: #{c(:gray, msg.text)}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
wait_enter
|
|
||||||
end
|
|
||||||
|
|
||||||
option 'New Message' do
|
tui = BBS::TUI.define do
|
||||||
ask :message_text, prompt: 'Message (max 200 chars)', validate: :non_empty
|
init do
|
||||||
call { |ctx| MESSAGES.append(ctx[:username], ctx[:message_text][0...200]) }
|
@menu_sel = 0
|
||||||
say 'Sent.', style: :success
|
@state = :idle
|
||||||
end
|
@prev_state = :idle
|
||||||
|
@items = []
|
||||||
|
@item_sel = 0
|
||||||
|
@scroll = 0
|
||||||
|
@detail = []
|
||||||
|
@page_header = ''
|
||||||
|
@page_meta = ''
|
||||||
|
@input = ''
|
||||||
|
@status = ''
|
||||||
|
@username = username
|
||||||
|
@session_id = session_id
|
||||||
|
end
|
||||||
|
|
||||||
option 'Blog Posts' do
|
render do
|
||||||
section 'Blog Posts', color: :blue
|
cont_w = term_cols - CONT_X - 1
|
||||||
fetch :pages, loading: 'Loading...' do |ctx|
|
cont_h = term_rows - CONT_Y - 4
|
||||||
WIKI.list('blog')
|
|
||||||
end
|
|
||||||
pick from: :pages,
|
|
||||||
empty: 'No results.',
|
|
||||||
prompt: 'Enter number to read (blank to go back)',
|
|
||||||
item: ->(p, i) { "#{c(:gray, "#{i}.")} #{c(:blue, p.title)} #{c(:gray, fmt_date(p.created_at))}" },
|
|
||||||
hint: ->(p, i) { p.description.to_s.strip[0...65] } do
|
|
||||||
fetch :page_body, loading: 'Loading page...' do |ctx|
|
|
||||||
WIKI.content(ctx[:picked].id)
|
|
||||||
end
|
|
||||||
line color: :blue
|
|
||||||
text(style: :white) { |ctx| ctx[:picked].title }
|
|
||||||
text(style: :muted) { |ctx| "#{fmt_date(ctx[:picked].created_at)} #{WIKI.page_url(ctx[:picked].locale, ctx[:picked].path)}" }
|
|
||||||
line color: :blue
|
|
||||||
body { |ctx| ctx[:page_body] }
|
|
||||||
wait_enter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
option 'HowTo Guides' do
|
clear
|
||||||
section 'HowTo Guides', color: :magenta
|
|
||||||
fetch :pages, loading: 'Loading...' do |ctx|
|
|
||||||
WIKI.list('howto')
|
|
||||||
end
|
|
||||||
pick from: :pages,
|
|
||||||
empty: 'No results.',
|
|
||||||
prompt: 'Enter number to read (blank to go back)',
|
|
||||||
item: ->(p, i) { "#{c(:gray, "#{i}.")} #{c(:magenta, p.title)} #{c(:gray, fmt_date(p.created_at))}" },
|
|
||||||
hint: ->(p, i) { p.description.to_s.strip[0...65] } do
|
|
||||||
fetch :page_body, loading: 'Loading page...' do |ctx|
|
|
||||||
WIKI.content(ctx[:picked].id)
|
|
||||||
end
|
|
||||||
line color: :magenta
|
|
||||||
text(style: :white) { |ctx| ctx[:picked].title }
|
|
||||||
text(style: :muted) { |ctx| "#{fmt_date(ctx[:picked].created_at)} #{WIKI.page_url(ctx[:picked].locale, ctx[:picked].path)}" }
|
|
||||||
line color: :magenta
|
|
||||||
body { |ctx| ctx[:page_body] }
|
|
||||||
wait_enter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
option 'Game Catalog' do
|
bar y: 1,
|
||||||
section 'Game Catalog', color: :cyan
|
content: " TELETYPE BBS │ #{@username} │ #{ONLINE.count} online",
|
||||||
fetch :games, loading: 'Loading...' do |ctx|
|
style: :success
|
||||||
CATALOG.fetch
|
|
||||||
end
|
|
||||||
output do |ctx|
|
|
||||||
games = Array(ctx[:games])
|
|
||||||
next " #{c(:red, 'Could not load catalog.')}\r\n" unless games.any?
|
|
||||||
|
|
||||||
render do
|
menu_labels = MENU_ITEMS.map { |item| item[0, 15] }
|
||||||
games.each_with_index do |game, i|
|
list menu_labels, x: 2, y: CONT_Y, selected: @menu_sel,
|
||||||
sep
|
style: :gray, highlight: :white
|
||||||
cols cyan: "#{i + 1}. #{game.title}", gray: "#{game.platform} #{game.author}"
|
|
||||||
para game.desc
|
(CONT_Y..CONT_Y + cont_h).each { |r| text c(:gray, '│'), x: SEP_X, y: r }
|
||||||
badge :green, '[▶ Play]' unless game.play_path.empty?
|
|
||||||
badge :yellow, '[⬇ Download]' unless game.download_path.empty?
|
case @state
|
||||||
badge :blue, '[Source]' unless game.source_path.empty?
|
when :idle
|
||||||
badge :magenta, '[Docs]' unless game.docs_path.empty?
|
text c(:gray, 'Navigate with ↑↓, select with Enter'),
|
||||||
line CATALOG.play_url(game.play_path), :gray unless game.play_path.empty?
|
x: CONT_X, y: CONT_Y + cont_h / 2
|
||||||
line "#{game.release_count} versions available", :gray if game.release_count > 1
|
|
||||||
|
when :messages
|
||||||
|
text c(:cyan, '── Message Board ──'), x: CONT_X, y: CONT_Y
|
||||||
|
(@items[@scroll, cont_h - 2] || []).each_with_index do |line, i|
|
||||||
|
text line[0, cont_w], x: CONT_X, y: CONT_Y + 2 + i
|
||||||
end
|
end
|
||||||
sep
|
text c(:gray, "#{@items.size} msg(s) ↑↓ scroll q back"),
|
||||||
line CatalogRepository::GAMES_URL, :gray
|
x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
|
||||||
|
when :new_msg
|
||||||
|
text c(:cyan, '── Post Message ──'), x: CONT_X, y: CONT_Y
|
||||||
|
text c(:gray,'Type message and press Enter. Esc cancels.'),
|
||||||
|
x: CONT_X, y: CONT_Y + 2
|
||||||
|
text c(:white, "#{@username}: #{@input}_"), x: CONT_X, y: CONT_Y + 4
|
||||||
|
text c(:green, @status), x: CONT_X, y: CONT_Y + 6 unless @status.empty?
|
||||||
|
|
||||||
|
when :blog, :howto
|
||||||
|
color = @state == :blog ? :blue : :magenta
|
||||||
|
hdr = @state == :blog ? '── Blog Posts ──' : '── HowTo Guides ──'
|
||||||
|
text c(color, hdr), x: CONT_X, y: CONT_Y
|
||||||
|
if @items.empty?
|
||||||
|
text c(:gray, 'No items found.'), x: CONT_X, y: CONT_Y + 2
|
||||||
|
else
|
||||||
|
list_h = cont_h - 5
|
||||||
|
visible = @items[@scroll, list_h] || []
|
||||||
|
labels = visible.map { |p| p.title[0, cont_w - 2] }
|
||||||
|
list labels, x: CONT_X, y: CONT_Y + 2,
|
||||||
|
selected: @item_sel - @scroll, style: :gray, highlight: :white
|
||||||
|
if (page = @items[@item_sel])
|
||||||
|
hint = page.description.to_s.strip[0, cont_w]
|
||||||
|
text c(:gray, hint), x: CONT_X, y: CONT_Y + cont_h - 2 unless hint.empty?
|
||||||
|
end
|
||||||
|
text c(:gray, '↑↓ navigate Enter read q back'),
|
||||||
|
x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
end
|
||||||
|
|
||||||
|
when :page_view
|
||||||
|
text c(:cyan, @page_header[0, cont_w]), x: CONT_X, y: CONT_Y
|
||||||
|
text c(:gray, @page_meta[0, cont_w]), x: CONT_X, y: CONT_Y + 1
|
||||||
|
(@detail[@scroll, cont_h - 3] || []).each_with_index do |l, i|
|
||||||
|
text c(:gray, l[0, cont_w]), x: CONT_X, y: CONT_Y + 3 + i
|
||||||
|
end
|
||||||
|
text c(:gray, "#{@scroll + 1}/#{@detail.size} ↑↓ scroll q back"),
|
||||||
|
x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
|
||||||
|
when :games
|
||||||
|
text c(:cyan, '── Game Catalog ──'), x: CONT_X, y: CONT_Y
|
||||||
|
if @items.empty?
|
||||||
|
text c(:gray, 'No games found.'), x: CONT_X, y: CONT_Y + 2
|
||||||
|
else
|
||||||
|
game = @items[@item_sel]
|
||||||
|
text c(:white, "#{@item_sel + 1}/#{@items.size} #{game.title}"[0, cont_w]),
|
||||||
|
x: CONT_X, y: CONT_Y + 1
|
||||||
|
text c(:gray, "#{game.platform} #{game.author}"[0, cont_w]),
|
||||||
|
x: CONT_X, y: CONT_Y + 2
|
||||||
|
wrap_wiki(game.desc.to_s, cont_w).first(cont_h - 10).each_with_index do |l, i|
|
||||||
|
text c(:gray, l), x: CONT_X, y: CONT_Y + 4 + i
|
||||||
|
end
|
||||||
|
badges = []
|
||||||
|
badges << c(:green, '[▶ Play]') unless game.play_path.empty?
|
||||||
|
badges << c(:yellow, '[⬇ Download]') unless game.download_path.empty?
|
||||||
|
badges << c(:blue, '[Source]') unless game.source_path.empty?
|
||||||
|
badges << c(:magenta, '[Docs]') unless game.docs_path.empty?
|
||||||
|
text badges.join(' '), x: CONT_X, y: CONT_Y + cont_h - 5
|
||||||
|
text c(:gray, "↑↓ navigate q back"), x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
end
|
||||||
|
|
||||||
|
when :online
|
||||||
|
text c(:yellow, '── Online Users ──'), x: CONT_X, y: CONT_Y
|
||||||
|
@items.each_with_index do |uname, i|
|
||||||
|
you = uname == @username ? c(:gray, ' ← you') : ''
|
||||||
|
text c(:white, uname) + you, x: CONT_X, y: CONT_Y + 2 + i
|
||||||
|
end
|
||||||
|
text c(:gray, "#{@items.size} user(s) online q back"),
|
||||||
|
x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
|
||||||
|
when :sysinfo
|
||||||
|
text c(:magenta, '── System Info ──'), x: CONT_X, y: CONT_Y
|
||||||
|
@items.each_with_index do |row, i|
|
||||||
|
text c(:gray, row[0, cont_w]), x: CONT_X, y: CONT_Y + 2 + i
|
||||||
|
end
|
||||||
|
text c(:gray, 'q back'), x: CONT_X, y: CONT_Y + cont_h
|
||||||
|
end
|
||||||
|
|
||||||
|
bar y: term_rows, content: ' ↑↓ Navigate Enter Select q Back/Quit r Refresh',
|
||||||
|
style: :muted
|
||||||
|
end
|
||||||
|
|
||||||
|
# ── Navigation ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
key(:up) do
|
||||||
|
case @state
|
||||||
|
when :blog, :howto
|
||||||
|
if @item_sel > 0
|
||||||
|
@item_sel -= 1
|
||||||
|
@scroll = @item_sel if @item_sel < @scroll
|
||||||
|
end
|
||||||
|
when :games
|
||||||
|
@item_sel = (@item_sel - 1) % @items.size if @items.any?
|
||||||
|
when :messages
|
||||||
|
@scroll = [@scroll - 1, 0].max
|
||||||
|
when :page_view
|
||||||
|
@scroll = [@scroll - 1, 0].max
|
||||||
|
else
|
||||||
|
@menu_sel = (@menu_sel - 1) % MENU_ITEMS.size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
wait_enter
|
|
||||||
end
|
|
||||||
|
|
||||||
option 'Online Users' do
|
key(:down) do
|
||||||
section 'Online Users', color: :yellow
|
case @state
|
||||||
rows do |ctx|
|
when :blog, :howto
|
||||||
ONLINE.snapshot.sort.map do |sid, name|
|
if @item_sel < @items.size - 1
|
||||||
marker = sid == ctx[:session_id] ? " #{c(:gray, '← you')}" : ''
|
@item_sel += 1
|
||||||
"#{c(:white, name)}#{marker}"
|
list_h = (term_rows - CONT_Y - 4) - 5
|
||||||
|
@scroll = @item_sel - list_h + 1 if @item_sel >= @scroll + list_h
|
||||||
|
end
|
||||||
|
when :games
|
||||||
|
@item_sel = (@item_sel + 1) % @items.size if @items.any?
|
||||||
|
when :messages
|
||||||
|
cont_h = term_rows - CONT_Y - 4
|
||||||
|
max = [@items.size - (cont_h - 2), 0].max
|
||||||
|
@scroll = [@scroll + 1, max].min
|
||||||
|
when :page_view
|
||||||
|
cont_h = term_rows - CONT_Y - 4
|
||||||
|
max = [@detail.size - (cont_h - 3), 0].max
|
||||||
|
@scroll = [@scroll + 1, max].min
|
||||||
|
else
|
||||||
|
@menu_sel = (@menu_sel + 1) % MENU_ITEMS.size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
text(style: :muted) { |ctx| "#{ONLINE.count} user(s) online" }
|
|
||||||
wait_enter
|
|
||||||
end
|
|
||||||
|
|
||||||
option 'System Info' do
|
key(:enter) do
|
||||||
section 'System Info', color: :magenta
|
if @state == :new_msg
|
||||||
table do |ctx|
|
if @input.strip.empty?
|
||||||
{
|
@status = 'Message cannot be empty.'
|
||||||
'Online users' => ONLINE.count,
|
else
|
||||||
'Messages' => MESSAGES.count,
|
MESSAGES.append(@username, @input.strip[0...200])
|
||||||
'Wiki' => 'https://wiki.teletype.hu',
|
@status = 'Sent!'
|
||||||
'Games API' => 'https://games.teletype.hu',
|
@input = ''
|
||||||
'Platform' => RUBY_PLATFORM,
|
end
|
||||||
'Ruby' => RUBY_VERSION
|
elsif (@state == :blog || @state == :howto) && @items[@item_sel]
|
||||||
}
|
page = @items[@item_sel]
|
||||||
|
body = WIKI.content(page.id)
|
||||||
|
@detail = wrap_wiki(body, term_cols - CONT_X - 1)
|
||||||
|
@page_header = page.title
|
||||||
|
@page_meta = "#{fmt_date(page.created_at)} #{WIKI.page_url(page.locale, page.path)}"
|
||||||
|
@prev_state = @state
|
||||||
|
@scroll = 0
|
||||||
|
@state = :page_view
|
||||||
|
else
|
||||||
|
case MENU_ITEMS[@menu_sel]
|
||||||
|
when 'Messages'
|
||||||
|
@items = MESSAGES.last(30).map do |m|
|
||||||
|
"#{c(:yellow, m.timestamp)} #{c(:white, m.username)}: #{m.text}"
|
||||||
|
end
|
||||||
|
@scroll = 0
|
||||||
|
@state = :messages
|
||||||
|
when 'Post Message'
|
||||||
|
@input = ''
|
||||||
|
@status = ''
|
||||||
|
@state = :new_msg
|
||||||
|
when 'Blog Posts'
|
||||||
|
@items = WIKI.list('blog')
|
||||||
|
@item_sel = 0
|
||||||
|
@scroll = 0
|
||||||
|
@state = :blog
|
||||||
|
when 'HowTo Guides'
|
||||||
|
@items = WIKI.list('howto')
|
||||||
|
@item_sel = 0
|
||||||
|
@scroll = 0
|
||||||
|
@state = :howto
|
||||||
|
when 'Game Catalog'
|
||||||
|
@items = CATALOG.fetch
|
||||||
|
@item_sel = 0
|
||||||
|
@state = :games
|
||||||
|
when 'Online Users'
|
||||||
|
@items = ONLINE.snapshot.sort.map { |_, name| name }
|
||||||
|
@state = :online
|
||||||
|
when '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}"
|
||||||
|
]
|
||||||
|
@state = :sysinfo
|
||||||
|
when 'Exit'
|
||||||
|
:halt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
key(:escape) do
|
||||||
|
if @state == :idle
|
||||||
|
:halt
|
||||||
|
elsif @state == :page_view
|
||||||
|
@scroll = 0
|
||||||
|
@state = @prev_state
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
@state = :idle
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
key('q') do
|
||||||
|
if @state == :new_msg
|
||||||
|
@input << 'q' if @input.length < 200
|
||||||
|
nil
|
||||||
|
elsif @state == :idle
|
||||||
|
:halt
|
||||||
|
elsif @state == :page_view
|
||||||
|
@scroll = 0
|
||||||
|
@state = @prev_state
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
@state = :idle
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
key('r') do
|
||||||
|
if @state == :new_msg
|
||||||
|
@input << 'r' if @input.length < 200
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
case @state
|
||||||
|
when :messages
|
||||||
|
@items = MESSAGES.last(30).map do |m|
|
||||||
|
"#{c(:yellow, m.timestamp)} #{c(:white, m.username)}: #{m.text}"
|
||||||
|
end
|
||||||
|
@scroll = 0
|
||||||
|
when :online
|
||||||
|
@items = ONLINE.snapshot.sort.map { |_, name| name }
|
||||||
|
when :blog
|
||||||
|
@items = WIKI.list('blog'); @item_sel = 0; @scroll = 0
|
||||||
|
when :howto
|
||||||
|
@items = WIKI.list('howto'); @item_sel = 0; @scroll = 0
|
||||||
|
when :games
|
||||||
|
@items = CATALOG.fetch; @item_sel = 0
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
key(:backspace) do
|
||||||
|
@input.chop! if @state == :new_msg && !@input.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
(' '..'~').each do |ch|
|
||||||
|
next if ch == 'q' || ch == 'r'
|
||||||
|
key(ch) do
|
||||||
|
@input << ch if @state == :new_msg && @input.length < 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
wait_enter
|
|
||||||
end
|
end
|
||||||
|
|
||||||
option 'Exit' do
|
BBS::TUIRunner.new(session, session_id, tui).run
|
||||||
exit_menu
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
say 'Goodbye!', style: :muted
|
say 'Goodbye!', style: :muted
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ require 'uri'
|
|||||||
require_relative '../model/game_model'
|
require_relative '../model/game_model'
|
||||||
|
|
||||||
class CatalogRepository
|
class CatalogRepository
|
||||||
API_URL = 'https://games.teletype.hu/api/software'
|
API_URL = 'https://teletypegames.org/api/software'
|
||||||
GAMES_URL = 'https://games.teletype.hu'
|
GAMES_URL = 'https://teletypegames.org'
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
uri = URI(API_URL)
|
uri = URI(API_URL)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ require 'uri'
|
|||||||
require_relative '../model/wiki_page_model'
|
require_relative '../model/wiki_page_model'
|
||||||
|
|
||||||
class WikiRepository
|
class WikiRepository
|
||||||
BASE_URL = 'https://wiki.teletype.hu'
|
BASE_URL = 'https://wiki.teletypegames.org'
|
||||||
|
|
||||||
def initialize(token: nil)
|
def initialize(token: nil)
|
||||||
@token = token
|
@token = token
|
||||||
|
|||||||
Reference in New Issue
Block a user