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!
|
# MVP: Complete!
|
||||||
#
|
#
|
||||||
# Reading/Status:
|
# Reading/Status:
|
||||||
# TODO: Add tests
|
|
||||||
# TODO: CLI options for scripting
|
|
||||||
# TODO: Add "read" list
|
# TODO: Add "read" list
|
||||||
# TODO: Add read/unread count
|
# TODO: Add read/unread count
|
||||||
# TODO: Create read file for current user if it doesn't exist
|
# TODO: Create read file for current user if it doesn't exist
|
||||||
#
|
#
|
||||||
# Tech debt:
|
# Tech debt:
|
||||||
# TODO: Reeeeefactor...
|
# TODO: Reeeeefactor...
|
||||||
|
# TODO: Flesh out tests
|
||||||
# TODO: Split helptext into separate file?
|
# TODO: Split helptext into separate file?
|
||||||
# TODO: Move all puts into Display class
|
# TODO: Move all puts into Display class
|
||||||
# TODO: Make all output WIDTH-aware
|
# TODO: Make all output WIDTH-aware
|
||||||
# TODO: Create struct to firm up message payload
|
# TODO: Create struct to firm up message payload
|
||||||
# TODO: Common message file location for the security-conscious?
|
# TODO: Common message file location for the security-conscious?
|
||||||
# TODO: Parse and manage options before instantiating Interface from .start
|
# 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
|
# TODO: Let Message initialization accept params as a hash
|
||||||
#
|
#
|
||||||
# Fancify interface:
|
# Fancify interface:
|
||||||
|
@ -53,6 +52,12 @@ require 'json'
|
||||||
require 'etc'
|
require 'etc'
|
||||||
require 'readline'
|
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
|
class Config
|
||||||
VERSION = '1.0.0'
|
VERSION = '1.0.0'
|
||||||
MESSAGE_FILE = "#{ENV['HOME']}/.iris.messages"
|
MESSAGE_FILE = "#{ENV['HOME']}/.iris.messages"
|
||||||
|
@ -257,15 +262,18 @@ class Message
|
||||||
def to_display
|
def to_display
|
||||||
error_marker = valid? ? nil : '### THIS MESSAGE HAS THE FOLLOWING ERRORS ###'
|
error_marker = valid? ? nil : '### THIS MESSAGE HAS THE FOLLOWING ERRORS ###'
|
||||||
error_follower = valid? ? nil : '### THIS MESSAGE MAY BE CORRUPT OR TAMPERED WITH ###'
|
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}...",
|
"#{leader_text} On #{timestamp}, #{author} #{verb_text}...",
|
||||||
error_marker,
|
error_marker,
|
||||||
errors,
|
errors,
|
||||||
error_follower,
|
error_follower,
|
||||||
'-' * Display::WIDTH,
|
bar,
|
||||||
message,
|
message_text,
|
||||||
'-' * Display::WIDTH
|
bar
|
||||||
].flatten.compact.join("\n")
|
].flatten.compact.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -291,6 +299,10 @@ class Message
|
||||||
topic? ? 'posted' : 'replied'
|
topic? ? 'posted' : 'replied'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def indent_text
|
||||||
|
topic? ? '' : ' | '
|
||||||
|
end
|
||||||
|
|
||||||
def replies
|
def replies
|
||||||
Corpus.find_all_by_parent_hash(hash)
|
Corpus.find_all_by_parent_hash(hash)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue