mirror of https://github.com/Calamitous/iris.git
Add reply indentation and text wrapping
This commit is contained in:
parent
3b6ad0d3d3
commit
04ad5be41d
24
iris.rb
24
iris.rb
|
@ -3,21 +3,20 @@
|
|||
# MVP: Complete!
|
||||
#
|
||||
# Reading/Status:
|
||||
# TODO: Add tests
|
||||
# TODO: CLI options for scripting
|
||||
# TODO: Add "read" list
|
||||
# TODO: Add read/unread count
|
||||
# TODO: Create read file for current user if it doesn't exist
|
||||
#
|
||||
# Tech debt:
|
||||
# TODO: Reeeeefactor...
|
||||
# TODO: Flesh out tests
|
||||
# TODO: Split helptext into separate file?
|
||||
# TODO: Move all puts into Display class
|
||||
# TODO: Make all output WIDTH-aware
|
||||
# TODO: Create struct to firm up message payload
|
||||
# TODO: Common message file location for the security-conscious?
|
||||
# TODO: Parse and manage options before instantiating Interface from .start
|
||||
# TODO: Validate config, read, and history perms on startup
|
||||
# TODO: Validate read and history perms on startup
|
||||
# TODO: Let Message initialization accept params as a hash
|
||||
#
|
||||
# Fancify interface:
|
||||
|
@ -53,6 +52,12 @@ require 'json'
|
|||
require 'etc'
|
||||
require 'readline'
|
||||
|
||||
class String
|
||||
def wrapped(width = Display::WIDTH)
|
||||
self.gsub(/.{1,#{width}}(?:\s|\Z|\-)/){($& + 5.chr).gsub(/\n\005/,"\n").gsub(/\005/,"\n")}
|
||||
end
|
||||
end
|
||||
|
||||
class Config
|
||||
VERSION = '1.0.0'
|
||||
MESSAGE_FILE = "#{ENV['HOME']}/.iris.messages"
|
||||
|
@ -257,15 +262,18 @@ class Message
|
|||
def to_display
|
||||
error_marker = valid? ? nil : '### THIS MESSAGE HAS THE FOLLOWING ERRORS ###'
|
||||
error_follower = valid? ? nil : '### THIS MESSAGE MAY BE CORRUPT OR TAMPERED WITH ###'
|
||||
|
||||
bar = indent_text + ('-' * (Display::WIDTH - indent_text.length))
|
||||
message_text = message.wrapped(Display::WIDTH - indent_text.length).split("\n").map{|m| indent_text + m }.join("\n")
|
||||
[
|
||||
'',
|
||||
"#{leader_text} On #{timestamp}, #{author} #{verb_text}...",
|
||||
error_marker,
|
||||
errors,
|
||||
error_follower,
|
||||
'-' * Display::WIDTH,
|
||||
message,
|
||||
'-' * Display::WIDTH
|
||||
bar,
|
||||
message_text,
|
||||
bar
|
||||
].flatten.compact.join("\n")
|
||||
end
|
||||
|
||||
|
@ -291,6 +299,10 @@ class Message
|
|||
topic? ? 'posted' : 'replied'
|
||||
end
|
||||
|
||||
def indent_text
|
||||
topic? ? '' : ' | '
|
||||
end
|
||||
|
||||
def replies
|
||||
Corpus.find_all_by_parent_hash(hash)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue