runChannelList is the default subcommand — prints recent messages optionally filtered by name. Identical to the legacy default minus the additional "unread" indicator on the header.
(ch channelLister, channelFilter string)
| 98 | // optionally filtered by name. Identical to the legacy default minus |
| 99 | // the additional "unread" indicator on the header. |
| 100 | func (cli *ChatCLI) runChannelList(ch channelLister, channelFilter string) { |
| 101 | if channelFilter == "list" { |
| 102 | channelFilter = "" |
| 103 | } |
| 104 | |
| 105 | type msgRow struct { |
| 106 | Server, Channel, Content, Timestamp string |
| 107 | Seq uint64 |
| 108 | } |
| 109 | var msgs []msgRow |
| 110 | |
| 111 | if channelFilter != "" { |
| 112 | for _, m := range ch.GetByChannel(channelFilter, 20) { |
| 113 | msgs = append(msgs, msgRow{ |
| 114 | Server: m.ServerName, Channel: m.Channel, Content: m.Content, |
| 115 | Timestamp: m.Timestamp.Format("15:04:05"), Seq: m.Seq, |
| 116 | }) |
| 117 | } |
| 118 | } else { |
| 119 | for _, m := range ch.GetRecent(20) { |
| 120 | msgs = append(msgs, msgRow{ |
| 121 | Server: m.ServerName, Channel: m.Channel, Content: m.Content, |
| 122 | Timestamp: m.Timestamp.Format("15:04:05"), Seq: m.Seq, |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | title := i18n.T("chan.cmd.box_title") |
| 128 | if channelFilter != "" { |
| 129 | title = i18n.T("chan.cmd.box_title_filtered", channelFilter) |
| 130 | } |
| 131 | |
| 132 | fmt.Println() |
| 133 | fmt.Println(uiBox("📡", title, ColorCyan)) |
| 134 | p := uiPrefix(ColorCyan) |
| 135 | |
| 136 | if len(msgs) == 0 { |
| 137 | fmt.Println(p + colorize(i18n.T("chan.cmd.no_messages"), ColorGray)) |
| 138 | fmt.Println(p + colorize(i18n.T("chan.cmd.no_messages_hint"), ColorGray)) |
| 139 | } else { |
| 140 | for _, m := range msgs { |
| 141 | fmt.Println(p + fmt.Sprintf(" #%d %s%s%s %s%s%s/%s%s%s %s", |
| 142 | m.Seq, |
| 143 | ColorGray, m.Timestamp, ColorReset, |
| 144 | ColorCyan, m.Server, ColorReset, |
| 145 | ColorPurple, m.Channel, ColorReset, |
| 146 | truncateStr(m.Content, 60))) |
| 147 | } |
| 148 | fmt.Println(p) |
| 149 | fmt.Println(p + fmt.Sprintf(" %s%s:%s ", |
| 150 | ColorGray, i18n.T("chan.cmd.total_label"), ColorReset) + |
| 151 | i18n.T("chan.cmd.total_messages", ch.Count())) |
| 152 | if u := ch.Unread(); u > 0 { |
| 153 | fmt.Println(p + colorize( |
| 154 | fmt.Sprintf(" %s: %d", i18n.T("chan.cmd.unread_label"), u), |
| 155 | ColorYellow)) |
| 156 | } |
| 157 | if cli.channelTriggerIsPaused() { |
no test coverage detected