Use tallboy to draw CLI table

This commit is contained in:
Alex Ling 2020-12-30 16:44:23 +00:00
parent af2fd2a66a
commit 5685dd1cc5
3 changed files with 14 additions and 12 deletions

View File

@ -68,3 +68,7 @@ shards:
git: https://github.com/crystal-lang/crystal-sqlite3.git git: https://github.com/crystal-lang/crystal-sqlite3.git
version: 0.16.0 version: 0.16.0
tallboy:
git: https://github.com/epoch/tallboy.git
version: 0.9.3

View File

@ -39,3 +39,5 @@ dependencies:
github: hkalexling/image_size.cr github: hkalexling/image_size.cr
koa: koa:
github: hkalexling/koa github: hkalexling/koa
tallboy:
github: epoch/tallboy

View File

@ -3,9 +3,10 @@ require "./queue"
require "./server" require "./server"
require "./main_fiber" require "./main_fiber"
require "./mangadex/*" require "./mangadex/*"
require "./plugin/*"
require "option_parser" require "option_parser"
require "clim" require "clim"
require "./plugin/*" require "tallboy"
MANGO_VERSION = "0.17.1" MANGO_VERSION = "0.17.1"
@ -110,18 +111,13 @@ class CLI < Clim
password.not_nil!, opts.admin password.not_nil!, opts.admin
when "list" when "list"
users = storage.list_users users = storage.list_users
name_length = users.map(&.[0].size).max? || 0 table = Tallboy.table do
l_cell_width = ["username".size, name_length].max header ["username", "admin access"]
r_cell_width = "admin access".size users.each do |name, admin|
header = " #{"username".ljust l_cell_width} | admin access " row [name, admin]
puts "-" * header.size end
puts header
puts "-" * header.size
users.each do |name, admin|
puts " #{name.ljust l_cell_width} | " \
"#{admin.to_s.ljust r_cell_width} "
end end
puts "-" * header.size puts table
when nil when nil
puts opts.help_string puts opts.help_string
else else