mirror of https://github.com/Calamitous/iris.git
Add topic column headers
This commit is contained in:
parent
7d318d4f9d
commit
e312a44db2
9
TODO.md
9
TODO.md
|
@ -6,10 +6,6 @@
|
|||
|
||||
# For 1.0.6
|
||||
* ~Message deletion~
|
||||
* Mark unread topics/topics with unread replies in topics list
|
||||
* Add column headers for topics
|
||||
* Keep replies on edited topics
|
||||
* Document new features
|
||||
* ~Message editing~
|
||||
* ~Gracefully handle bad message files~
|
||||
* ~Fix topic selection when replying without topic ID~
|
||||
|
@ -18,6 +14,10 @@
|
|||
* ~Fix truncated message headers being one character too long in topic list~
|
||||
* ~Status flag fix~
|
||||
* ~Keep order of message on edit~
|
||||
* ~Mark unread topics/topics with unread replies in topics list~
|
||||
* ~Add column headers for topics~
|
||||
* Keep replies on edited topics
|
||||
* Document new features
|
||||
|
||||
# Bugs:
|
||||
* Is `Time.now.utc.iso8601` working as expected?
|
||||
|
@ -30,6 +30,7 @@
|
|||
* Create Struct to firm up message payload
|
||||
* Let Message initialization accept params as a hash
|
||||
* Add check for message file format version
|
||||
* Build entire topic line, _then_ truncate
|
||||
|
||||
# Refactoring
|
||||
* Split helptext into separate file?
|
||||
|
|
25
iris.rb
25
iris.rb
|
@ -387,11 +387,22 @@ class Message
|
|||
(replies.map(&:timestamp).max || timestamp || 'UNKNOWN').gsub(/T/, ' ').gsub(/Z/, '')
|
||||
end
|
||||
|
||||
def unread?
|
||||
Corpus.unread_messages.include? self
|
||||
end
|
||||
|
||||
def topic_status
|
||||
return '{r X}' unless valid?
|
||||
unread_count = replies.count(&:unread?)
|
||||
return ' ' if unread_count == 0
|
||||
return '*' if unread_count > 9
|
||||
unread_count.to_s
|
||||
end
|
||||
|
||||
def to_topic_line(index)
|
||||
error_marker = valid? ? '|' : 'X'
|
||||
head = [Display.print_index(index), latest_topic_timestamp, Display.print_author(author)].join(' | ')
|
||||
head = [Display.print_index(index), topic_status, latest_topic_timestamp, Display.print_author(author)].join(' | ')
|
||||
message_stub = truncated_display_message(Display::WIDTH - head.decolorize.length - 1)
|
||||
error_marker + ' ' + [head, message_stub].join(' | ')
|
||||
'| ' + [head, message_stub].join(' | ')
|
||||
end
|
||||
|
||||
def to_display
|
||||
|
@ -494,7 +505,7 @@ class Display
|
|||
end
|
||||
|
||||
def self.topic_index_width
|
||||
Corpus.topics.size.to_s.length
|
||||
[Corpus.topics.size.to_s.length, 2].max
|
||||
end
|
||||
|
||||
def self.topic_author_width
|
||||
|
@ -510,6 +521,11 @@ class Display
|
|||
# Right-align
|
||||
(author.to_s + (' ' * topic_author_width))[0..(topic_author_width - 1)]
|
||||
end
|
||||
|
||||
def self.topic_header
|
||||
author_head = ('AUTHOR' + (' ' * WIDTH))[0..topic_author_width-1]
|
||||
'| ' + ['ID', 'U', 'TIMESTAMP ', author_head, 'MESSAGE'].join(' | ')
|
||||
end
|
||||
end
|
||||
|
||||
class Interface
|
||||
|
@ -775,6 +791,7 @@ class Interface
|
|||
|
||||
def topics
|
||||
Display.say
|
||||
Display.say Display.topic_header
|
||||
Corpus.topics.each_with_index do |topic, index|
|
||||
Display.say topic.to_topic_line(index + 1)
|
||||
end
|
||||
|
|
16
iris_test.rb
16
iris_test.rb
|
@ -165,17 +165,19 @@ describe Display do
|
|||
it 'has a setting for the calculated screen width'
|
||||
|
||||
describe '#topic_index_width' do
|
||||
it 'returns the length in characters of the longest topic index' do
|
||||
Corpus.stubs(:topics).returns(%w{a bc def})
|
||||
Display.topic_index_width.must_equal 1
|
||||
|
||||
Corpus.stubs(:topics).returns(%w{a b c d e f g h i j k})
|
||||
it 'returns the a minimun length of 2' do
|
||||
Corpus.stubs(:topics).returns(%w{a})
|
||||
Display.topic_index_width.must_equal 2
|
||||
end
|
||||
|
||||
it 'returns 1 if there are no topics' do
|
||||
it 'returns the length in characters of the longest topic index' do
|
||||
Corpus.stubs(:topics).returns((0..1000).to_a)
|
||||
Display.topic_index_width.must_equal 4
|
||||
end
|
||||
|
||||
it 'returns 2 if there are no topics' do
|
||||
Corpus.stubs(:topics).returns([])
|
||||
Display.topic_index_width.must_equal 1
|
||||
Display.topic_index_width.must_equal 2
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue